Skip to content
Snippets Groups Projects
Commit 7101fbc2 authored by schneider's avatar schneider
Browse files

fix(ble): Consume all events in ble app

parent bcb6ccc1
No related branches found
No related tags found
1 merge request!446Initial MicroPython BLE support (GATTS)
Pipeline #5130 passed
......@@ -6,7 +6,7 @@ import sys_ble
import interrupt
import config
ble_event = None
ble_events = []
is_active = False
STATE_IDLE = 1
......@@ -16,8 +16,13 @@ STATE_FAIL = 4
def ble_callback(_):
global ble_event
ble_event = sys_ble.get_event()
global ble_events
while True:
event = sys_ble.get_event()
if event == sys_ble.EVENT_NONE:
break
ble_events.append(event)
def init():
......@@ -95,6 +100,11 @@ while True:
v = ~v_old & v_new
v_old = v_new
ble_event = None
if len(ble_events) > 0:
ble_event = ble_events[0]
ble_events = ble_events[1:]
if state == STATE_IDLE:
# print config screen
disp.clear()
......@@ -104,7 +114,6 @@ while True:
# wait for button press or ble_event
if ble_event == sys_ble.EVENT_HANDLE_NUMERIC_COMPARISON:
ble_event = None
state = STATE_NUMERIC_COMPARISON
if v & buttons.TOP_RIGHT:
toggle()
......@@ -128,7 +137,6 @@ while True:
# wait for button press or ble_event
if ble_event == sys_ble.EVENT_PAIRING_FAILED:
ble_event = None
state = STATE_FAIL
if v & buttons.BOTTOM_LEFT:
sys_ble.confirm_compare_value(True)
......@@ -144,10 +152,8 @@ while True:
elif state == STATE_WAIT_FOR_COMPLETION:
# Wait for pairing to complete
if ble_event == sys_ble.EVENT_PAIRING_FAILED:
ble_event = None
state = STATE_FAIL
elif ble_event == sys_ble.EVENT_PAIRING_COMPLETE:
ble_event = None
pairing_name = sys_ble.get_last_pairing_name().split("/")[-1].split(".")[0]
disp.clear()
disp.print("BLE Pairing", posy=0, fg=[0, 0, 255])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment