annotate MonitorDev.py @ 13:c029d2195d19

Put the log file in CWD.
author darius
date Tue, 23 Oct 2007 01:00:19 +0000
parents 9d5b291cfd01
children f1832dec26e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
1 #!/usr/bin/env python
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
2
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
3 ############################################################################
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
4 # Monitoring/control interface to hardware for beermon
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
5 #
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
6 # $Id: MonitorDev.py,v 1.2 2007/09/29 14:51:20 darius Exp $
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
7 #
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
8 # Depends on: Python 2.3 (I think)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
9 #
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
10 ############################################################################
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
11 #
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
12 # Copyright (C) 2007 Daniel O'Connor. All rights reserved.
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
13 #
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
14 # Redistribution and use in source and binary forms, with or without
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
15 # modification, are permitted provided that the following conditions
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
16 # are met:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
17 # 1. Redistributions of source code must retain the above copyright
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
18 # notice, this list of conditions and the following disclaimer.
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
19 # 2. Redistributions in binary form must reproduce the above copyright
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
20 # notice, this list of conditions and the following disclaimer in the
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
21 # documentation and/or other materials provided with the distribution.
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
22 #
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
23 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
26 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
27 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
29 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
30 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
33 # SUCH DAMAGE.
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
34 #
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
35 ############################################################################
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
36
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
37 import threading, re, time, pexpect
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
38
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
39 class MonitorDev(threading.Thread):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
40 """This class continually polls the hardware for temperature
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
41 readings and accepts state changes to heat & cool"""
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
42
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
43 # Match a ROM ID (eg 00:11:22:33:44:55:66:77)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
44 romre = re.compile('([0-9a-f]{2}:){7}[0-9a-f]{2}')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
45 # Match the prompt
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
46 promptre = re.compile('> ')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
47
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
48 # Dictionary of sensor IDs & temperatures
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
49 temps = {}
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
50 # Dictionary of sensor IDs & epoch times
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
51 lastUpdate = {}
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
52
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
53 # List of all device IDs
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
54 devs = []
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
55 # List of temperature sensor IDs
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
56 tempdevs = []
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
57
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
58 # Lock to gate access to the comms
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
59 commsLock = None
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
60
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
61 currState = 'idle'
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
62
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
63 lastHeatOn = 0
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
64 lastHeatOff = 0
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
65 lastCoolOn = 0
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
66 lastCoolOff = 0
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
67
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
68 def __init__(self, _log, conf):
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
69 """_log is a logging object, conf is a ConfigParser object"""
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
70 global log
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
71 log = _log
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
72 threading.Thread.__init__(self)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
73
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
74 # Collect parameters
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
75 self.coolRelay = conf.getint('hardware', 'coolRelay')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
76 self.heatRelay = conf.getint('hardware', 'heatRelay')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
77 self.fermenterId = conf.get('hardware', 'fermenterId')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
78 self.fridgeId = conf.get('hardware', 'fridgeId')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
79 self.ambientId = conf.get('hardware', 'ambientId')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
80 self.minCoolOnTime = conf.getfloat('hardware', 'minCoolOnTime')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
81 self.minCoolOffTime = conf.getfloat('hardware', 'minCoolOffTime')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
82 self.minHeatOnTime = conf.getfloat('hardware', 'minHeatOnTime')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
83 self.minHeatOffTime = conf.getfloat('hardware', 'minHeatOffTime')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
84 self.minHeatOvershoot = conf.getfloat('hardware', 'minHeatOvershoot')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
85 self.minCoolOvershoot = conf.getfloat('hardware', 'minCoolOvershoot')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
86
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
87 # Setup locking & spawn SSH
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
88 self.commsLock = threading.Lock()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
89 self.p = pexpect.spawn('/usr/bin/ssh', ['-xt', '-enone', '-i', '/home/darius/.ssh/id_wrt', 'root@wrt', '(echo logged in; microcom -D/dev/cua/1)'])
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
90 assert(self.p.expect('logged in') == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
91 self.p.timeout = 3
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
92 self.setspeed()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
93
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
94 # Search for 1-wire modules
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
95 self.devs = self.find1wire()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
96 self.tempdevs = filter(self.istemp, self.devs)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
97
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
98 log.debug("fermenterId - %s" % (self.fermenterId))
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
99 log.debug("fridgeId - %s" % (self.fridgeId))
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
100 log.debug("ambientId - %s" % (self.ambientId))
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
101 log.debug("minCoolOnTime - %d, minCoolOffTime - %d" %
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
102 (self.minCoolOnTime, self.minCoolOffTime))
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
103 log.debug("minHeatOnTime - %d, minHeatOffTime - %d" %
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
104 (self.minHeatOnTime, self.minHeatOffTime))
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
105 log.debug("minHeatOvershoot - %3.2f, minCoolOvershoot - %3.2f" %
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
106 (self.minHeatOvershoot, self.minCoolOvershoot))
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
107 self.start()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
108
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
109 def setspeed(self):
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
110 """Set the speed microcom talks to the serial port to 38400"""
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
111 self.commsLock.acquire()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
112 self.p.send('~')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
113 assert(self.p.expect('t - set terminal') == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
114 self.p.send('t')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
115 assert(self.p.expect('p - set speed') == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
116 self.p.send('p')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
117 assert(self.p.expect('f - 38400') == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
118 self.p.send('f')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
119 assert(self.p.expect('done!') == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
120 self.commsLock.release()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
121
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
122 def find1wire(self):
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
123 """Scan the bus for 1-wire devices"""
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
124 self.commsLock.acquire()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
125 self.p.sendline('')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
126 assert(self.p.expect('> ') == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
127 self.p.sendline('sr')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
128 # Echo
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
129 assert(self.p.expect('sr') == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
130
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
131 # Send a new line which will give us a command prompt to stop on
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
132 # later. We could use read() but that would make the code a lot
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
133 # uglier
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
134 self.p.sendline('')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
135
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
136 devlist = []
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
137
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
138 # Loop until we get the command prompt (> ) collecting ROM IDs
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
139 while True:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
140 idx = self.p.expect([self.romre, self.promptre])
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
141 if (idx == 0):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
142 # Matched a ROM
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
143 #print "Found ROM " + self.p.match.group()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
144 devlist.append(self.p.match.group(0))
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
145 elif (idx == 1):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
146 # Matched prompt, exit
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
147 break
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
148 else:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
149 # Unpossible!
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
150 self.commsLock.release()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
151 raise SystemError()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
152
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
153 self.commsLock.release()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
154
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
155 return(devlist)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
156
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
157 def istemp(self, id):
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
158 """Returns true if the 1-wire device is a temperature sensor"""
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
159 [family, a, b, c, d, e, f, g] = id.split(':')
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
160 if (family == '10'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
161 return True
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
162 else:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
163 return False
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
164
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
165 def updateTemps(self):
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
166 """Update our cached copy of temperatures"""
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
167 for i in self.tempdevs:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
168 try:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
169 self.temps[i] = float(self.readTemp(i))
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
170 self.lastUpdate[i] = time.time()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
171 except OWReadError:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
172 # Ignore this - just results in no update reflected by lastUpdate
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
173 pass
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
174
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
175 return(self.temps)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
176
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
177 def readTemp(self, id):
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
178 """Read the temperature of a sensor"""
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
179 self.commsLock.acquire()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
180 cmd = 'te ' + id
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
181 self.p.sendline(cmd)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
182 # Echo
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
183 assert(self.p.expect(cmd) == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
184 # Eat EOL left from expect
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
185 self.p.readline()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
186
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
187 line = self.p.readline().strip()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
188 self.commsLock.release()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
189 # 'CRC mismatch' can mean that we picked the wrong ROM..
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
190 if (re.match('CRC mismatch', line) != None):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
191 raise OWReadError
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
192
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
193 return(line)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
194
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
195 def setState(self, state):
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
196 """Set the heat/cool state, track the on/off time"""
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
197 if (state == 'cool'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
198 relay = 1 << self.coolRelay
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
199 elif (state == 'heat'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
200 relay = 1 << self.heatRelay
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
201 elif (state == 'idle'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
202 relay = 0
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
203 else:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
204 raise(ValueError)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
205
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
206 if (state == self.currState):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
207 return
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
208
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
209 # Keep track of when we last turned off or on
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
210 if (state == 'cool'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
211 if (self.currState == 'heat'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
212 self.lastHeatOff = time.time()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
213 self.lastCoolOn = time.time()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
214 elif (state == 'heat'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
215 if (self.currState == 'cool'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
216 self.lastCoolOff = time.time()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
217 self.lastHeatOn = time.time()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
218 else:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
219 if (self.currState == 'cool'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
220 self.lastCoolOff = time.time()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
221 if (self.currState == 'heat'):
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
222 self.lastHeatOff = time.time()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
223
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
224 self.currState = state
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
225
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
226 self.commsLock.acquire()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
227 # Need the extra spaces cause the parser in the micro is busted
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
228 cmd = 'out c %02x' % relay
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
229 self.p.sendline(cmd)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
230 # Echo
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
231 assert(self.p.expect(cmd) == 0)
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
232 self.commsLock.release()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
233
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
234 def run(self):
12
9d5b291cfd01 Add/correct docstrings & comments.
darius
parents: 8
diff changeset
235 """Sit in a loop polling temperatures"""
8
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
236 while True:
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
237 self.updateTemps()
483375ca5d10 Split into seperate files.
darius
parents:
diff changeset
238