1
0

Add scanner

This commit is contained in:
2026-02-20 21:53:52 +01:00
parent 6517709ea7
commit eece17b9db
7 changed files with 325 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
import serial
import struct
import time
import time
def crc8(data: bytes) -> int:
crc = 0x00
@@ -15,13 +16,16 @@ class I2CPCClient:
def __init__(self, port, baudrate=115200, timeout=1):
self.ser = serial.Serial(port=port, baudrate=baudrate, timeout=timeout)
# Gurantees resync
self.ser.write(b"~/")
self.ser.write(b"\x00"*64)
self.ser.write(b"\x00"*128)
self.ser.flush()
self.ser.write(b"~/")
self.ser.flush()
while not ((d := self.ser.read_all()) and b"\xff" in d): time.sleep(0.01)
start = time.monotonic()
while not ((d := self.ser.read_all()) and b"\xff" in d):
time.sleep(0.01)
if ((time.monotonic()) - start) > 5: raise ConnectionError("Could not wake")
def _send_packet(self, payload: bytes, crc: bool = True):
if len(payload) > 127: raise ValueError("Payload too large")