Skip to content

Commit 4bb3ac2

Browse files
committed
Moved some methods to the InstrumentedSample parent class. This means we should be able to get both temperature and temperature/relative humidity simulations.
1 parent a811135 commit 4bb3ac2

2 files changed

Lines changed: 23 additions & 34 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setuptools.setup(
88
name="cuplcodec",
9-
version="2.0.5",
9+
version="2.0.6",
1010
author="Malcolm Mackay",
1111
author_email="malcolm@plotsensor.com",
1212
description="Package for creating and decoding URLs that contain temperature and humidity samples.",

wscodec/encoder/pyencoder/instrumented.py

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ def temp_degc_to_raw(self, degc):
122122
""" Converts degrees C to a raw ADC value for the Texas HDC2010. """
123123
return int((degc + 40) * 4096 / 165)
124124

125-
126125
def rh_percent_to_raw(self, rhpc):
127126
""" Converts from relative humidity in percent to a raw ADC value for the Texas HDC2010. """
128127
return int((rhpc * 4096) / 100)
@@ -143,6 +142,28 @@ def rhsample(self, countermax, counterstep):
143142
rawrh = self.rh_percent_to_raw(counter)
144143
yield {'adc': rawrh, 'ref': counter}
145144

145+
def pushsamplelist(self, trhlist: list):
146+
"""
147+
148+
:param trhlist: a list of dictionaries each containing temperature and relative humidity keys.
149+
:return: None
150+
"""
151+
for smpldict in trhlist:
152+
tempdegc = smpldict['temp']
153+
rhpc = smpldict['rh']
154+
tempraw = self.temp_degc_to_raw(tempdegc)
155+
rhraw = self.rh_percent_to_raw(rhpc)
156+
# rhraw is ignored (set to -1) inside enc_pushsample if the format is temperature only.
157+
self.ffimodule.lib.enc_pushsample(tempraw, rhraw)
158+
159+
def updateendstop(self, minutes: int):
160+
""" Update the endstop with minutes elapsed since the most recent sample.
161+
162+
:param minutes: Minutes elapsed since the most recent sample.
163+
:return: None
164+
"""
165+
self.ffimodule.lib.enc_setelapsed(minutes)
166+
146167

147168
class InstrumentedSampleT(InstrumentedSample):
148169
FORMAT_HDC2021_TEMPONLY = 2
@@ -180,17 +201,6 @@ def pushsamples(self, num):
180201
self.ffimodule.lib.enc_pushsample(tempsmpl['adc'], 0)
181202
return inlist
182203

183-
def pushsamplelist(self, tlist: list):
184-
"""
185-
186-
:param tlist: a list of dictionaries each containing temperature keys.
187-
:return: None
188-
"""
189-
for smpldict in tlist:
190-
tempdegc = smpldict['temp']
191-
tempraw = self.temp_degc_to_raw(tempdegc)
192-
self.ffimodule.lib.enc_pushsample(tempraw, 0)
193-
194204

195205
class InstrumentedSampleTRH(InstrumentedSample):
196206
FORMAT_HDC2021_TRH = 1
@@ -230,26 +240,5 @@ def pushsamples(self, num):
230240
self.ffimodule.lib.enc_pushsample(tempsmpl['adc'], rhsmpl['adc'])
231241
return inlist
232242

233-
def pushsamplelist(self, trhlist: list):
234-
"""
235-
236-
:param trhlist: a list of dictionaries each containing temperature and relative humidity keys.
237-
:return: None
238-
"""
239-
for smpldict in trhlist:
240-
tempdegc = smpldict['temp']
241-
rhpc = smpldict['rh']
242-
tempraw = self.temp_degc_to_raw(tempdegc)
243-
rhraw = self.rh_percent_to_raw(rhpc)
244-
self.ffimodule.lib.enc_pushsample(tempraw, rhraw)
245-
246-
def updateendstop(self, minutes: int):
247-
""" Update the endstop with minutes elapsed since the most recent sample.
248-
249-
:param minutes: Minutes elapsed since the most recent sample.
250-
:return: None
251-
"""
252-
self.ffimodule.lib.enc_setelapsed(minutes)
253-
254243
def geturlqs(self):
255244
return self.eepromba.get_url_parsedqs()

0 commit comments

Comments
 (0)