You've already forked TEF6686_Driver
Add scanner
This commit is contained in:
10
protocol.py
10
protocol.py
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user