Skip to content
Snippets Groups Projects

Bonding dialog

Merged schneider requested to merge schneider/mp-bonding into master
1 file
+ 73
28
Compare changes
  • Side-by-side
  • Inline
+ 73
28
@@ -9,29 +9,21 @@ CONFIG_NAME = "ble.txt"
MAC_NAME = "mac.txt"
ACTIVE_STRING = "active=true"
INACTIVE_STRING = "active=false"
event = None
def numeric_comparison_callback(_):
compare_value = sys_ble.get_compare_value()
disp.clear()
disp.print("confirm:", posy=0, fg=[0, 255, 255])
disp.print("%d" % compare_value, posy=20, fg=[255, 0, 0])
disp.update()
while True:
v = buttons.read()
if v & buttons.TOP_RIGHT:
sys_ble.confirm_compare_value()
break
elif v != 0:
break
utime.sleep(0.1)
def ble_callback(_):
global event
event = sys_ble.get_event()
def init():
if CONFIG_NAME not in os.listdir("."):
with open(CONFIG_NAME, "w") as f:
f.write(INACTIVE_STRING)
interrupt.set_callback(10, numeric_comparison_callback)
interrupt.set_callback(10, ble_callback)
interrupt.enable_callback(10)
sys_ble.set_bondable(True)
def load_mac():
@@ -86,21 +78,74 @@ def selector():
disp.print("toggle", posx=25, posy=40, fg=[255, 255, 255])
disp = display.open()
button_pressed = True
init()
disp = display.open()
state = 1
v_old = buttons.read()
while True:
disp.clear()
headline()
v = buttons.read(buttons.TOP_RIGHT)
if v == 0:
button_pressed = False
if not button_pressed and v & buttons.TOP_RIGHT != 0:
button_pressed = True
toggle()
v_new = buttons.read()
v = ~v_old & v_new
v_old = v_new
if state == 1:
# print config screen
disp.clear()
headline()
selector()
disp.update()
state = 2
elif state == 2:
# wait for button press or event
if event == 1:
event = 0
state = 3
if v & buttons.TOP_RIGHT:
toggle()
state = 1
elif state == 3:
# print confirmation value
compare_value = sys_ble.get_compare_value()
disp.clear()
disp.print("confirm:", posy=0, fg=[0, 255, 255])
disp.print("%06d" % compare_value, posy=20, fg=[255, 0, 0])
disp.update()
state = 4
elif state == 4:
# wait for button press or event
if event == 2:
event = 0
state = 6
if v & buttons.BOTTOM_RIGHT:
sys_ble.confirm_compare_value(True)
disp.clear()
disp.print("Wait", posy=0, fg=[0, 255, 255])
disp.update()
state = 5
elif v & buttons.BOTTOM_LEFT:
sys_ble.confirm_compare_value(False)
state = 1
elif state == 5:
# Wait for pairing to complete
if event == 2:
event = 0
state = 6
elif event == 3:
event = 0
disp.clear()
disp.print("OK", posy=0, fg=[0, 255, 255])
disp.update()
time.sleep(5)
state = 1
elif state == 6:
# display fail screen and wait 5 seconds
disp.clear()
disp.print("Fail", posy=0, fg=[0, 255, 255])
disp.update()
time.sleep(5)
state = 1
selector()
disp.update()
time.sleep(0.1)
Loading