Created
December 10, 2012 14:36
-
-
Save smakhtin/4250895 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class @Sensocamera.ExternalSensor | |
| START_ACTION = "start" | |
| STOP_ACTION = "stop" | |
| STATE_STOPPED = 0 | |
| STATE_STARTING = 1 | |
| STATE_RUNNING = 2 | |
| STATE_FAILED = 3 | |
| currentState = STATE_STOPPED | |
| refreshPeriod = 0 | |
| intervalAction = null | |
| sensors = null; | |
| sensorName = "121111111" | |
| constructor: (name)-> | |
| setState(STATE_STARTING) | |
| sensorName = name | |
| watchData: (success, error, period)-> | |
| setState(STATE_STARTING) | |
| refreshPeriod = period | |
| intervalAction = setInterval (() -> success(sensors)), refreshPeriod | |
| callNativeFunction = (action, params) -> | |
| console.log "Calling class " + sensorName | |
| cordova.exec( | |
| (success)-> | |
| if currentState is STATE_STARTING | |
| setState(STATE_RUNNING) | |
| sensors = success | |
| ,(error)-> | |
| if currentState is STATE_STARTING | |
| setState STATE_FAILED | |
| console.log "NAME: " + sensorName | |
| console.log "EXEC ERROR" | |
| console.log error | |
| , sensorName, action, params | |
| ) | |
| setState = (state) -> | |
| if currentState is state then return | |
| currentState = state; | |
| switch currentState | |
| when STATE_STOPPED | |
| callNativeFunction(STOP_ACTION, []) | |
| clearInterval(intervalAction) | |
| when STATE_STARTING | |
| callNativeFunction(START_ACTION, []) | |
| when STATE_FAILED | |
| console.log "Failed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment