Skip to content

Commit

Permalink
Merge pull request #10 from semininja/main
Browse files Browse the repository at this point in the history
enable selection of polling rate
  • Loading branch information
dhalbert authored Nov 28, 2023
2 parents 366845d + 7c9b45e commit f668c62
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions cedargrove_nau7802.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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:
Expand All @@ -253,6 +253,28 @@ def gain(self, factor=1):
elif self._gain == 128:
self._c1_gains = Gain.GAIN_X128

@property
def poll_rate(self):
"""ADC conversion/polling rate."""
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
Expand Down

0 comments on commit f668c62

Please sign in to comment.