1 //Create a class for acceleration sensor
2 package AccelerationSensor
3 import Timer.SimulatedTimer
5 public class AccelerationSensor {
8 private String displayName
9 private String acceleration
10 private String currentAcceleration
11 private String accelerationLatestValue
12 private List states = []
13 private List timeOfStates = []
15 AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) {
18 this.displayName = displayName
19 this.acceleration = acceleration
20 this.currentAcceleration = acceleration
21 this.accelerationLatestValue = accelerationLatestValue
24 def setValue(String value) {
25 println("the acceleration sensor with id:$id is triggered to $value!")
26 this.accelerationLatestValue = value
27 this.acceleration = value
28 this.currentAcceleration = value
29 this.states.add(value)
30 this.timeOfStates.add(System.currentTimeMillis())
33 def statesSince(String info, Date dateObj) {
34 def List happenedStates = []
35 def sinceThen = dateObj.time
36 for (int i = 0;i < timeOfStates.size();i++) {
37 if (timeOfStates[i]>=sinceThen)
38 happenedStates.add(states[i])
44 def currentValue(String deviceFeature) {
45 if (deviceFeature == "acceleration") {
50 def latestValue(String deviceFeature) {
51 if (deviceFeature == "acceleration") {
52 return accelerationLatestValue