-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added digital output multi-pin configuration, since the 4-digit 7-seg…
…ment display requires multiple digital output pins.
- Loading branch information
1 parent
673910b
commit 8a795a1
Showing
1 changed file
with
132 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
...a/com/opensourcewithslu/utilities/MultiPinConfigs/DigitalOutputMultiPinConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.opensourcewithslu.utilities.MultiPinConfigs; | ||
|
||
import io.micronaut.context.annotation.EachProperty; | ||
import io.micronaut.context.annotation.Parameter; | ||
import io.micronaut.context.annotation.Prototype; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* This class handles the configuration of a digital output component that has multiple pins. | ||
*/ | ||
@Prototype | ||
@EachProperty("pi4j.multi-digital-output") | ||
public class DigitalOutputMultiPinConfiguration { | ||
private final String id; | ||
private String name; | ||
private int[] addresses; | ||
private int[] initials; | ||
private int[] shutdowns; | ||
private String provider; | ||
|
||
/** | ||
* The DigitalOutputMultiPinConfiguration constructor. | ||
* | ||
* @param id The configuration id as defined in the application.yml | ||
*/ | ||
public DigitalOutputMultiPinConfiguration(@Parameter String id) { | ||
this.id = id + "MultiPin"; | ||
} | ||
|
||
/** | ||
* Gets the id of the component. | ||
* | ||
* @return The id of the component. | ||
*/ | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Gets the name of the component. | ||
* | ||
* @return The name of the component. | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Sets the name of the component. | ||
* | ||
* @param name The string name to replace the existing name. | ||
*/ | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Gets the pin addresses for the component. | ||
* | ||
* @return An array of the pin addresses. | ||
*/ | ||
public int[] getAddresses() { | ||
return addresses; | ||
} | ||
|
||
/** | ||
* Sets the pin addresses for the component. All previously existing address are replaced. | ||
* | ||
* @param addresses Pin addresses separated by a comma. | ||
*/ | ||
public void setAddresses(String addresses) { | ||
addresses = addresses.replaceAll("\\s", ""); | ||
this.addresses = Arrays.stream(addresses.split(",")).mapToInt(Integer::parseInt).toArray(); | ||
} | ||
|
||
/** | ||
* Gets the initial states that the component is in when first initialized. | ||
* | ||
* @return Array of integers representing the initial state for each pin. | ||
*/ | ||
public int[] getInitials() { | ||
return initials; | ||
} | ||
|
||
/** | ||
* Sets the initial states for the component. | ||
* | ||
* @param initials String of states separated by commas. | ||
*/ | ||
public void setInitials(String initials) { | ||
initials = initials.replaceAll("\\s", ""); | ||
this.initials = Arrays.stream(initials.split(",")).mapToInt(Integer::parseInt).toArray(); | ||
} | ||
|
||
/** | ||
* Gets the shutdown states for the component. | ||
* | ||
* @return Array of integers representing the shutdowns. | ||
*/ | ||
public int[] getShutdowns() { | ||
return shutdowns; | ||
} | ||
|
||
/** | ||
* Sets the shutdown states for the component. Existing shutdowns are replaced. | ||
* | ||
* @param shutdowns String of shutdowns separated by commas. | ||
*/ | ||
public void setShutdowns(String shutdowns) { | ||
shutdowns = shutdowns.replaceAll("\\s", ""); | ||
this.shutdowns = Arrays.stream(shutdowns.split(",")).mapToInt(Integer::parseInt).toArray(); | ||
} | ||
|
||
/** | ||
* Gets the provider for the component. | ||
* | ||
* @return A String representation of the provider. | ||
*/ | ||
public String getProvider() { | ||
return provider; | ||
} | ||
|
||
/** | ||
* Sets the provider. | ||
* | ||
* @param provider The new provider for the component. | ||
*/ | ||
public void setProvider(String provider) { | ||
this.provider = provider; | ||
} | ||
} |