Mercurial > code > home > repos > homeauto
changeset 185:2161c71c7b02
support for device code in the idle loop
Ignore-this: 7454ba4c9bab3c5393707af7ac91547
author | drewp@bigasterisk.com |
---|---|
date | Wed, 08 Jul 2015 01:19:21 -0700 |
parents | e052416a2290 |
children | 57e6d328d45b |
files | service/arduinoNode/arduinoNode.py service/arduinoNode/devices.py |
diffstat | 2 files changed, 30 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/service/arduinoNode/arduinoNode.py Thu Jun 18 01:45:07 2015 -0700 +++ b/service/arduinoNode/arduinoNode.py Wed Jul 08 01:19:21 2015 -0700 @@ -69,7 +69,7 @@ for devIndex, dev in enumerate(self._devs)) self._polledDevs = [d for d in self._devs if d.generatePollCode()] - self._statementsFromInputs = {} # input uri: latest statements + self._statementsFromInputs = {} # input device uri: latest statements self.open() @@ -158,9 +158,11 @@ 'global': '', 'setups': '', 'polls': '', + 'idles': '', 'actions': '', } - for attr in ['includes', 'global', 'setups', 'polls', 'actions']: + for attr in ['includes', 'global', 'setups', 'polls', 'idles', + 'actions']: for dev in self._devs: if attr == 'includes': gen = '\n'.join('#include "%s"\n' % inc @@ -168,6 +170,7 @@ elif attr == 'global': gen = dev.generateGlobalCode() elif attr == 'setups': gen = dev.generateSetupCode() elif attr == 'polls': gen = dev.generatePollCode() + elif attr == 'idles': gen = dev.generateIdleCode() elif attr == 'actions': code = dev.generateActionCode() if code: @@ -189,15 +192,30 @@ %(includes)s %(global)s - +byte frame=0; +unsigned long lastFrame=0; + void setup() { Serial.begin(%(baudrate)d); Serial.flush(); %(setups)s } +void idle() { + // this slowdown is to spend somewhat less time PWMing, to reduce + // leaking from on channels to off ones (my shift register has no + // latching) + if (micros() < lastFrame + 128) { + return; + } + lastFrame = micros(); + frame++; + %(idles)s +} + void loop() { byte head, cmd; + idle(); if (Serial.available() >= 2) { head = Serial.read(); if (head != 0x60) { @@ -344,7 +362,7 @@ turtleLiteral = self.request.body try: obj = Literal(float(turtleLiteral)) - except TypeError: + except ValueError: obj = Literal(turtleLiteral) stmt = (subj, pred, obj)
--- a/service/arduinoNode/devices.py Thu Jun 18 01:45:07 2015 -0700 +++ b/service/arduinoNode/devices.py Wed Jul 08 01:19:21 2015 -0700 @@ -75,13 +75,20 @@ return [] def generateGlobalCode(self): - """C code to emit in the global section""" + """C code to emit in the global section. + + Note that 'frame' (uint8) is available and increments each frame. + """ return '' def generateSetupCode(self): """C code to emit in setup()""" return '' + def generateIdleCode(self): + """C code to emit in the serial-read loop""" + return '' + def generatePollCode(self): """ C code to run a poll update. This should Serial.write its output