Mercurial > code > home > repos > homeauto
comparison service/frontDoorArduino/frontDoorArduino.py @ 17:d6c2b9b87f7b
yard light toggle button
Ignore-this: c003731daf656c377440278527522d75
author | drewp@bigasterisk.com |
---|---|
date | Sat, 03 Dec 2011 19:03:07 -0800 |
parents | 6fd208b97616 |
children | 84af13435de7 |
comparison
equal
deleted
inserted
replaced
16:3a429f6cc9dc | 17:d6c2b9b87f7b |
---|---|
3 this LCD; use frontDoorMessage for that. | 3 this LCD; use frontDoorMessage for that. |
4 | 4 |
5 lcd is this wide | 5 lcd is this wide |
6 |-------------------| | 6 |-------------------| |
7 22:05 85F in, 71F out | 7 22:05 85F in, 71F out |
8 | |
9 pin 11 senses the door | |
10 pin 12 activates the front yard lights ('out yard') | |
8 | 11 |
9 """ | 12 """ |
10 | 13 |
11 from __future__ import division | 14 from __future__ import division |
12 | 15 |
27 """ | 30 """ |
28 def __init__(self, port): | 31 def __init__(self, port): |
29 self.ser = LoggingSerial(port=port) | 32 self.ser = LoggingSerial(port=port) |
30 self.ser.flush() | 33 self.ser.flush() |
31 | 34 |
32 self.ser.write("\xff\x00\x00") | 35 self.setLcd("") |
33 self.ser.write("\xff\x03\x00") | 36 self.setLcdBrightness(0) |
34 self.currentText = "" | 37 self.setYardLight(0) |
35 self.currentBrightness = 0 | |
36 | 38 |
37 def ping(self): | 39 def ping(self): |
38 self.getDoor() | 40 self.getDoor() |
39 | 41 |
40 def getDoor(self): | 42 def getDoor(self): |
41 self.ser.write("\xff\x01") | 43 self.ser.write("\xff\x01") |
42 ret = self.ser.readJson() | 44 ret = self.ser.readJson() |
43 return ret['door'] | 45 return ret['door'] |
46 | |
47 def setYardLight(self, level): | |
48 self.currentYardLight = bool(level) | |
49 self.ser.write("\xff\x04" + chr(bool(self.currentYardLight))) | |
50 | |
51 def getYardLight(self): | |
52 return self.currentYardLight | |
44 | 53 |
45 def getLcd(self): | 54 def getLcd(self): |
46 return self.currentText | 55 return self.currentText |
47 | 56 |
48 def setLcd(self, txt): | 57 def setLcd(self, txt): |
98 """param brightness=0 to brightness=255""" | 107 """param brightness=0 to brightness=255""" |
99 self.settings.board.setLcdBrightness( | 108 self.settings.board.setLcdBrightness( |
100 int(self.get_argument('brightness'))) | 109 int(self.get_argument('brightness'))) |
101 self.write("ok") | 110 self.write("ok") |
102 post = put | 111 post = put |
112 | |
113 | |
114 class YardLight(PrettyErrorHandler, cyclone.web.RequestHandler): | |
115 def get(self): | |
116 self.set_header("Content-Type", "application/json") | |
117 self.write(json.dumps({ | |
118 "yardLight" : self.settings.board.getYardLight()})) | |
119 | |
120 def put(self): | |
121 """text true or false or 0 or 1""" | |
122 self.settings.board.setYardLight( | |
123 self.request.body.strip() in ['true', '1']) | |
124 self.write("ok") | |
125 post = put | |
126 | |
103 | 127 |
104 class Door(PrettyErrorHandler, cyclone.web.RequestHandler): | 128 class Door(PrettyErrorHandler, cyclone.web.RequestHandler): |
105 def get(self): | 129 def get(self): |
106 self.set_header("Content-Type", "text/plain") | 130 self.set_header("Content-Type", "text/plain") |
107 self.write(self.settings.board.getDoor()) | 131 self.write(self.settings.board.getDoor()) |
118 (r"/", index), | 142 (r"/", index), |
119 (r'/lcd', Lcd), | 143 (r'/lcd', Lcd), |
120 (r'/door', Door), | 144 (r'/door', Door), |
121 (r'/temperature', Temperature), | 145 (r'/temperature', Temperature), |
122 (r'/lcd/backlight', Backlight), | 146 (r'/lcd/backlight', Backlight), |
147 (r'/yardLight', YardLight), | |
123 ] | 148 ] |
124 settings = {"board" : board} | 149 settings = {"board" : board} |
125 cyclone.web.Application.__init__(self, handlers, **settings) | 150 cyclone.web.Application.__init__(self, handlers, **settings) |
126 | 151 |
127 | 152 |
167 'boardName' : 'frontDoor', # gets sent with updates | 192 'boardName' : 'frontDoor', # gets sent with updates |
168 'doorChangePost' : 'http://bang.bigasterisk.com:9069/inputChange', | 193 'doorChangePost' : 'http://bang.bigasterisk.com:9069/inputChange', |
169 # todo: need options to preset inputs/outputs at startup | 194 # todo: need options to preset inputs/outputs at startup |
170 } | 195 } |
171 | 196 |
172 log.startLogging(sys.stdout) | 197 #log.startLogging(sys.stdout) |
173 | 198 |
174 board = Board(port=config['arduinoPort']) | 199 board = Board(port=config['arduinoPort']) |
175 | 200 |
176 p = Poller(board, config['doorChangePost'], config['boardName']) | 201 p = Poller(board, config['doorChangePost'], config['boardName']) |
177 task.LoopingCall(p.poll).start(1/config['pollFrequency']) | 202 task.LoopingCall(p.poll).start(1/config['pollFrequency']) |