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 ...@@ -6,7 +6,7 @@ import sys_ble
import interrupt import interrupt
import config import config
ble_event = None ble_events = []
is_active = False is_active = False
STATE_IDLE = 1 STATE_IDLE = 1
...@@ -16,8 +16,13 @@ STATE_FAIL = 4 ...@@ -16,8 +16,13 @@ STATE_FAIL = 4
def ble_callback(_): def ble_callback(_):
global ble_event global ble_events
ble_event = sys_ble.get_event()
while True:
event = sys_ble.get_event()
if event == sys_ble.EVENT_NONE:
break
ble_events.append(event)
def init(): def init():
...@@ -95,6 +100,11 @@ while True: ...@@ -95,6 +100,11 @@ while True:
v = ~v_old & v_new v = ~v_old & v_new
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: if state == STATE_IDLE:
# print config screen # print config screen
disp.clear() disp.clear()
...@@ -104,7 +114,6 @@ while True: ...@@ -104,7 +114,6 @@ while True:
# wait for button press or ble_event # wait for button press or ble_event
if ble_event == sys_ble.EVENT_HANDLE_NUMERIC_COMPARISON: if ble_event == sys_ble.EVENT_HANDLE_NUMERIC_COMPARISON:
ble_event = None
state = STATE_NUMERIC_COMPARISON state = STATE_NUMERIC_COMPARISON
if v & buttons.TOP_RIGHT: if v & buttons.TOP_RIGHT:
toggle() toggle()
...@@ -128,7 +137,6 @@ while True: ...@@ -128,7 +137,6 @@ while True:
# wait for button press or ble_event # wait for button press or ble_event
if ble_event == sys_ble.EVENT_PAIRING_FAILED: if ble_event == sys_ble.EVENT_PAIRING_FAILED:
ble_event = None
state = STATE_FAIL state = STATE_FAIL
if v & buttons.BOTTOM_LEFT: if v & buttons.BOTTOM_LEFT:
sys_ble.confirm_compare_value(True) sys_ble.confirm_compare_value(True)
...@@ -144,10 +152,8 @@ while True: ...@@ -144,10 +152,8 @@ while True:
elif state == STATE_WAIT_FOR_COMPLETION: elif state == STATE_WAIT_FOR_COMPLETION:
# Wait for pairing to complete # Wait for pairing to complete
if ble_event == sys_ble.EVENT_PAIRING_FAILED: if ble_event == sys_ble.EVENT_PAIRING_FAILED:
ble_event = None
state = STATE_FAIL state = STATE_FAIL
elif ble_event == sys_ble.EVENT_PAIRING_COMPLETE: elif ble_event == sys_ble.EVENT_PAIRING_COMPLETE:
ble_event = None
pairing_name = sys_ble.get_last_pairing_name().split("/")[-1].split(".")[0] pairing_name = sys_ble.get_last_pairing_name().split("/")[-1].split(".")[0]
disp.clear() disp.clear()
disp.print("BLE Pairing", posy=0, fg=[0, 0, 255]) 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.
Please register or to comment