mirror of
https://github.com/bitlair/bitlair_doorduino.git
synced 2025-05-13 12:20:07 +02:00
Add button management scripts
This commit is contained in:
parent
db8695250c
commit
dd4203c06f
3 changed files with 114 additions and 0 deletions
52
list_buttons.py
Executable file
52
list_buttons.py
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/python3
|
||||
import serial
|
||||
import time
|
||||
import sys
|
||||
|
||||
def list_buttons(ser):
|
||||
ser.write(b'\r\n')
|
||||
time.sleep(0.1)
|
||||
ser.write(b'list_buttons\r\n')
|
||||
|
||||
expect_button_line = False
|
||||
buttons_in_arduino = []
|
||||
while True:
|
||||
line = ser.readline()
|
||||
if line.strip() == b"button list start":
|
||||
expect_button_line = True
|
||||
continue
|
||||
|
||||
if expect_button_line and line.startswith(b"button: "):
|
||||
key, val = line.strip().split(b" ")
|
||||
buttons_in_arduino.append(val)
|
||||
if line == b"":
|
||||
break
|
||||
buttons_in_arduino.sort()
|
||||
print(len(buttons_in_arduino))
|
||||
return buttons_in_arduino
|
||||
|
||||
def remove_button(ser, button):
|
||||
ser.write(b'\r\n')
|
||||
time.sleep(0.1)
|
||||
ser.write(b'remove_button '+ button + b'\r\n')
|
||||
while True:
|
||||
line = ser.readline()
|
||||
if line == b"":
|
||||
break
|
||||
print(line)
|
||||
|
||||
def add_button(ser, button, secret):
|
||||
ser.write(b'\r\n')
|
||||
time.sleep(0.1)
|
||||
ser.write(b'add_button '+ button + b' ' + secret + b'\r\n')
|
||||
while True:
|
||||
line = ser.readline()
|
||||
if line == b"":
|
||||
break
|
||||
print(line)
|
||||
|
||||
|
||||
for tty in [ "/dev/ttyS1", "/dev/ttyS2" ]:
|
||||
with serial.Serial(tty, 115200, timeout=1) as ser:
|
||||
print(list_buttons(ser))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue