Mercurial > code > home > repos > homeauto
comparison service/garageArduino/garageArduino.py @ 122:fcf97a7f674c
garage arduino sends brite/* color changes out on virtualwire to a digispark now
Ignore-this: c14e3bd188cb97b2a7e596bb494b1e7b
author | drewp@bigasterisk.com |
---|---|
date | Sat, 28 Sep 2013 23:01:14 -0700 |
parents | 69b214997213 |
children |
comparison
equal
deleted
inserted
replaced
121:e367cdd15a24 | 122:fcf97a7f674c |
---|---|
64 return self.ser.readJson()['garage'] | 64 return self.ser.readJson()['garage'] |
65 | 65 |
66 def setVideoSelect(self, chan): | 66 def setVideoSelect(self, chan): |
67 """set video select bits from 0..3""" | 67 """set video select bits from 0..3""" |
68 self.ser.write("\x60\x05"+chr(chan)) | 68 self.ser.write("\x60\x05"+chr(chan)) |
69 | |
69 return self.ser.readJson()['videoSelect'] | 70 return self.ser.readJson()['videoSelect'] |
70 | 71 |
71 def shiftbrite(self, colors): | 72 def shiftbrite(self, colors): |
72 """ | 73 """ |
73 shift out this sequence of (r,g,b) triples of 10-bit ints | 74 shift out this sequence of (r,g,b) triples of 10-bit ints |
80 for r,g,b in colors) | 81 for r,g,b in colors) |
81 out = resetCurrent + out | 82 out = resetCurrent + out |
82 self.ser.write("\x60\x06" + chr(len(out)) + out) | 83 self.ser.write("\x60\x06" + chr(len(out)) + out) |
83 msg = self.ser.readJson() | 84 msg = self.ser.readJson() |
84 assert msg == {"ok":1}, msg | 85 assert msg == {"ok":1}, msg |
86 | |
87 def virtualwire(self, colors): | |
88 """ | |
89 send this sequence of (r,g,b) 8-bit triples | |
90 """ | |
91 numLeds = 4 | |
92 # vw receiver wants data for all leds every time | |
93 colors = (list(colors) + [(0,0,0)] * numLeds)[:numLeds] | |
94 msg = "".join("%s%s%s" % (chr(r), chr(g), chr(b)) for r,g,b in colors) | |
95 self.ser.write("\x60\x07" + chr(len(msg)) + msg) | |
96 msg = self.ser.readJson() | |
97 assert msg == {"sent": 12}, msg | |
98 | |
85 | 99 |
86 class Index(PrettyErrorHandler, cyclone.web.RequestHandler): | 100 class Index(PrettyErrorHandler, cyclone.web.RequestHandler): |
87 def get(self): | 101 def get(self): |
88 """ | 102 """ |
89 this is an acceptable status check since it makes a round-trip | 103 this is an acceptable status check since it makes a round-trip |
174 self.write(hexFromRgb(self.settings.colors[int(chan)])) | 188 self.write(hexFromRgb(self.settings.colors[int(chan)])) |
175 | 189 |
176 def put(self, chan): | 190 def put(self, chan): |
177 s = self.settings | 191 s = self.settings |
178 s.colors[int(chan)] = rgbFromHex(self.request.body) | 192 s.colors[int(chan)] = rgbFromHex(self.request.body) |
179 s.arduino.shiftbrite(s.colors) | 193 #s.arduino.shiftbrite(s.colors) |
194 s.arduino.virtualwire([(r//4, g//4, b//4) for r,g,b in s.colors]) | |
180 post = put | 195 post = put |
181 | 196 |
182 class Application(cyclone.web.Application): | 197 class Application(cyclone.web.Application): |
183 def __init__(self, ard, poller): | 198 def __init__(self, ard, poller): |
184 handlers = [ | 199 handlers = [ |
190 (r'/housePower/threshold', HousePowerThreshold), | 205 (r'/housePower/threshold', HousePowerThreshold), |
191 (r'/garageDoorOpen', GarageDoorOpen), | 206 (r'/garageDoorOpen', GarageDoorOpen), |
192 (r'/videoSelect', VideoSelect), | 207 (r'/videoSelect', VideoSelect), |
193 (r"/brite/(\d+)", Brite), | 208 (r"/brite/(\d+)", Brite), |
194 ] | 209 ] |
195 colors = [(0,0,0)] * 1 # stored 10-bit | 210 colors = [(0,0,0)] * 4 # stored 10-bit for legacy (or future!) reasons |
196 settings = {"arduino" : ard, "poller" : poller, "colors" : colors} | 211 settings = {"arduino" : ard, "poller" : poller, "colors" : colors} |
197 cyclone.web.Application.__init__(self, handlers, **settings) | 212 cyclone.web.Application.__init__(self, handlers, **settings) |
198 | 213 |
199 class Poller(object): | 214 class Poller(object): |
200 """ | 215 """ |