public abstract class Sensor
extends java.lang.Object
MiniMU
for more details.
Created by ollie on 1/06/2016.Modifier and Type | Field and Description |
---|---|
protected static boolean |
simulatedOnly |
protected boolean |
validLoad
Add a validLoad flag.
|
Constructor and Description |
---|
Sensor() |
Modifier and Type | Method and Description |
---|---|
void |
addListener(SensorUpdateListener listener)
Add a @
SensorUpdateListener that will listen to this @Sensor . |
void |
addNonResettableListener(SensorUpdateListener listener)
Add a @
SensorUpdateListener that will listen to this @Sensor . |
void |
addNonResettableValueChangedListener(SensorValueChangedListener listener)
Add a @
SensorValueChangedListener that will listen to this @Sensor . |
void |
addValueChangedListener(SensorValueChangedListener listener)
Add a @
SensorValueChangedListener that will listen to this @Sensor . |
void |
clearListeners()
Clear all listeners listening to this @
Sensor . |
static Sensor |
getSensor(java.lang.Class sensorClass)
Return a sensor if it has been constructed.
|
abstract java.lang.String |
getSensorName()
Returns the sensor name, typically the make/model of the hardware sensor that this class refers to.
|
static boolean |
isSimulatedOnly()
Flag to indicate this is just a simulator
|
boolean |
isValidLoadedSensor()
returns true if the sensor was loaded correctly.
|
protected void |
notifyListeners()
Notify all listeners that the sensor has updated
|
void |
reloadSimulation()
Override this on any classes you need to do something as a simulated sensor
|
void |
removeListener(SensorUpdateListener listener)
Remove the given @
SensorUpdateListener . |
void |
removeListener(SensorValueChangedListener listener)
Remove the given @
SensorValueChangedListener . |
void |
resetToDefault()
Override this function on any sensors that have resolution or the likes set
|
protected double |
roundValue(double val,
int rounding)
Round the double value to the number of decimal places defined by rounding
If rounding is less than zero, we will leave value as is
|
static float |
scaleValue(double sensor_min,
double sensor_max,
double scaled_min,
double scaled_max,
double sensor_value)
Return a scaled value for a sensor based on known maximum and minimum values
A continuous function that satisfies this the following
sensor_value(sensor_min) = scaled_min
sensor_value(sensor_max) = scaled_max
|
static void |
setSimulatedOnly(boolean simulated)
Set from inside IDE to indicate we are just simulating a sensor
|
protected void |
setValidLoad(boolean valid)
This needs to be set inside sensor to indicate it had a valid load
|
protected static void |
storeSensor(Sensor sensor)
Store the sensor into our loadedSensors
|
protected boolean validLoad
protected static boolean simulatedOnly
public static boolean isSimulatedOnly()
public static float scaleValue(double sensor_min, double sensor_max, double scaled_min, double scaled_max, double sensor_value)
sensor_min
- the minimum value sensor would normally returnsensor_max
- the maximum value our sensor would normally returnscaled_min
- the value we want returned as our minimum for sensor minimum valuescaled_max
- the value we want returned as our maximum for our sensor maximum valuesensor_value
- the actual value of the sensorpublic static void setSimulatedOnly(boolean simulated)
simulated
- set to true if we are simulatingpublic abstract java.lang.String getSensorName()
String
representing the sensor's name.public void addListener(SensorUpdateListener listener)
SensorUpdateListener
that will listen to this @Sensor
.
Will be deprecated in 3.0listener
- the listener to add.
deprecated use (@link addValueChangedListener) insteadpublic void addNonResettableListener(SensorUpdateListener listener)
SensorUpdateListener
that will listen to this @Sensor
.
Will be deprecated in 3.0
These listeners are not removed when device is resetlistener
- the listener to add.
deprecated use (@link addValueChangedListener) insteadpublic boolean isValidLoadedSensor()
protected void setValidLoad(boolean valid)
valid
- set to true if loadedpublic void addValueChangedListener(SensorValueChangedListener listener)
SensorValueChangedListener
that will listen to this @Sensor
.listener
- the listener to add.public void addNonResettableValueChangedListener(SensorValueChangedListener listener)
SensorValueChangedListener
that will listen to this @Sensor
.
These listeners are NOT removed when device is resetlistener
- the listener to add.public void removeListener(SensorUpdateListener listener)
SensorUpdateListener
.listener
- the listener to remove.public void removeListener(SensorValueChangedListener listener)
SensorValueChangedListener
.listener
- the listener to remove.public void clearListeners()
Sensor
.protected void notifyListeners()
public void resetToDefault()
public void reloadSimulation()
protected double roundValue(double val, int rounding)
val
- the value to roundrounding
- the number of decimal places to round topublic static Sensor getSensor(java.lang.Class sensorClass)
sensorClass
- the class we are looking forprotected static void storeSensor(Sensor sensor)
sensor
- the sensor we are loading