From 926ce61ab38d8cb82bece1ed652f9435d337a1a5 Mon Sep 17 00:00:00 2001 From: semininja Date: Sat, 5 Aug 2023 23:30:06 -0400 Subject: [PATCH 1/2] enable selection of polling rate --- cedargrove_nau7802.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cedargrove_nau7802.py b/cedargrove_nau7802.py index a586925..145fa3c 100755 --- a/cedargrove_nau7802.py +++ b/cedargrove_nau7802.py @@ -214,7 +214,7 @@ def ldo_voltage(self): @ldo_voltage.setter def ldo_voltage(self, voltage="EXTERNAL"): """Select the LDO Voltage. Valid voltages are '2V4', '2V7', '3V0'.""" - if not "LDO_" + voltage in dir(LDOVoltage): + if not f"LDO_{voltage}" in dir(LDOVoltage): raise ValueError("Invalid LDO Voltage") self._ldo_voltage = voltage if self._ldo_voltage == "2V4": @@ -231,9 +231,9 @@ def gain(self): @gain.setter def gain(self, factor=1): - """Select PGA gain factor. Valid values are '1, 2, 4, 8, 16, 32, 64, + """Select PGA gain factor. Valid values are 1, 2, 4, 8, 16, 32, 64, and 128.""" - if not "GAIN_X" + str(factor) in dir(Gain): + if not f"GAIN_X{factor}" in dir(Gain): raise ValueError("Invalid Gain Factor") self._gain = factor if self._gain == 1: @@ -253,6 +253,27 @@ def gain(self, factor=1): elif self._gain == 128: self._c1_gains = Gain.GAIN_X128 + @property + def poll_rate(self): + return self._c2_conv_rate + + @poll_rate.setter + def poll_rate(self, rate=0): + """Select polling rate. Valid values are 10, 20, 40, 80, and 320.""" + if not f"RATE_{rate}SPS" in dir(ConversionRate): + raise ValueError("Invalid Conversion Rate") + self._rate = rate + if self._rate == 10: + self._c2_conv_rate = ConversionRate.RATE_10SPS + if self._rate == 20: + self._c2_conv_rate = ConversionRate.RATE_20SPS + if self._rate == 40: + self._c2_conv_rate = ConversionRate.RATE_40SPS + if self._rate == 80: + self._c2_conv_rate = ConversionRate.RATE_80SPS + if self._rate == 320: + self._c2_conv_rate = ConversionRate.RATE_320SPS + def enable(self, power=True): """Enable(start) or disable(stop) the internal analog and digital systems power. Enable = True; Disable (low power) = False. Returns From 7c9b45ecb864b3457e313f7567e4c63d2ed27f7a Mon Sep 17 00:00:00 2001 From: semininja Date: Sat, 5 Aug 2023 23:36:05 -0400 Subject: [PATCH 2/2] forgot a docstring --- cedargrove_nau7802.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cedargrove_nau7802.py b/cedargrove_nau7802.py index 145fa3c..f12fec4 100755 --- a/cedargrove_nau7802.py +++ b/cedargrove_nau7802.py @@ -255,6 +255,7 @@ def gain(self, factor=1): @property def poll_rate(self): + """ADC conversion/polling rate.""" return self._c2_conv_rate @poll_rate.setter