1 //Create a class for acceleration sensor
2 package AccelerationSensor
3 import Timer.SimulatedTimer
5 public class AccelerationSensors {
6 private int deviceNumbers
7 private List accelerationSensors
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
11 private String id = "accelerationSensorID0"
12 private String label = "accelerationSensor0"
13 private String displayName = "accelerationSensor0"
14 private String acceleration = "inactive"
15 private String currentAcceleration = "inactive"
16 private String accelerationLatestValue = "inactive"
20 AccelerationSensors(Closure sendEvent, int deviceNumbers, boolean init) {
21 this.sendEvent = sendEvent
22 this.deviceNumbers = deviceNumbers
23 this.accelerationSensors = []
26 this.acceleration = "inactive"
27 this.accelerationLatestValue = "inactive"
29 this.acceleration = "active"
30 this.accelerationLatestValue = "active"
32 accelerationSensors.add(new AccelerationSensor(id, label, displayName, this.acceleration, this.accelerationLatestValue))
36 def setValue(LinkedHashMap eventDataMap) {
37 if (eventDataMap["value"] != accelerationSensors[0].acceleration) {
38 this.accelerationLatestValue = eventDataMap["value"]
39 this.acceleration = eventDataMap["value"]
40 this.currentAcceleration = eventDataMap["value"]
41 accelerationSensors[0].setValue(eventDataMap["value"])
42 sendEvent(eventDataMap)
47 def eventsSince(Date dateObj) {
48 return accelerationSensors[0].eventsSince()
51 def statesSince(String info, Date dateObj) {
52 return accelerationSensors[0].statesSince()
55 //Methods for closures
56 def count(Closure Input) {
57 accelerationSensors.count(Input)
60 accelerationSensors.size()
62 def each(Closure Input) {
63 accelerationSensors.each(Input)
65 def sort(Closure Input) {
66 accelerationSensors.each(Input)
68 def find(Closure Input) {
69 accelerationSensors.find(Input)
71 def collect(Closure Input) {
72 accelerationSensors.collect(Input)
76 def currentValue(String deviceFeature) {
77 accelerationSensors[0].currentValue(deviceFeature)//It is called if we have only one device
80 def latestValue(String deviceFeature) {
81 accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device
85 accelerationSensors[ix]