From b5d3ea69628d49ab5b26e064559f7a237b46c086 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Wed, 4 Jul 2012 22:03:34 +0200 Subject: srd: lm75: Output min/max/avg temperature in report(). This is just a preparation for later, the report() is not hooked up anywhere, yet. --- decoders/lm75/lm75.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'decoders/lm75') 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. -- cgit v1.2.3-70-g09d2