Merge remote-tracking branch 'origin/MichaelBell-battery-improvements' into battery-improvements
This commit is contained in:
commit
be0f1358d1
|
@ -54,7 +54,9 @@ def state_running():
|
|||
|
||||
|
||||
def state_clear_running():
|
||||
running = state_running()
|
||||
state_modify("launcher", {"running": "launcher"})
|
||||
return running != "launcher"
|
||||
|
||||
|
||||
def state_set_running(app):
|
||||
|
@ -110,8 +112,6 @@ def launch(file):
|
|||
|
||||
def quit_to_launcher(pin):
|
||||
if button_a.value() and button_c.value():
|
||||
state_clear_running()
|
||||
time.sleep(0.1) # Needed to stop write fail
|
||||
machine.reset()
|
||||
|
||||
button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=quit_to_launcher)
|
||||
|
|
|
@ -94,7 +94,7 @@ if TOTAL_IMAGES == 0:
|
|||
|
||||
badger_os.state_load("image", state)
|
||||
|
||||
changed = not display.woken()
|
||||
changed = not badger2040.woken_by_button()
|
||||
|
||||
|
||||
while True:
|
||||
|
|
|
@ -10,9 +10,13 @@ import badger_os
|
|||
# Reduce clock speed to 48MHz, that's fast enough!
|
||||
machine.freq(48000000)
|
||||
|
||||
changed = False
|
||||
exited_to_launcher = False
|
||||
woken_by_button = badger2040.woken_by_button() # Must be done before we clear_pressed_to_wake
|
||||
|
||||
if badger2040.pressed_to_wake(badger2040.BUTTON_A) and badger2040.pressed_to_wake(badger2040.BUTTON_C):
|
||||
# Pressing A and C together at start quits app
|
||||
badger_os.state_clear_running()
|
||||
exited_to_launcher = badger_os.state_clear_running()
|
||||
badger2040.clear_pressed_to_wake()
|
||||
else:
|
||||
# Otherwise restore previously running app
|
||||
|
@ -33,7 +37,8 @@ state = {
|
|||
}
|
||||
|
||||
badger_os.state_load("launcher", state)
|
||||
changed = state["running"] != "launcher"
|
||||
|
||||
display.invert(state["inverted"])
|
||||
|
||||
icons = bytearray(launchericons.data())
|
||||
icons_width = 576
|
||||
|
@ -155,10 +160,15 @@ def render():
|
|||
display.update()
|
||||
|
||||
|
||||
def launch_example(index):
|
||||
while display.pressed(badger2040.BUTTON_A) or display.pressed(badger2040.BUTTON_B) or display.pressed(badger2040.BUTTON_C) or display.pressed(badger2040.BUTTON_UP) or display.pressed(badger2040.BUTTON_DOWN):
|
||||
def wait_for_user_to_release_buttons():
|
||||
pr = display.pressed
|
||||
while pr(badger2040.BUTTON_A) or pr(badger2040.BUTTON_B) or pr(badger2040.BUTTON_C) or pr(badger2040.BUTTON_UP) or pr(badger2040.BUTTON_DOWN):
|
||||
time.sleep(0.01)
|
||||
|
||||
|
||||
def launch_example(index):
|
||||
wait_for_user_to_release_buttons()
|
||||
|
||||
file = examples[(state["page"] * 3) + index][0]
|
||||
|
||||
for k in locals().keys():
|
||||
|
@ -206,16 +216,12 @@ def button(pin):
|
|||
render()
|
||||
|
||||
|
||||
if changed:
|
||||
# Wait for any wakeup button to be released
|
||||
while display.pressed(badger2040.BUTTON_A) or display.pressed(badger2040.BUTTON_B) or display.pressed(badger2040.BUTTON_C) or display.pressed(badger2040.BUTTON_UP) or display.pressed(badger2040.BUTTON_DOWN):
|
||||
time.sleep(0.01)
|
||||
if exited_to_launcher or not woken_by_button:
|
||||
wait_for_user_to_release_buttons()
|
||||
display.update_speed(badger2040.UPDATE_MEDIUM)
|
||||
render()
|
||||
|
||||
display.update_speed(badger2040.UPDATE_FAST)
|
||||
if not changed and not display.woken():
|
||||
render()
|
||||
|
||||
while True:
|
||||
if display.pressed(badger2040.BUTTON_A):
|
||||
|
|
|
@ -9,9 +9,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_is_busy_obj, Badger2040_is_busy);
|
|||
MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_update_obj, Badger2040_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(Badger2040_partial_update_obj, 4, Badger2040_partial_update);
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_halt_obj, Badger2040_halt);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_woken_obj, Badger2040_woken);
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(Badger2040_invert_obj, Badger2040_invert);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(Badger2040_led_obj, Badger2040_led);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(Badger2040_font_obj, Badger2040_font);
|
||||
|
@ -38,6 +35,8 @@ MP_DEFINE_CONST_FUN_OBJ_3(Badger2040_command_obj, Badger2040_command);
|
|||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_pressed_to_wake_obj, Badger2040_pressed_to_wake);
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(Badger2040_clear_pressed_to_wake_obj, Badger2040_clear_pressed_to_wake);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_halt_obj, Badger2040_halt);
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(Badger2040_woken_by_button_obj, Badger2040_woken_by_button);
|
||||
|
||||
/***** Binding of Methods *****/
|
||||
STATIC const mp_rom_map_elem_t Badger2040_locals_dict_table[] = {
|
||||
|
@ -48,7 +47,6 @@ STATIC const mp_rom_map_elem_t Badger2040_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_partial_update), MP_ROM_PTR(&Badger2040_partial_update_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_halt), MP_ROM_PTR(&Badger2040_halt_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_woken), MP_ROM_PTR(&Badger2040_woken_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_invert), MP_ROM_PTR(&Badger2040_invert_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_led), MP_ROM_PTR(&Badger2040_led_obj) },
|
||||
|
@ -95,6 +93,7 @@ STATIC const mp_rom_map_elem_t badger2040_globals_table[] = {
|
|||
|
||||
{ MP_ROM_QSTR(MP_QSTR_pressed_to_wake), MP_ROM_PTR(&Badger2040_pressed_to_wake_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear_pressed_to_wake), MP_ROM_PTR(&Badger2040_clear_pressed_to_wake_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_woken_by_button), MP_ROM_PTR(&Badger2040_woken_by_button_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_UPDATE_NORMAL), MP_ROM_INT(0) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_UPDATE_MEDIUM), MP_ROM_INT(1) },
|
||||
|
|
|
@ -213,8 +213,7 @@ MICROPY_EVENT_POLL_HOOK
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t Badger2040_woken(mp_obj_t self_in) {
|
||||
(void)self_in;
|
||||
mp_obj_t Badger2040_woken_by_button() {
|
||||
return button_wake_state.any() ? mp_const_true : mp_const_false;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ extern mp_obj_t Badger2040_update(mp_obj_t self_in);
|
|||
extern mp_obj_t Badger2040_partial_update(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
|
||||
extern mp_obj_t Badger2040_halt(mp_obj_t self_in);
|
||||
extern mp_obj_t Badger2040_woken(mp_obj_t self_in);
|
||||
|
||||
extern mp_obj_t Badger2040_invert(mp_obj_t self_in, mp_obj_t invert);
|
||||
extern mp_obj_t Badger2040_led(mp_obj_t self_in, mp_obj_t brightness);
|
||||
|
@ -45,3 +44,4 @@ extern mp_obj_t Badger2040_command(mp_obj_t self_in, mp_obj_t reg, mp_obj_t data
|
|||
|
||||
extern mp_obj_t Badger2040_pressed_to_wake(mp_obj_t button);
|
||||
extern mp_obj_t Badger2040_clear_pressed_to_wake();
|
||||
extern mp_obj_t Badger2040_woken_by_button();
|
||||
|
|
Loading…
Reference in New Issue