diff --git a/weioLib/weioParser.py b/weioLib/weioParser.py index 2482d9c0..1682f639 100755 --- a/weioLib/weioParser.py +++ b/weioLib/weioParser.py @@ -48,6 +48,8 @@ ### from weioLib.weioIO import * +from weioUserApi import serverPush + from weioLib import weioRunnerGlobals import platform, sys @@ -160,7 +162,8 @@ def callProportion(data) : def callAttachInterrupt(data) : if (weioRunnerGlobals.WEIO_SERIAL_LINKED is True): - attachInterrupt(data[0], data[1], data[2], data[3]) + iObj = {"pin" : data[0], "jsCallbackString" : data[2]} + attachInterrupt(data[0], data[1], genericInterrupt, iObj) else: print "attachInterrupt ON PC", data return None @@ -172,6 +175,12 @@ def callDetachInterrupt(data) : print "detachInterrupt ON PC", data return None +def genericInterrupt(event, obj): + bck = {} + bck["data"] = obj["pin"] + bck["eventType"] = getInterruptType(event["type"]) + serverPush(obj["jsCallbackString"], bck) + def callDelay(data) : if (weioRunnerGlobals.WEIO_SERIAL_LINKED is True): delay(data[0]) @@ -228,14 +237,6 @@ def callGetTemperature(data): bck["data"] = 0 # faked value return bck -def genericInterrupt(data): - #type = data["type"] - #data = {} - #data["requested"] = 'analogRead' - #data["data"] = value - #self.write_message(json.dumps(data)) - pass - def callUserMesage(data): print "USER TALKS", data #weioRunnerGlobals.userMain diff --git a/www/libs/weio/weioApi.js b/www/libs/weio/weioApi.js index 20c9f164..709ecbe4 100755 --- a/www/libs/weio/weioApi.js +++ b/www/libs/weio/weioApi.js @@ -58,8 +58,7 @@ var _weio = null; * Each key is binded to coresponding function */ var weioCallbacks = { - "inbox":callInbox, - "attachInterrupt":weioExecuteInterrupt + "inbox":callInbox }; /** @@ -139,18 +138,19 @@ $(document).ready(function() { data = JSON.parse(e.data); console.log(data); - if ("requested" in data) { + if ("requested" in data) { + // this is instruction that was echoed from server + data as response + instruction = data.requested; + if (instruction in weioCallbacks) + weioCallbacks[instruction](data); + } else if ("serverPush" in data) { // this is instruction that was echoed from server + data as response - instruction = data.requested; - if (instruction in weioCallbacks) - weioCallbacks[instruction](data); - } else if ("serverPush" in data) { - // this is instruction that was echoed from server + data as response - - instruction = data.serverPush; - if (instruction in weioCallbacks) - weioCallbacks[instruction](data.data); - + instruction = data.serverPush; + if (instruction in weioCallbacks) { + weioCallbacks[instruction](data.data); + + } + } }; @@ -317,14 +317,14 @@ function noTone(pin) { function constrain(x, a, b) { if(x > a){ if(x < b){ - return a + return a; } } if(x < a){ - return a + return a; } if(x > b){ - return b + return b; } }; @@ -362,14 +362,11 @@ function callInbox(data) { } }; -function attachInterrupt(pin, mode, callback, obj) { +function attachInterrupt(pin, mode, callback) { var fName = callback.name; + weioCallbacks[fName] = callback; weioInterrupts[pin] = fName; - genericMessage("attachInterrupt", [pin, mode,fName,obj], null); -} - -function weioExecuteInterrupt(data) { - console.log("INTERRUPR",data); + genericMessage("attachInterrupt", [pin, mode,fName], null); } function detachInterrupt(pin) {