changeset 10:24c7e85c3efd

Add/correct docstrings & comments.
author darius
date Sat, 29 Sep 2007 14:51:20 +0000
parents f5cd94b55d5a
children 17449d52d5e5
files Control.py MonitorDev.py
diffstat 2 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Control.py	Sat Sep 29 14:40:54 2007 +0000
+++ b/Control.py	Sat Sep 29 14:51:20 2007 +0000
@@ -3,7 +3,7 @@
 ############################################################################
 # Control class for beermon
 #
-# $Id: Control.py,v 1.1 2007/09/29 14:39:59 darius Exp $
+# $Id: Control.py,v 1.2 2007/09/29 14:51:20 darius Exp $
 #
 # Depends on: Python 2.3 (I think)
 #
@@ -51,7 +51,7 @@
     staleDataTime = 30
     
     def __init__(self, _log, m, conf):
-        """m is a MonitorDev object, conf is a ConfigParser object"""
+        """m is a MonitorDev object, _log is a logging object, conf is a ConfigParser object"""
         global log
         log = _log
 
@@ -65,6 +65,9 @@
         log.debug("hysteresis - %3.2f" % (self.hysteresis))
         log.debug("pollInterval - %d" % (self.pollInterval))
 
+        # We sleep on this, using time.sleep() doesn't work well in a
+        # threaded environment (eg ctrl-c will be blocked until the
+        # timeout expires.)
         self.cv = threading.Condition()
         self.cv.acquire()
         
@@ -73,7 +76,7 @@
         log.debug("=== Starting ===")
         log.debug("Fermenter	Fridge	Ambient	State	New State")
         while True:
-            # Check if our monitor thread has died
+            # Check if the monitor thread has died
             if (not self.m.isAlive()):
                 raise ThreadDied, "Monitor thread has died"
 
--- a/MonitorDev.py	Sat Sep 29 14:40:54 2007 +0000
+++ b/MonitorDev.py	Sat Sep 29 14:51:20 2007 +0000
@@ -3,7 +3,7 @@
 ############################################################################
 # Monitoring/control interface to hardware for beermon
 #
-# $Id: MonitorDev.py,v 1.1 2007/09/29 14:39:59 darius Exp $
+# $Id: MonitorDev.py,v 1.2 2007/09/29 14:51:20 darius Exp $
 #
 # Depends on: Python 2.3 (I think)
 #
@@ -66,6 +66,7 @@
     lastCoolOff = 0
 
     def __init__(self, _log, conf):
+        """_log is a logging object, conf is a ConfigParser object"""
         global log
         log = _log
         threading.Thread.__init__(self)
@@ -106,6 +107,7 @@
         self.start()
         
     def setspeed(self):
+        """Set the speed microcom talks to the serial port to 38400"""
         self.commsLock.acquire()
         self.p.send('~')
         assert(self.p.expect('t - set terminal') == 0)
@@ -118,6 +120,7 @@
         self.commsLock.release()
         
     def find1wire(self):
+        """Scan the bus for 1-wire devices"""
         self.commsLock.acquire()
         self.p.sendline('')
         assert(self.p.expect('> ') == 0)
@@ -152,6 +155,7 @@
         return(devlist)
 
     def istemp(self, id):
+        """Returns true if the 1-wire device is a temperature sensor"""
         [family, a, b, c, d, e, f, g] = id.split(':')
         if (family == '10'):
             return True
@@ -159,6 +163,7 @@
             return False
 
     def updateTemps(self):
+        """Update our cached copy of temperatures"""
         for i in self.tempdevs:
             try:
                 self.temps[i] = float(self.readTemp(i))
@@ -170,6 +175,7 @@
         return(self.temps)
 
     def readTemp(self, id):
+        """Read the temperature of a sensor"""
         self.commsLock.acquire()
         cmd = 'te ' + id
         self.p.sendline(cmd)
@@ -187,6 +193,7 @@
         return(line)
 
     def setState(self, state):
+        """Set the heat/cool state, track the on/off time"""
         if (state == 'cool'):
             relay = 1 << self.coolRelay
         elif (state == 'heat'):
@@ -224,15 +231,8 @@
         assert(self.p.expect(cmd) == 0)
         self.commsLock.release()
         
-    def polltemps(self, temps):
-        while True:
-            for d in temps:
-                #print d
-                t = gettemp(p, d)
-                print "%s -> %s" % (d, t)
-            print
-
     def run(self):
+        """Sit in a loop polling temperatures"""
         while True:
             self.updateTemps()