Skip to content

Commit a294f4c

Browse files
authored
Merge pull request #25 from jrrickerson/config_voltage_alarm
Allow configuration of the low voltage alarm
2 parents 3f3b459 + 8699361 commit a294f4c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

adafruit_lc709203f.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
LC709203F_CMD_CELLTEMPERATURE = const(0x08)
6060
LC709203F_CMD_THERMISTORB = const(0x06)
6161
LC709203F_CMD_STATUSBIT = const(0x16)
62+
LC709203F_CMD_ALARMPERCENT = const(0x13)
63+
LC709203F_CMD_ALARMVOLTAGE = const(0x14)
6264

6365

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

238+
@property
239+
def low_voltage_alarm_percent(self) -> int:
240+
"""Return the current low voltage alarm percentage.
241+
0 indicates disabled."""
242+
return self._read_word(LC709203F_CMD_ALARMPERCENT)
243+
244+
@low_voltage_alarm_percent.setter
245+
def low_voltage_alarm_percent(self, percent: int) -> None:
246+
"""Set the low voltage alarm percentage.
247+
Value of 0 disables the alarm"""
248+
if not 0 <= percent <= 100:
249+
raise ValueError("alarm voltage percent must be 0-100")
250+
self._write_word(LC709203F_CMD_ALARMPERCENT, percent)
251+
252+
@property
253+
def low_voltage_alarm(self) -> int:
254+
"""Return the current low voltage alarm value in mV
255+
0 indicates disabled"""
256+
return self._read_word(LC709203F_CMD_ALARMVOLTAGE)
257+
258+
@low_voltage_alarm.setter
259+
def low_voltage_alarm(self, voltage: int) -> None:
260+
"""Set the low voltage alarm value in mV.
261+
Value of 0 disables the alarm."""
262+
self._write_word(LC709203F_CMD_ALARMVOLTAGE, voltage)
263+
236264
# pylint: disable=no-self-use
237265
def _generate_crc(self, data: ReadableBuffer) -> int:
238266
"""8-bit CRC algorithm for checking data"""

0 commit comments

Comments
 (0)