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 def initHue = Verify.getIntFromList(30, 50, 70)
42 def initSat = Verify.getIntFromList(40, 50, 60)
43 this.saturation = initSat
44 def init = Verify.getInt(0,2)
47 } else if (init == 1) {
53 colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation))
56 //Methods for closures
57 def count(Closure Input) {
58 colorControls.count(Input)
63 def each(Closure Input) {
64 colorControls.each(Input)
66 def find(Closure Input) {
67 colorControls.find(Input)
69 def collect(Closure Input) {
70 colorControls.collect(Input)
74 def setValue(LinkedHashMap eventDataMap) {
75 if (eventDataMap["name"] == "color") {
76 if (eventDataMap["value"] != colorControls[0].color) {
77 colorControls[0].setValue(eventDataMap["value"], "color")
78 this.color = colorControls[0].color
79 sendEvent(eventDataMap)
81 } else if (eventDataMap["name"] == "hue") {
82 if (eventDataMap["value"] != colorControls[0].hue) {
83 colorControls[0].setValue(eventDataMap["value"], "hue")
84 this.hue = colorControls[0].hue
85 sendEvent(eventDataMap)
88 if (eventDataMap["value"] != colorControls[0].saturation) {
89 colorControls[0].setValue(eventDataMap["value"], "saturation")
90 this.saturation = colorControls[0].saturation
91 sendEvent(eventDataMap)
98 def setColor(String color) {
99 if (color != this.color) {
100 colorControls[0].setColor(color)
105 def setHue(int hue) {
106 if (hue != this.hue) {
107 colorControls[0].setHue(hue)
112 def setSaturation(int saturation) {
113 if (saturation != this.saturation) {
114 colorControls[0].setSaturation(saturation)
115 this.saturation = saturation
119 def currentValue(String deviceFeature) {
120 colorControls[0].currentValue(deviceFeature)