load-controller/load_controller/load.py

34 lines
787 B
Python
Raw Normal View History

2023-01-03 22:57:18 +01:00
import serial
import time
2023-01-04 16:53:42 +01:00
from PySide6.QtCore import QObject
2023-01-04 00:22:27 +01:00
from .profile_handler import ProfileHandler
2023-01-03 22:57:18 +01:00
class Load(QObject):
dev: serial.Serial
2023-01-04 00:22:27 +01:00
_current: float
def __init__(self, uart_path: str, profile_handler: ProfileHandler):
super().__init__(None)
self.dev = serial.Serial(uart_path, 115200)
self._current = 0
profile_handler.current_changed.connect(self._update_current)
def _update_current(self, current):
self._current = current
2023-01-03 22:57:18 +01:00
def do_work(self):
while True:
time.sleep(0.1)
2023-01-04 00:22:27 +01:00
curr_quants = round(self._current / 0.1)
assert curr_quants <= 0xFFFF
msb = curr_quants >> 8
lsb = curr_quants & 0xFF
self.dev.write(bytes((msb, lsb)))