Skip to content

Allow configuration of the low voltage alarm #25

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 3 commits into from
May 1, 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: 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