X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=ThreeAxis%2FThreeAxis.groovy;fp=ThreeAxis%2FThreeAxis.groovy;h=a555d6892e9865ed131a5b702ec8fd3b9a97964b;hb=d0b538d93e64c63d2673796db08570953b57f947;hp=3e5e817f62c5a478c38b9b3d42f96d4b1404fe03;hpb=2932def9bb947d617975235763f7338360f0e5a4;p=smartthings-infrastructure.git diff --git a/ThreeAxis/ThreeAxis.groovy b/ThreeAxis/ThreeAxis.groovy index 3e5e817..a555d68 100644 --- a/ThreeAxis/ThreeAxis.groovy +++ b/ThreeAxis/ThreeAxis.groovy @@ -1,40 +1,48 @@ //Create a class for three axis package ThreeAxis -import Timer.SimulatedTimer -import groovy.json.JsonSlurper - -//JPF's Verify API -import gov.nasa.jpf.vm.Verify public class ThreeAxis { - private String id - private String label - private String displayName - private LinkedHashMap threeAxis + // id, label, and display name of the device + StringBuilder id = new StringBuilder() + StringBuilder label = new StringBuilder() + StringBuilder displayName = new StringBuilder() + // Other variables + def sendEvent + LinkedHashMap currentThreeAxis + - ThreeAxis(String id, String label, String displayName, LinkedHashMap threeAxis) { + ThreeAxis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, LinkedHashMap currentThreeAxis) { + // Initialization this.id = id this.label = label this.displayName = displayName - this.threeAxis = threeAxis + this.currentThreeAxis = currentThreeAxis + this.sendEvent = sendEvent } + // Methods to set values def setValue(LinkedHashMap eventDataMap) { - threeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"]) - println("the three axis of cube is chagned to $threeAxis!") + def tmpID = id.toString() + currentThreeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"]) + println("the three axis with id:$tmpID of cube is chagned to $currentThreeAxis!") + sendEvent(eventDataMap) + } + + // Methods to return values + def getCurrentThreeAxis() { + return currentThreeAxis } def currentState(String deviceFeature) { currentValue(deviceFeature) } - def currentValue(String deviceFeature) { - if (deviceFeature == "threeAxis" || deviceFeature == "status") - return threeAxis + def latestValue(String deviceFeature) { + currentValue(deviceFeature) } - def latestValue(String deviceFeature) { + def currentValue(String deviceFeature) { if (deviceFeature == "threeAxis" || deviceFeature == "status") - return threeAxis + return currentThreeAxis } }