Skip to content

enable selection of polling rate #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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