26 lines
779 B
Python
26 lines
779 B
Python
#!/usr/bin/env python3
|
|
import smbus2
|
|
from inachip import *
|
|
|
|
|
|
class PowerMon:
|
|
def __init__(self, sensors: list):
|
|
self.bus = smbus2.SMBus(1)
|
|
self.sensors = sensors
|
|
self.chipObjs = []
|
|
try:
|
|
ina = None
|
|
for i in range(len(sensors)):
|
|
if type(list[i]) is int:
|
|
ina = INA226(self.bus, sensors[i])
|
|
else:
|
|
ina = INA226(self.bus, sensors[i][0], sensors[i][1])
|
|
self.chipObjs.append(ina)
|
|
except Exception as e:
|
|
raise Exception("Initiating sensors failed: " + e)
|
|
|
|
def getData(self) -> list[PowerData]:
|
|
results = []
|
|
for chip in self.chipObjs:
|
|
results.append(chip.getData())
|
|
return results
|