@toffee This is how my first attempt of changing init,. read_word and write_word would look like. Untested of course, since I do not have that device.
def __init__(self, i2c, i2c_address=LC709023F_I2CADDR_DEFAULT):
self.i2c = i2c
self.i2c_address = i2c_address
self._buf = bytearray(10)
self.power_mode = PowerMode.OPERATE # pylint: disable=no-member
self.pack_size = PackSize.MAH500 # pylint: disable=no-member
self.battery_profile = 1
self.init_RSOC()
def _read_word(self, command):
self._buf[0] = self.i2c_address * 2 # write byte
self._buf[1] = command # command / register
self._buf[2] = self._buf[0] | 0x1 # read byte
data = self.i2c.readfrom_mem(self.i2c_address, command)
if len(data) != 3:
raise RuntimeError("Insufficient data on reading word")
self._buf[3:6] = data
crc8 = self._generate_crc(self._buf[0:6])
if crc8 != 0:
raise RuntimeError("CRC failure on reading word")
return (self._buf[4] << 8) | self._buf[3]
def _write_word(self, command, data):
self._buf[0] = self.i2c_address * 2 # write byte
self._buf[1] = command # command / register
self._buf[2] = data & 0xFF
self._buf[3] = (data >> 8) & 0xFF
self._buf[4] = self._generate_crc(self._buf[0:4])
self.i2c.writeto_mem(self.i2c_address, command, buf[2:5])