From a81113532b582aa9b55a7fcd8b1a340b458814e0 Mon Sep 17 00:00:00 2001 From: Malcolm Mackay Date: Thu, 30 Jul 2020 00:09:02 +0100 Subject: [PATCH 1/2] Added pushsamplelist function to temperature. --- setup.py | 2 +- wscodec/encoder/pyencoder/instrumented.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index edd98fb..bb4e1c8 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name="cuplcodec", - version="2.0.4", + version="2.0.5", author="Malcolm Mackay", author_email="malcolm@plotsensor.com", description="Package for creating and decoding URLs that contain temperature and humidity samples.", diff --git a/wscodec/encoder/pyencoder/instrumented.py b/wscodec/encoder/pyencoder/instrumented.py index c5d8f07..994a2de 100644 --- a/wscodec/encoder/pyencoder/instrumented.py +++ b/wscodec/encoder/pyencoder/instrumented.py @@ -180,6 +180,17 @@ def pushsamples(self, num): self.ffimodule.lib.enc_pushsample(tempsmpl['adc'], 0) return inlist + def pushsamplelist(self, tlist: list): + """ + + :param tlist: a list of dictionaries each containing temperature keys. + :return: None + """ + for smpldict in tlist: + tempdegc = smpldict['temp'] + tempraw = self.temp_degc_to_raw(tempdegc) + self.ffimodule.lib.enc_pushsample(tempraw, 0) + class InstrumentedSampleTRH(InstrumentedSample): FORMAT_HDC2021_TRH = 1 From 4bb3ac2e5b653e837ac2c970988082294c36b635 Mon Sep 17 00:00:00 2001 From: Malcolm Mackay Date: Thu, 30 Jul 2020 00:20:14 +0100 Subject: [PATCH 2/2] Moved some methods to the InstrumentedSample parent class. This means we should be able to get both temperature and temperature/relative humidity simulations. --- setup.py | 2 +- wscodec/encoder/pyencoder/instrumented.py | 55 +++++++++-------------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/setup.py b/setup.py index bb4e1c8..4f1d527 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name="cuplcodec", - version="2.0.5", + version="2.0.6", author="Malcolm Mackay", author_email="malcolm@plotsensor.com", description="Package for creating and decoding URLs that contain temperature and humidity samples.", diff --git a/wscodec/encoder/pyencoder/instrumented.py b/wscodec/encoder/pyencoder/instrumented.py index 994a2de..246b73c 100644 --- a/wscodec/encoder/pyencoder/instrumented.py +++ b/wscodec/encoder/pyencoder/instrumented.py @@ -122,7 +122,6 @@ def temp_degc_to_raw(self, degc): """ Converts degrees C to a raw ADC value for the Texas HDC2010. """ return int((degc + 40) * 4096 / 165) - def rh_percent_to_raw(self, rhpc): """ Converts from relative humidity in percent to a raw ADC value for the Texas HDC2010. """ return int((rhpc * 4096) / 100) @@ -143,6 +142,28 @@ def rhsample(self, countermax, counterstep): rawrh = self.rh_percent_to_raw(counter) yield {'adc': rawrh, 'ref': counter} + def pushsamplelist(self, trhlist: list): + """ + + :param trhlist: a list of dictionaries each containing temperature and relative humidity keys. + :return: None + """ + for smpldict in trhlist: + tempdegc = smpldict['temp'] + rhpc = smpldict['rh'] + tempraw = self.temp_degc_to_raw(tempdegc) + rhraw = self.rh_percent_to_raw(rhpc) + # rhraw is ignored (set to -1) inside enc_pushsample if the format is temperature only. + self.ffimodule.lib.enc_pushsample(tempraw, rhraw) + + def updateendstop(self, minutes: int): + """ Update the endstop with minutes elapsed since the most recent sample. + + :param minutes: Minutes elapsed since the most recent sample. + :return: None + """ + self.ffimodule.lib.enc_setelapsed(minutes) + class InstrumentedSampleT(InstrumentedSample): FORMAT_HDC2021_TEMPONLY = 2 @@ -180,17 +201,6 @@ def pushsamples(self, num): self.ffimodule.lib.enc_pushsample(tempsmpl['adc'], 0) return inlist - def pushsamplelist(self, tlist: list): - """ - - :param tlist: a list of dictionaries each containing temperature keys. - :return: None - """ - for smpldict in tlist: - tempdegc = smpldict['temp'] - tempraw = self.temp_degc_to_raw(tempdegc) - self.ffimodule.lib.enc_pushsample(tempraw, 0) - class InstrumentedSampleTRH(InstrumentedSample): FORMAT_HDC2021_TRH = 1 @@ -230,26 +240,5 @@ def pushsamples(self, num): self.ffimodule.lib.enc_pushsample(tempsmpl['adc'], rhsmpl['adc']) return inlist - def pushsamplelist(self, trhlist: list): - """ - - :param trhlist: a list of dictionaries each containing temperature and relative humidity keys. - :return: None - """ - for smpldict in trhlist: - tempdegc = smpldict['temp'] - rhpc = smpldict['rh'] - tempraw = self.temp_degc_to_raw(tempdegc) - rhraw = self.rh_percent_to_raw(rhpc) - self.ffimodule.lib.enc_pushsample(tempraw, rhraw) - - def updateendstop(self, minutes: int): - """ Update the endstop with minutes elapsed since the most recent sample. - - :param minutes: Minutes elapsed since the most recent sample. - :return: None - """ - self.ffimodule.lib.enc_setelapsed(minutes) - def geturlqs(self): return self.eepromba.get_url_parsedqs()