1 //Create a class for color control
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class ColorControls {
9 private int deviceNumbers
10 private List colorControls
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "colorControlID0"
15 private String label = "colorControl0"
16 private String displayName = "colorControl0"
17 private String color = "red"
19 private int saturation = 50
22 ColorControls(Closure sendEvent, int deviceNumbers) {
23 this.sendEvent = sendEvent
24 this.deviceNumbers = deviceNumbers
25 this.colorControls = []
27 def initHue = Verify.getIntFromList(30, 50, 70)
29 def initSat = Verify.getIntFromList(40, 50, 60)
30 this.saturation = initSat
31 def init = Verify.getInt(0,2)
34 } else if (init == 1) {
40 colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation))
43 //Methods for closures
44 def count(Closure Input) {
45 colorControls.count(Input)
50 def each(Closure Input) {
51 colorControls.each(Input)
53 def find(Closure Input) {
54 colorControls.find(Input)
56 def collect(Closure Input) {
57 colorControls.collect(Input)
61 def setValue(LinkedHashMap eventDataMap) {
62 if (eventDataMap["name"] == "color") {
63 if (eventDataMap["value"] != colorControls[0].color) {
64 colorControls[0].setValue(eventDataMap["value"], "color")
65 this.color = colorControls[0].color
66 sendEvent(eventDataMap)
68 } else if (eventDataMap["name"] == "hue") {
69 if (eventDataMap["value"] != colorControls[0].hue) {
70 colorControls[0].setValue(eventDataMap["value"], "hue")
71 this.hue = colorControls[0].hue
72 sendEvent(eventDataMap)
75 if (eventDataMap["value"] != colorControls[0].saturation) {
76 colorControls[0].setValue(eventDataMap["value"], "saturation")
77 this.saturation = colorControls[0].saturation
78 sendEvent(eventDataMap)
85 def setColor(String color) {
86 if (color != this.color) {
87 colorControls[0].setColor(color)
93 if (hue != this.hue) {
94 colorControls[0].setHue(hue)
99 def setSaturation(int saturation) {
100 if (saturation != this.saturation) {
101 colorControls[0].setSaturation(saturation)
102 this.saturation = saturation
106 def currentValue(String deviceFeature) {
107 colorControls[0].currentValue(deviceFeature)