public abstract class Sensor
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.util.List<ValueListener> |
listeners
Contains the listeners without range argument needed.
|
protected java.util.List<RangedValueListener> |
listenersWithRange
Contains the listeners with range argument needed.
|
protected int |
value
Contains the current value of the sensor.
|
Modifier | Constructor and Description |
---|---|
protected |
Sensor()
Creates a new sensor without attaching it to the BrickPi
|
Modifier and Type | Method and Description |
---|---|
protected void |
addListener(ValueListener listener)
Add a value listener to the sensor
|
protected void |
addListenerWithRange(RangedValueListener listener)
Add a value listener with range to the sensor
|
abstract SensorType |
getType()
Get the sensor type
|
int |
getValue()
Get the value of the sensor
|
void |
onChange(int range,
ValueListener listener)
Register a new listener with a range.
|
void |
onChange(ValueListener listener)
Registers a listener on the value of the sensor,
the listener will be triggered each time it changes.
|
protected void |
setValue(int value)
Set the value of the sensor, listeners will be triggered when updating this value
to a different value than the previous one
|
protected java.util.List<ValueListener> listeners
protected java.util.List<RangedValueListener> listenersWithRange
protected int value
protected Sensor()
public abstract SensorType getType()
public int getValue()
protected void setValue(int value)
value
- the new sensor value to be setpublic void onChange(ValueListener listener)
listener
- the listener to be triggeredpublic void onChange(int range, ValueListener listener)
range
- the range to be setlistener
- the listener that will be triggeredprotected void addListener(ValueListener listener)
listener
- the listener to be triggered when the value changesprotected void addListenerWithRange(RangedValueListener listener)
listener
- the ranged value listener to be triggered
when the value is out of the range