Mercurial > templog
comparison py/sensor_ds18b20.py @ 155:d03157c7ad60
rough touch sensor
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 21 Dec 2012 23:30:16 +0800 |
parents | e114b38c8a55 |
children | 256505f98c4d |
comparison
equal
deleted
inserted
replaced
154:542efb356e46 | 155:d03157c7ad60 |
---|---|
45 # interactively. | 45 # interactively. |
46 return self.readthread.apply(f.read) | 46 return self.readthread.apply(f.read) |
47 | 47 |
48 def do_sensor(self, s, contents = None): | 48 def do_sensor(self, s, contents = None): |
49 """ contents can be set by the caller for testing """ | 49 """ contents can be set by the caller for testing """ |
50 D("dosensor %s" % s) | |
51 try: | 50 try: |
52 if contents is None: | 51 if contents is None: |
53 fn = os.path.join(self.master_dir, s, 'w1_slave') | 52 fn = os.path.join(self.master_dir, s, 'w1_slave') |
54 f = open(fn, 'r') | 53 f = open(fn, 'r') |
55 contents = self.read_wait(f) | 54 contents = self.read_wait(f) |
57 match = self.THERM_RE.match(contents) | 56 match = self.THERM_RE.match(contents) |
58 if match is None: | 57 if match is None: |
59 D("no match") | 58 D("no match") |
60 return None | 59 return None |
61 temp = int(match.groups(1)[0]) / 1000.0 | 60 temp = int(match.groups(1)[0]) / 1000.0 |
62 D("returning %f" % temp) | |
63 return temp | 61 return temp |
64 except Exception, e: | 62 except Exception, e: |
65 EX("Problem reading sensor '%s': %s" % (s, str(e))) | 63 EX("Problem reading sensor '%s': %s" % (s, str(e))) |
66 return None | 64 return None |
67 | 65 |