public class Pin extends Object
A pin in libbulldog is solely a management container. It contains features that can be activated on it.
E.g. one might choose to use the Pin as a DigitalOutput or a
DigitalInput.
The pin contains the necessary information to be set up according to the user's wishes. If the information of this class is not enough, then board implementations derive from it. It ensures that only one feature can be activated at a time. If asynchronous or blocking operations are currently in progress on another feature, then the pin will deny any other feature activation during that time.
Mostly, the pin is just used to grab a feature that is available on
it:
DigitalOutput output = pin.as(DigitalOutput.class);
Pwm pwm = pin.as(Pwm.class);
| Constructor and Description |
|---|
Pin(String name,
int address,
String port,
int indexOnPort)
Instantiates a new pin.
|
| Modifier and Type | Method and Description |
|---|---|
<T extends PinFeature> |
activateFeature(Class<T> feature)
Activates a feature on a pin.
|
Pin |
addFeature(PinFeature feature)
Adds the feature to the pin.
|
void |
addFeatureActivationListener(FeatureActivationListener listener)
Adds a feature activation listener.
|
<T extends PinFeature> |
as(Class<T> feature)
This is a very important method.
|
void |
block(PinFeature blocker)
Blocks a pin.
|
void |
clearFeatureActivationListeners()
Clears the list of feature activation listeners.
|
protected void |
fireFeatureActivated(PinFeature feature)
This method fires the feature activated event.
|
protected void |
fireFeatureActivating(PinFeature feature)
This method fires the feature activating event.
|
protected void |
fireFeatureDeactivated(PinFeature feature)
This method fires the feature deactivated event.
|
protected void |
fireFeatureDeactivating(PinFeature feature)
This method fires the feature deactivating event.
|
PinFeature |
getActiveFeature()
Gets the active feature.
|
int |
getAddress()
Gets the address of the pin.
|
String |
getAlias()
Gets the alias of the pin.
|
PinFeature |
getBlocker()
Gets the pin feature that currently blocks the pin.
|
<T extends PinFeature> |
getFeature(Class<T> featureClass)
Grabs a feature from the pin, if it is available.
|
List<FeatureActivationListener> |
getFeatureActivationListeners()
Gets a list of all registered
FeatureActivationListeners. |
List<PinFeature> |
getFeatures()
Gets a list of all available feature instances.
|
int |
getIndexOnPort()
Gets the index of the pin on the port.
|
String |
getName()
Gets the name of the pin.
|
String |
getPort()
Gets the port of the pin.
|
boolean |
hasFeature(Class<? extends PinFeature> featureClass)
Checks if a feature class is available on a pin.
|
boolean |
isBlocked()
Checks if the pin is currently blocked by a feature.
|
boolean |
isFeatureActive(Class<? extends PinFeature> featureClass)
Checks if a feature class is currently active on this pin.
|
boolean |
isFeatureActive(PinFeature feature)
Checks if the feature instance is currently active on this pin.
|
Pin |
removeFeature(Class<? extends PinFeature> featureClass)
Removes a feature from a pin.
|
void |
removeFeatureActivationListener(FeatureActivationListener listener)
Removes a feature activation listener.
|
void |
setAlias(String alias)
Sets the alias of the pin.
|
void |
unblock(PinFeature blocker)
Unblocks a pin if it is currently blocked.
|
public <T extends PinFeature> void activateFeature(Class<T> feature)
T - the type (classname) of the desired featurefeature - the type (classname) of the desired featurepublic Pin addFeature(PinFeature feature)
feature - the instance of the feature to be addedpublic Pin removeFeature(Class<? extends PinFeature> featureClass)
featureClass - the feature class to be removedpublic <T extends PinFeature> T as(Class<T> feature)
T - the concrete type of the pin feature.feature - the classname of the feature.public void block(PinFeature blocker)
unblock.blocker - the pin feature that should block the pin.public void unblock(PinFeature blocker)
blocker - the feature that currently blocks the pin. If
the pin is blocked, but not by the pin feature given
in the argument, then a PinBlockedException will be
thrown.public PinFeature getBlocker()
public boolean isBlocked()
public <T extends PinFeature> T getFeature(Class<T> featureClass)
T - the concrete type of the pin featurefeatureClass - the class of the pin featurenull otherwise.public PinFeature getActiveFeature()
public boolean isFeatureActive(Class<? extends PinFeature> featureClass)
featureClass - the feature classpublic boolean isFeatureActive(PinFeature feature)
feature - the featurepublic int getAddress()
public String getPort()
public int getIndexOnPort()
public List<PinFeature> getFeatures()
public String getName()
public String getAlias()
setAlias.public void setAlias(String alias)
alias - the alternate name of the pin.public boolean hasFeature(Class<? extends PinFeature> featureClass)
featureClass - the feature classpublic void addFeatureActivationListener(FeatureActivationListener listener)
listener - the listenerpublic void removeFeatureActivationListener(FeatureActivationListener listener)
listener - the listenerpublic void clearFeatureActivationListeners()
public List<FeatureActivationListener> getFeatureActivationListeners()
FeatureActivationListeners.FeatureActivationListenersprotected void fireFeatureActivating(PinFeature feature)
FeatureActivationListeners will
react on it.feature - the feature that is currently being activatedprotected void fireFeatureActivated(PinFeature feature)
FeatureActivationListeners will
react on it.feature - the feature that is currently being activatedprotected void fireFeatureDeactivating(PinFeature feature)
FeatureActivationListeners will
react on it.feature - the feature that is currently being activatedprotected void fireFeatureDeactivated(PinFeature feature)
FeatureActivationListeners will
react on it.feature - the feature that is currently being activatedCopyright © 2015 silverspoon.io. All rights reserved.