import serial import time from PyQt6.QtCore import QObject from .profile_handler import ProfileHandler class Load(QObject): dev: serial.Serial _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 def do_work(self): while True: time.sleep(0.1) 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)))