Mercurial > ~darius > hgwebdir.cgi > beermon.old
comparison Control.py @ 12:9d5b291cfd01
Add/correct docstrings & comments.
author | darius |
---|---|
date | Sat, 29 Sep 2007 14:51:20 +0000 |
parents | 483375ca5d10 |
children | f1832dec26e3 |
comparison
equal
deleted
inserted
replaced
11:4b3d6022e6ea | 12:9d5b291cfd01 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 ############################################################################ | 3 ############################################################################ |
4 # Control class for beermon | 4 # Control class for beermon |
5 # | 5 # |
6 # $Id: Control.py,v 1.1 2007/09/29 14:39:59 darius Exp $ | 6 # $Id: Control.py,v 1.2 2007/09/29 14:51:20 darius Exp $ |
7 # | 7 # |
8 # Depends on: Python 2.3 (I think) | 8 # Depends on: Python 2.3 (I think) |
9 # | 9 # |
10 ############################################################################ | 10 ############################################################################ |
11 # | 11 # |
49 """This class is responsible for controlling the temperature of | 49 """This class is responsible for controlling the temperature of |
50 the fermenter by switching the heater & cooler.""" | 50 the fermenter by switching the heater & cooler.""" |
51 staleDataTime = 30 | 51 staleDataTime = 30 |
52 | 52 |
53 def __init__(self, _log, m, conf): | 53 def __init__(self, _log, m, conf): |
54 """m is a MonitorDev object, conf is a ConfigParser object""" | 54 """m is a MonitorDev object, _log is a logging object, conf is a ConfigParser object""" |
55 global log | 55 global log |
56 log = _log | 56 log = _log |
57 | 57 |
58 self.m = m | 58 self.m = m |
59 | 59 |
63 | 63 |
64 log.debug("target temperature - %3.2f" % (self.targetTemp)) | 64 log.debug("target temperature - %3.2f" % (self.targetTemp)) |
65 log.debug("hysteresis - %3.2f" % (self.hysteresis)) | 65 log.debug("hysteresis - %3.2f" % (self.hysteresis)) |
66 log.debug("pollInterval - %d" % (self.pollInterval)) | 66 log.debug("pollInterval - %d" % (self.pollInterval)) |
67 | 67 |
68 # We sleep on this, using time.sleep() doesn't work well in a | |
69 # threaded environment (eg ctrl-c will be blocked until the | |
70 # timeout expires.) | |
68 self.cv = threading.Condition() | 71 self.cv = threading.Condition() |
69 self.cv.acquire() | 72 self.cv.acquire() |
70 | 73 |
71 def doit(self): | 74 def doit(self): |
72 """Runs forever controlling the temperature until something breaks or interrupted""" | 75 """Runs forever controlling the temperature until something breaks or interrupted""" |
73 log.debug("=== Starting ===") | 76 log.debug("=== Starting ===") |
74 log.debug("Fermenter Fridge Ambient State New State") | 77 log.debug("Fermenter Fridge Ambient State New State") |
75 while True: | 78 while True: |
76 # Check if our monitor thread has died | 79 # Check if the monitor thread has died |
77 if (not self.m.isAlive()): | 80 if (not self.m.isAlive()): |
78 raise ThreadDied, "Monitor thread has died" | 81 raise ThreadDied, "Monitor thread has died" |
79 | 82 |
80 # Check for stale data | 83 # Check for stale data |
81 if (self.m.lastUpdate[self.m.fermenterId] + self.staleDataTime < time.time()): | 84 if (self.m.lastUpdate[self.m.fermenterId] + self.staleDataTime < time.time()): |