Skip to content

Commit

Permalink
Merge pull request #25 from jrrickerson/config_voltage_alarm
Browse files Browse the repository at this point in the history
Allow configuration of the low voltage alarm
  • Loading branch information
tekktrik authored May 1, 2023
2 parents 3f3b459 + 8699361 commit a294f4c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions adafruit_lc709203f.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
LC709203F_CMD_CELLTEMPERATURE = const(0x08)
LC709203F_CMD_THERMISTORB = const(0x06)
LC709203F_CMD_STATUSBIT = const(0x16)
LC709203F_CMD_ALARMPERCENT = const(0x13)
LC709203F_CMD_ALARMVOLTAGE = const(0x14)


class CV:
Expand Down Expand Up @@ -233,6 +235,32 @@ def thermistor_enable(self, status: bool) -> None:
raise ValueError("thermistor_enable must be True or False")
self._write_word(LC709203F_CMD_STATUSBIT, status)

@property
def low_voltage_alarm_percent(self) -> int:
"""Return the current low voltage alarm percentage.
0 indicates disabled."""
return self._read_word(LC709203F_CMD_ALARMPERCENT)

@low_voltage_alarm_percent.setter
def low_voltage_alarm_percent(self, percent: int) -> None:
"""Set the low voltage alarm percentage.
Value of 0 disables the alarm"""
if not 0 <= percent <= 100:
raise ValueError("alarm voltage percent must be 0-100")
self._write_word(LC709203F_CMD_ALARMPERCENT, percent)

@property
def low_voltage_alarm(self) -> int:
"""Return the current low voltage alarm value in mV
0 indicates disabled"""
return self._read_word(LC709203F_CMD_ALARMVOLTAGE)

@low_voltage_alarm.setter
def low_voltage_alarm(self, voltage: int) -> None:
"""Set the low voltage alarm value in mV.
Value of 0 disables the alarm."""
self._write_word(LC709203F_CMD_ALARMVOLTAGE, voltage)

# pylint: disable=no-self-use
def _generate_crc(self, data: ReadableBuffer) -> int:
"""8-bit CRC algorithm for checking data"""
Expand Down

0 comments on commit a294f4c

Please sign in to comment.