summaryrefslogtreecommitdiff
path: root/decoders/lm75
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2012-07-04 22:03:34 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2012-07-06 01:30:03 +0200
commitb5d3ea69628d49ab5b26e064559f7a237b46c086 (patch)
tree43f2314f760427d6aaee57baa4ce8fd307d42212 /decoders/lm75
parent86aac5f0a866f7a5bf5280ea44a291549554d661 (diff)
downloadlibsigrokdecode-b5d3ea69628d49ab5b26e064559f7a237b46c086.tar.gz
libsigrokdecode-b5d3ea69628d49ab5b26e064559f7a237b46c086.zip
srd: lm75: Output min/max/avg temperature in report().
This is just a preparation for later, the report() is not hooked up anywhere, yet.
Diffstat (limited to 'decoders/lm75')
-rw-r--r--decoders/lm75/lm75.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/decoders/lm75/lm75.py b/decoders/lm75/lm75.py
index 338086a..05ff231 100644
--- a/decoders/lm75/lm75.py
+++ b/decoders/lm75/lm75.py
@@ -75,15 +75,18 @@ class Decoder(srd.Decoder):
self.databytes = []
self.mintemp = 0
self.maxtemp = 0
- self.avgtemp = 0
+ self.avgvalues = []
def start(self, metadata):
# self.out_proto = self.add(srd.OUTPUT_PROTO, 'lm75')
self.out_ann = self.add(srd.OUTPUT_ANN, 'lm75')
def report(self):
- # TODO: Output min/max/avg temperature.
- pass
+ # TODO: print() or self.put() or return xyz, or... ?
+ avg = sum(self.avgvalues) / len(self.avgvalues)
+ temperatures = (self.mintemp, self.maxtemp, avg)
+ # TODO: Configurable report() output, e.g. for Kelvin.
+ return 'Min/max/avg temperature: %f/%f/%f °C' % temperatures
def putx(self, data):
# Helper for annotations which span exactly one I2C packet.
@@ -119,7 +122,7 @@ class Decoder(srd.Decoder):
self.mintemp = celsius
if celsius > self.maxtemp:
self.maxtemp = celsius
- # TODO: avg. temp.
+ self.avgvalues.append(celsius)
def handle_temperature_reg(self, b, s, rw):
# Common helper for the temperature/T_HYST/T_OS registers.