class Bq27542(): def __init__(self): self.aa = Aardvark() self.i2c_addr = 0x55 def __del__(self): self.aa.die() def get_voltage(self): return self._reg_to_int(0x08) def get_current(self): return self._reg_to_int(0x14) def get_soc(self): return self._reg_to_int(0x04) def get_remcap(self): return self._reg_to_int(0x10) def get_fcc(self): return self._reg_to_int(0x12) def _reg_to_int(self, offset): bytes = self.aa.read(self.i2c_addr, offset, 2) if bytes < 0: return -999999999 res = struct.unpack('h', bytes)[0] return res
def __init__(self): self.aa = Aardvark() self.i2c_addr = 0x55