Skip to content
Snippets Groups Projects
Commit 684ae0f9 authored by ave's avatar ave
Browse files

let micropython handle restarts for REPL mode when an app is running

parent c218fd08
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ target_sources(usermod_badge23 INTERFACE
${CMAKE_CURRENT_LIST_DIR}/mp_sys_kernel.c
${CMAKE_CURRENT_LIST_DIR}/mp_uctx.c
${CMAKE_CURRENT_LIST_DIR}/mp_media.c
${CMAKE_CURRENT_LIST_DIR}/mp_sys_mode.c
)
target_include_directories(usermod_badge23 INTERFACE
......
// probably doesn't need all of these idk
#include <stdio.h>
#include <string.h>
#include "extmod/virtpin.h"
#include "machine_rtc.h"
#include "modmachine.h"
#include "mphalport.h"
#include "py/builtin.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "flow3r_bsp.h"
#include "st3m_mode.h"
STATIC mp_obj_t mp_mode_set(mp_obj_t kind) {
// this does not support message at the time
st3m_mode_set(mp_obj_get_int(kind), NULL);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_mode_set_obj, mp_mode_set);
STATIC const mp_rom_map_elem_t mp_module_sys_mode_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_mode) },
{ MP_ROM_QSTR(MP_QSTR_mode_set), MP_ROM_PTR(&mp_mode_set_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_sys_mode_globals,
mp_module_sys_mode_globals_table);
const mp_obj_module_t mp_module_sys_mode = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_sys_mode_globals,
};
MP_REGISTER_MODULE(MP_QSTR_sys_mode, mp_module_sys_mode);
......@@ -158,6 +158,7 @@ soft_reset:
}
esp_log_set_vprintf(vprintf_log);
} else {
st3m_mode_set(st3m_mode_kind_repl, NULL);
if ((ret = pyexec_friendly_repl() != 0)) {
_diskmode_maybe(pyexec_system_exit);
break;
......
def mode_set(kind: int) -> None:
"""
Sets the mode of the badge, which handles what is displayed on screen and what behavior
is used for pressing the OS shoulder button.
Very low level, should not be used if you don't know what you're doing.
kind values can be viewed on components/st3m/st3m_mode.h
Need to switch to flash or SD mode? Use machine.disk_mode_flash/disk_mode_sd instead.
"""
...
......@@ -20,7 +20,7 @@ from st3m.application import (
from st3m.about import About
from st3m import settings_menu as settings, logging, processors, wifi
import captouch, audio, leds, gc, sys_buttons, sys_display
import captouch, audio, leds, gc, sys_buttons, sys_display, sys_mode
import os
import machine
......@@ -116,15 +116,16 @@ def _make_compositor(reactor: Reactor, vm: ViewManager) -> overlays.Compositor:
return compositor
def run_view(v: View) -> None:
def run_view(v: View, debug_vm=True) -> None:
"""
Run a given View in the foreground, with an empty ViewManager underneath.
This is useful for debugging simple applications from the REPL.
"""
reactor = _make_reactor()
vm = ViewManager(ViewTransitionBlend())
vm = ViewManager(ViewTransitionBlend(), debug=debug_vm)
vm.push(v)
sys_mode.mode_set(2) # st3m_mode_kind_app
compositor = _make_compositor(reactor, vm)
top = processors.ProcessorMidldeware(compositor)
reactor.set_top(top)
......@@ -132,7 +133,7 @@ def run_view(v: View) -> None:
def run_app(klass):
run_view(klass(ApplicationContext()))
run_view(klass(ApplicationContext()), debug_vm=True)
def _yeet_local_changes() -> None:
......@@ -192,8 +193,8 @@ def run_main() -> None:
raise Exception(f"More than one bundle named {override_main_app}")
if len(requested) == 0:
raise Exception(f"Requested bundle {override_main_app} not found")
run_view(requested[0].load())
run_view(menu_main)
run_view(requested[0].load(), debug_vm=True)
run_view(menu_main, debug_vm=False)
__all__ = [
......
......@@ -2,6 +2,8 @@ from st3m.reactor import Responder
from st3m.goose import ABCBase, abstractmethod, Optional, List
from st3m.input import InputState, InputController
from ctx import Context
import machine
import utime
class View(Responder):
......@@ -145,13 +147,15 @@ class ViewManager(Responder):
popped.
"""
def __init__(self, vt: ViewTransition) -> None:
def __init__(self, vt: ViewTransition, debug: bool) -> None:
"""
Create a new ViewManager with a default ViewTransition.
"""
self._incoming: Optional[View] = None
self._outgoing: Optional[View] = None
self._debug = debug
# Transition time.
self._time_ms = 150
......@@ -167,6 +171,10 @@ class ViewManager(Responder):
self._input.think(ins, delta_ms)
if self._input.buttons.os.middle.pressed:
if not self._history and self._debug:
utime.sleep(0.5)
machine.reset()
else:
self.pop(ViewTransitionSwipeRight())
if self._transitioning:
......
def mode_set(kind: int) -> None:
return None
import time
def sleep(i: int):
time.sleep(i)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment