capstone/powermon.py
2025-12-14 18:16:48 -05:00

24 lines
694 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)):
ina = INA226(self.bus, sensors[i][0], sensors[i][1], sensors[i][2], sensors[i][3])
self.chipObjs.append(ina)
except Exception as e:
e.add_note("Initiating sensors failed")
raise
def getData(self) -> list[PowerData]:
results = []
for chip in self.chipObjs:
results.append(chip.getData())
return results