Add supervisor.runtime.autoreload
This replaces supervisor.enable_autoreload() and supervisor.disable_autoreload(). It also allows user code to get the current autoreload state. Replaces #5352 and part of #5414
This commit is contained in:
parent
e7d72b1ebe
commit
5e015001c0
@ -33,6 +33,8 @@
|
||||
#include "shared-bindings/supervisor/RunReason.h"
|
||||
#include "shared-bindings/supervisor/Runtime.h"
|
||||
|
||||
#include "supervisor/shared/reload.h"
|
||||
|
||||
#if (CIRCUITPY_USB)
|
||||
#include "tusb.h"
|
||||
#endif
|
||||
@ -105,7 +107,7 @@ void supervisor_set_run_reason(supervisor_run_reason_t run_reason) {
|
||||
}
|
||||
|
||||
//| run_reason: RunReason
|
||||
//| """Returns why CircuitPython started running this particular time."""
|
||||
//| """Why CircuitPython started running this particular time."""
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_runtime_get_run_reason(mp_obj_t self) {
|
||||
return cp_enum_find(&supervisor_run_reason_type, _run_reason);
|
||||
@ -115,11 +117,34 @@ MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_run_reason_obj, supervisor_runt
|
||||
MP_PROPERTY_GETTER(supervisor_runtime_run_reason_obj,
|
||||
(mp_obj_t)&supervisor_runtime_get_run_reason_obj);
|
||||
|
||||
//| autoreload: bool
|
||||
//| """Whether CircuitPython may autoreload based on workflow writes to the filesystem."""
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_runtime_get_autoreload(mp_obj_t self) {
|
||||
return mp_obj_new_bool(autoreload_is_enabled());
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_autoreload_obj, supervisor_runtime_get_autoreload);
|
||||
|
||||
STATIC mp_obj_t supervisor_runtime_set_autoreload(mp_obj_t self, mp_obj_t state_in) {
|
||||
if (mp_obj_is_true(state_in)) {
|
||||
autoreload_enable();
|
||||
} else {
|
||||
autoreload_disable();
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_autoreload_obj, supervisor_runtime_set_autoreload);
|
||||
|
||||
MP_PROPERTY_GETSET(supervisor_runtime_autoreload_obj,
|
||||
(mp_obj_t)&supervisor_runtime_get_autoreload_obj,
|
||||
(mp_obj_t)&supervisor_runtime_set_autoreload_obj);
|
||||
|
||||
STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_usb_connected), MP_ROM_PTR(&supervisor_runtime_usb_connected_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_runtime_serial_connected_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_serial_bytes_available), MP_ROM_PTR(&supervisor_runtime_serial_bytes_available_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_run_reason), MP_ROM_PTR(&supervisor_runtime_run_reason_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_autoreload), MP_ROM_PTR(&supervisor_runtime_autoreload_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table);
|
||||
|
@ -53,27 +53,6 @@
|
||||
//| This object is the sole instance of `supervisor.Runtime`."""
|
||||
//|
|
||||
|
||||
//| def enable_autoreload() -> None:
|
||||
//| """Enable autoreload based on USB file write activity."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_enable_autoreload(void) {
|
||||
autoreload_enable();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(supervisor_enable_autoreload_obj, supervisor_enable_autoreload);
|
||||
|
||||
//| def disable_autoreload() -> None:
|
||||
//| """Disable autoreload based on USB file write activity until
|
||||
//| `enable_autoreload` is called."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_disable_autoreload(void) {
|
||||
autoreload_disable();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(supervisor_disable_autoreload_obj, supervisor_disable_autoreload);
|
||||
|
||||
//| def set_rgb_status_brightness(brightness: int) -> None:
|
||||
//| """Set brightness of status RGB LED from 0-255. This will take effect
|
||||
//| after the current code finishes and the status LED is used to show
|
||||
@ -312,8 +291,6 @@ MP_DEFINE_CONST_FUN_OBJ_2(supervisor_reset_terminal_obj, supervisor_reset_termin
|
||||
|
||||
STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_supervisor) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable_autoreload), MP_ROM_PTR(&supervisor_disable_autoreload_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_rgb_status_brightness), MP_ROM_PTR(&supervisor_set_rgb_status_brightness_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_runtime), MP_ROM_PTR(&common_hal_supervisor_runtime_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_reload), MP_ROM_PTR(&supervisor_reload_obj) },
|
||||
|
Loading…
Reference in New Issue
Block a user