|
@@ -36,6 +36,10 @@ public class FloatSensorDevice extends SmartDevice implements FloatSensor, Sched
|
|
*/
|
|
*/
|
|
long nextSimulationTime = 0;
|
|
long nextSimulationTime = 0;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Update interval
|
|
|
|
+ */
|
|
|
|
+ int updateInterval = 10000;
|
|
/**
|
|
/**
|
|
* Name of the sensor reading
|
|
* Name of the sensor reading
|
|
*/
|
|
*/
|
|
@@ -57,6 +61,17 @@ public class FloatSensorDevice extends SmartDevice implements FloatSensor, Sched
|
|
init();
|
|
init();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Create a new Sensor with the given name and update interval
|
|
|
|
+ * @param name
|
|
|
|
+ * @param updateInterval
|
|
|
|
+ */
|
|
|
|
+ public FloatSensorDevice(String name, int updateInterval) {
|
|
|
|
+ super(name);
|
|
|
|
+ this.updateInterval = updateInterval;
|
|
|
|
+ init();
|
|
|
|
+ }
|
|
|
|
+
|
|
public void init(){
|
|
public void init(){
|
|
min = 10;
|
|
min = 10;
|
|
max = 35;
|
|
max = 35;
|
|
@@ -120,11 +135,11 @@ public class FloatSensorDevice extends SmartDevice implements FloatSensor, Sched
|
|
public void simulateEvent(long time) {
|
|
public void simulateEvent(long time) {
|
|
updateData();
|
|
updateData();
|
|
//Update again in 10 seconds
|
|
//Update again in 10 seconds
|
|
- nextSimulationTime=time + 10000;
|
|
|
|
|
|
+ nextSimulationTime=time + updateInterval;
|
|
SimulationManager.scheduleEvent(this);
|
|
SimulationManager.scheduleEvent(this);
|
|
}
|
|
}
|
|
|
|
|
|
- private void updateData() {
|
|
|
|
|
|
+ protected void updateData() {
|
|
float newVal = val + (val-oldVal)+new Random().nextFloat()/2.0f-0.25f;
|
|
float newVal = val + (val-oldVal)+new Random().nextFloat()/2.0f-0.25f;
|
|
newVal = Math.max(Math.min(newVal, max),min);
|
|
newVal = Math.max(Math.min(newVal, max),min);
|
|
this.oldVal = val;
|
|
this.oldVal = val;
|