From: Uwe Hermann Date: Wed, 4 Jul 2012 20:03:34 +0000 (+0200) Subject: srd: lm75: Output min/max/avg temperature in report(). X-Git-Tag: libsigrokdecode-0.1.1~57 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b5d3ea69628d49ab5b26e064559f7a237b46c086;p=libsigrokdecode.git srd: lm75: Output min/max/avg temperature in report(). This is just a preparation for later, the report() is not hooked up anywhere, yet. --- 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.