display and espmega driver

This commit is contained in:
Siwat Sirichai 2023-11-06 15:42:06 +07:00
parent 5e019fef20
commit 29e28b8dca
21 changed files with 43 additions and 9 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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

View File

@ -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

BIN
display/DoorOpen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

Binary file not shown.

BIN
display/Fonts/roboto-14.zi Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
display/Fonts/roboto-16.zi Normal file

Binary file not shown.

Binary file not shown.

BIN
display/Fonts/roboto-24.zi Normal file

Binary file not shown.

Binary file not shown.

BIN
display/Fonts/roboto-56.zi Normal file

Binary file not shown.

Binary file not shown.

BIN
display/Scan Parent.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

BIN
display/Scan Student.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

BIN
display/display.HMI Normal file

Binary file not shown.

BIN
display/home.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB