OpenCode experiments...
This commit is contained in:
18
gauge.py
18
gauge.py
@@ -152,19 +152,27 @@ 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, timeout=10)
|
||||
_arduino = None
|
||||
|
||||
|
||||
def _ensure_arduino():
|
||||
global _arduino
|
||||
if _arduino is None:
|
||||
_arduino = UART(ARDUINO_UART_ID, baudrate=ARDUINO_BAUD, tx=ARDUINO_TX_PIN, rx=ARDUINO_RX_PIN, timeout=10)
|
||||
return _arduino
|
||||
|
||||
|
||||
def arduino_send(cmd):
|
||||
"""Send a newline-terminated command to the Arduino."""
|
||||
_arduino.write((cmd + "\n").encode())
|
||||
_ensure_arduino().write((cmd + "\n").encode())
|
||||
info(f"Arduino → {cmd}")
|
||||
|
||||
|
||||
def arduino_recv():
|
||||
"""Print any lines waiting in the Arduino RX buffer."""
|
||||
while _arduino.any():
|
||||
line = _arduino.readline()
|
||||
uart = _ensure_arduino()
|
||||
while uart.any():
|
||||
line = uart.readline()
|
||||
if line:
|
||||
print(f"[{_ts()}] ARDU {line.decode().strip()}")
|
||||
|
||||
@@ -1333,6 +1341,8 @@ def main():
|
||||
_w.active(True)
|
||||
del _w
|
||||
gc.collect()
|
||||
_ensure_arduino()
|
||||
gc.collect()
|
||||
info("=" * 48)
|
||||
info("Gauge MQTT controller starting")
|
||||
info(f"Heap free: {gc.mem_free()} bytes")
|
||||
|
||||
Reference in New Issue
Block a user