display and espmega driver
This commit is contained in:
parent
5e019fef20
commit
29e28b8dca
21 changed files with 43 additions and 9 deletions
|
@ -1,9 +1,11 @@
|
|||
import paho.mqtt.client as mqtt
|
||||
import espmega_mqtt.ESPMegaMQTT as ESPMegaMQTT
|
||||
|
||||
BASE_TOPIC = "/facescan"
|
||||
plc = ESPMegaMQTT()
|
||||
|
||||
class access_control:
|
||||
def __init__(self, serial_port: str):
|
||||
|
||||
pass
|
||||
|
||||
def light_on(self):
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
import serial
|
||||
class Display:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
def __init__(self, serial_port: str) -> None:
|
||||
self.serial_adapter = serial.Serial(serial_port,baudrate=115200)
|
||||
def set_page(self, page):
|
||||
command = f'page {page}'.encode("ascii")
|
||||
self.serial_adapter.write(command)
|
||||
self.send_stop_bit()
|
||||
def set_string(self, field, text):
|
||||
command = f'{field}="{text}"'.encode("ascii")
|
||||
self.serial_adapter.write(command)
|
||||
def send_stop_bit(self):
|
||||
self.serial_adapter.write(0xFF)
|
||||
self.serial_adapter.write(0xFF)
|
||||
self.serial_adapter.write(0xFF)
|
|
@ -1,7 +1,25 @@
|
|||
class espmega_mqtt:
|
||||
import paho.mqtt.client as pahomqtt
|
||||
BROKER = "192.168.0.26"
|
||||
BASE_TOPIC = "/facescan"
|
||||
class ESPMegaMQTT:
|
||||
input_buffer = [0]*16
|
||||
mqtt: pahomqtt.Client
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
def write_pwm():
|
||||
pass
|
||||
def read_digital():
|
||||
pass
|
||||
self.mqtt = pahomqtt.Client(client_id="pyfacescan")
|
||||
self.mqtt.connect(host=BROKER,port=1883,keepalive=60)
|
||||
self.mqtt.subscribe(f'{BASE_TOPIC}/input/#')
|
||||
self.mqtt.on_message=self.handle_message
|
||||
self.request_state()
|
||||
self.mqtt.loop_start()
|
||||
def write_pwm(self, id: int, state: bool, value: int = 4095):
|
||||
self.mqtt.publish(f'{BASE_TOPIC}/pwm/{"%02d"}/set/state'%id,"on" if state else "off")
|
||||
self.mqtt.publish(f'{BASE_TOPIC}/pwm/{"%02d"}/set/value'%id, str(value))
|
||||
def read_digital(self, id: int):
|
||||
return self.input_buffer[id]
|
||||
def request_state(self):
|
||||
self.mqtt.publish(f'{BASE_TOPIC}/requeststate',"req")
|
||||
def handle_message(self, client: pahomqtt.Client, data, message: pahomqtt.MQTTMessage):
|
||||
if (message.topic.startswith(BASE_TOPIC+"/input/")):
|
||||
id = int(message.topic[len(BASE_TOPIC)+7:len(message.topic)])
|
||||
state = int(message.payload)
|
||||
self.input_buffer[id] = state
|
|
@ -4,6 +4,7 @@ import time
|
|||
import face_processing as fp
|
||||
from access_control import access_control
|
||||
from database import database, Student, Parent
|
||||
from displ
|
||||
|
||||
SERIAL_PORT_STM32 = "COM12"
|
||||
SERIAL_PORT_DISPLAY = "COM15"
|
||||
|
@ -11,6 +12,7 @@ CAMERA_INDEX = 0
|
|||
|
||||
cam = cv2.VideoCapture(CAMERA_INDEX)
|
||||
stm32 = access_control(SERIAL_PORT_STM32)
|
||||
display =
|
||||
|
||||
global img
|
||||
global frame_ready
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue