Fix light sensor parsing
This commit is contained in:
0
rpi/hardware/light/__init__.py
Normal file
0
rpi/hardware/light/__init__.py
Normal file
27
rpi/hardware/light/lora_light_sensor_reader.py
Normal file
27
rpi/hardware/light/lora_light_sensor_reader.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
import re
|
||||
from re import Pattern
|
||||
|
||||
from hardware.generic.serial_reader import SerialReader
|
||||
|
||||
class LoraLightSensorReader(SerialReader):
|
||||
|
||||
json_pattern : Pattern = None
|
||||
|
||||
def __init__(self, port, baudrate):
|
||||
super().__init__(port, baudrate)
|
||||
self.json_pattern = re.compile(r'\{.*}')
|
||||
|
||||
def __read(self):
|
||||
while self._run_event.is_set():
|
||||
line = self.serial.readline().decode('utf-8', errors='ignore').strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
match = self.json_pattern.search(line)
|
||||
if match:
|
||||
try:
|
||||
data = json.loads(match.group())
|
||||
print("Received JSON:", data)
|
||||
except json.JSONDecodeError:
|
||||
print("Received invalid JSON:", match.group())
|
||||
@@ -1,8 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
from collections.abc import Callable
|
||||
from threading import Thread
|
||||
import threading
|
||||
from serial import Serial
|
||||
|
||||
from hardware.generic.serial_reader import SerialReader
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
import cv2
|
||||
from flask import Flask
|
||||
|
||||
from hardware.generic.serial_reader import SerialReader
|
||||
from hardware.light.lora_light_sensor_reader import LoraLightSensorReader
|
||||
from hardware.screen.screen import Screen
|
||||
from hardware.rfid.reader import RfidReader
|
||||
from services.detection_service import DetectionService
|
||||
@@ -13,7 +12,7 @@ app = Flask(__name__)
|
||||
screen = Screen()
|
||||
mqtt_service = MQTTService("127.0.0.1", 1883)
|
||||
rfid_reader = RfidReader("/dev/serial0", 9600)
|
||||
light_sensor_reader = SerialReader("/dev/ttyUSB1", 57600)
|
||||
light_sensor_reader = LoraLightSensorReader("/dev/ttyUSB1", 57600)
|
||||
detection_service = DetectionService()
|
||||
|
||||
@app.route("/party/start", methods=['POST'])
|
||||
@@ -59,8 +58,6 @@ if __name__ == "__main__":
|
||||
print(e)
|
||||
exit_app()
|
||||
|
||||
|
||||
|
||||
"""
|
||||
def get_move(prompt, move_queue):
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user