1 //Create a class for step sensor
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class StepSensors {
9 private int deviceNumbers
10 private List stepSensors
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "stepSensorID0"
15 private String label = "stepSensor0"
16 private String displayName = "stepSensor0"
17 private int goal = 1000
21 StepSensors(Closure sendEvent, int deviceNumbers) {
22 this.sendEvent = sendEvent
23 this.deviceNumbers = deviceNumbers
26 /*def initGoal = Verify.getIntFromList(1000, 2000, 3000)
28 def initSteps = Verify.getIntFromList(0, 1, 2)
29 this.steps = initSteps*/
31 stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
35 def setValue(LinkedHashMap eventDataMap) {
36 if (eventDataMap["name"] == "steps") {
37 if (eventDataMap["value"] != stepSensors[0].steps) {
38 stepSensors[0].setValue(eventDataMap["value"], "steps")
39 this.steps = stepSensors[0].steps
40 sendEvent(eventDataMap)
42 } else if (eventDataMap["value"] == "goal") {
43 if (eventDataMap["value"] != stepSensors[0].goal) {
44 stepSensors[0].setValue(eventDataMap["value"], "goal")
45 this.goal = stepSensors[0].goal
46 sendEvent(eventDataMap)
51 //Methods for closures
52 def count(Closure Input) {
53 stepSensors.count(Input)
58 def each(Closure Input) {
59 stepSensors.each(Input)
61 def find(Closure Input) {
62 stepSensors.find(Input)
64 def collect(Closure Input) {
65 stepSensors.collect(Input)
69 def currentValue(String deviceFeature) {
70 stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device