From 9de0775c9b1dd5bdaf6634692c8b6519a736ba60 Mon Sep 17 00:00:00 2001 From: JR Rickerson Date: Mon, 24 Apr 2023 17:33:47 -0400 Subject: [PATCH 1/3] Allow configuration of the low voltage alarm Enable read/write properties for the 0x13 (low voltage RSOC threshold) and 0x14 (low voltage value register) --- adafruit_lc709203f.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/adafruit_lc709203f.py b/adafruit_lc709203f.py index 16336e4..fd32ce9 100644 --- a/adafruit_lc709203f.py +++ b/adafruit_lc709203f.py @@ -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: @@ -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""" From 06170bce39de9da0bce337cf077940f496ab0340 Mon Sep 17 00:00:00 2001 From: JR Rickerson Date: Mon, 24 Apr 2023 18:39:09 -0400 Subject: [PATCH 2/3] Make pylint happy --- adafruit_lc709203f.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_lc709203f.py b/adafruit_lc709203f.py index fd32ce9..83b1ab4 100644 --- a/adafruit_lc709203f.py +++ b/adafruit_lc709203f.py @@ -245,7 +245,7 @@ def low_voltage_alarm_percent(self) -> int: 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): + if not 0 < percent < 100: raise ValueError("alarm voltage percent must be 0-100") self._write_word(LC709203F_CMD_ALARMPERCENT, percent) From 86993612e5cd8766fb1ad85bb71e5d9950d47b88 Mon Sep 17 00:00:00 2001 From: JR Rickerson Date: Fri, 28 Apr 2023 12:36:41 -0400 Subject: [PATCH 3/3] Correct the percent range check --- adafruit_lc709203f.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_lc709203f.py b/adafruit_lc709203f.py index 83b1ab4..72fc171 100644 --- a/adafruit_lc709203f.py +++ b/adafruit_lc709203f.py @@ -245,7 +245,7 @@ def low_voltage_alarm_percent(self) -> int: 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: + if not 0 <= percent <= 100: raise ValueError("alarm voltage percent must be 0-100") self._write_word(LC709203F_CMD_ALARMPERCENT, percent)