diff --git a/gauge.py b/gauge.py index b0cdd47..592671d 100644 --- a/gauge.py +++ b/gauge.py @@ -146,7 +146,7 @@ ARDUINO_TX_PIN = int(_cfg.get("arduino_tx_pin", 17)) ARDUINO_RX_PIN = int(_cfg.get("arduino_rx_pin", 16)) ARDUINO_BAUD = int(_cfg.get("arduino_baud", 115200)) -_arduino = UART(ARDUINO_UART_ID, baudrate=ARDUINO_BAUD, tx=ARDUINO_TX_PIN, rx=ARDUINO_RX_PIN) +_arduino = UART(ARDUINO_UART_ID, baudrate=ARDUINO_BAUD, tx=ARDUINO_TX_PIN, rx=ARDUINO_RX_PIN, timeout=10) def arduino_send(cmd): @@ -155,6 +155,14 @@ def arduino_send(cmd): info(f"Arduino → {cmd}") +def arduino_recv(): + """Print any lines waiting in the Arduino RX buffer.""" + while _arduino.any(): + line = _arduino.readline() + if line: + print(f"[{_ts()}] ARDU {line.decode().strip()}") + + # --------------------------------------------------------------------------- # Arduino command helpers # --------------------------------------------------------------------------- @@ -845,6 +853,7 @@ def main(): continue client_ref.check_msg() + arduino_recv() _flush_backlight_state() # Periodic re-home