|
34 | 34 | #include "shared-bindings/supervisor/Runtime.h"
|
35 | 35 |
|
36 | 36 | #include "supervisor/shared/reload.h"
|
| 37 | +#include "supervisor/shared/stack.h" |
| 38 | +#include "supervisor/shared/status_leds.h" |
| 39 | +#include "supervisor/shared/bluetooth/bluetooth.h" |
37 | 40 |
|
38 | 41 | #if (CIRCUITPY_USB)
|
39 | 42 | #include "tusb.h"
|
@@ -134,12 +137,91 @@ MP_PROPERTY_GETSET(supervisor_runtime_autoreload_obj,
|
134 | 137 | (mp_obj_t)&supervisor_runtime_get_autoreload_obj,
|
135 | 138 | (mp_obj_t)&supervisor_runtime_set_autoreload_obj);
|
136 | 139 |
|
| 140 | +//| ble_workflow: bool |
| 141 | +//| """Enable/Disable ble workflow until a reset. This prevents BLE advertising outside of the VM and |
| 142 | +//| the services used for it.""" |
| 143 | +//| |
| 144 | +STATIC mp_obj_t supervisor_runtime_get_ble_workflow(mp_obj_t self) { |
| 145 | + #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_SERIAL_BLE |
| 146 | + return mp_obj_new_bool(supervisor_bluetooth_workflow_is_enabled()); |
| 147 | + #else |
| 148 | + return mp_const_false; |
| 149 | + #endif |
| 150 | +} |
| 151 | +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_ble_workflow_obj, supervisor_runtime_get_ble_workflow); |
| 152 | + |
| 153 | +STATIC mp_obj_t supervisor_runtime_set_ble_workflow(mp_obj_t self, mp_obj_t state_in) { |
| 154 | + #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_SERIAL_BLE |
| 155 | + if (mp_obj_is_true(state_in)) { |
| 156 | + supervisor_bluetooth_enable_workflow(); |
| 157 | + } else { |
| 158 | + supervisor_bluetooth_disable_workflow(); |
| 159 | + } |
| 160 | + #else |
| 161 | + mp_raise_NotImplementedError(NULL); |
| 162 | + #endif |
| 163 | + return mp_const_none; |
| 164 | +} |
| 165 | +MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_ble_workflow_obj, supervisor_runtime_set_ble_workflow); |
| 166 | + |
| 167 | +MP_PROPERTY_GETSET(supervisor_runtime_ble_workflow_obj, |
| 168 | + (mp_obj_t)&supervisor_runtime_get_ble_workflow_obj, |
| 169 | + (mp_obj_t)&supervisor_runtime_set_ble_workflow_obj); |
| 170 | + |
| 171 | +//| next_stack_limit: int |
| 172 | +//| """The size of the stack for the next vm run. If its too large, the default will be used.""" |
| 173 | +//| |
| 174 | +STATIC mp_obj_t supervisor_runtime_get_next_stack_limit(mp_obj_t self) { |
| 175 | + return mp_obj_new_int(get_next_stack_size()); |
| 176 | +} |
| 177 | +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_next_stack_limit_obj, supervisor_runtime_get_next_stack_limit); |
| 178 | + |
| 179 | +STATIC mp_obj_t supervisor_runtime_set_next_stack_limit(mp_obj_t self, mp_obj_t size_obj) { |
| 180 | + mp_int_t size = mp_obj_get_int(size_obj); |
| 181 | + mp_arg_validate_int_min(size, 256, MP_QSTR_size); |
| 182 | + set_next_stack_size(size); |
| 183 | + return mp_const_none; |
| 184 | +} |
| 185 | +MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_next_stack_limit_obj, supervisor_runtime_set_next_stack_limit); |
| 186 | + |
| 187 | +MP_PROPERTY_GETSET(supervisor_runtime_next_stack_limit_obj, |
| 188 | + (mp_obj_t)&supervisor_runtime_get_next_stack_limit_obj, |
| 189 | + (mp_obj_t)&supervisor_runtime_set_next_stack_limit_obj); |
| 190 | + |
| 191 | +//| rgb_status_brightness: int |
| 192 | +//| """Set brightness of status RGB LED from 0-255. This will take effect |
| 193 | +//| after the current code finishes and the status LED is used to show |
| 194 | +//| the finish state.""" |
| 195 | +//| |
| 196 | +STATIC mp_obj_t supervisor_runtime_get_rgb_status_brightness(mp_obj_t self) { |
| 197 | + return MP_OBJ_NEW_SMALL_INT(get_status_brightness()); |
| 198 | +} |
| 199 | +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_rgb_status_brightness_obj, supervisor_runtime_get_rgb_status_brightness); |
| 200 | + |
| 201 | +STATIC mp_obj_t supervisor_runtime_set_rgb_status_brightness(mp_obj_t self, mp_obj_t lvl) { |
| 202 | + #if CIRCUITPY_STATUS_LED |
| 203 | + // This must be int. If cast to uint8_t first, will never raise a ValueError. |
| 204 | + set_status_brightness((uint8_t)mp_arg_validate_int_range(mp_obj_get_int(lvl), 0, 255, MP_QSTR_brightness)); |
| 205 | + #else |
| 206 | + mp_raise_NotImplementedError(NULL); |
| 207 | + #endif |
| 208 | + return mp_const_none; |
| 209 | +} |
| 210 | +MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_rgb_status_brightness_obj, supervisor_runtime_set_rgb_status_brightness); |
| 211 | + |
| 212 | +MP_PROPERTY_GETSET(supervisor_runtime_rgb_status_brightness_obj, |
| 213 | + (mp_obj_t)&supervisor_runtime_get_rgb_status_brightness_obj, |
| 214 | + (mp_obj_t)&supervisor_runtime_set_rgb_status_brightness_obj); |
| 215 | + |
137 | 216 | STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = {
|
138 | 217 | { MP_ROM_QSTR(MP_QSTR_usb_connected), MP_ROM_PTR(&supervisor_runtime_usb_connected_obj) },
|
139 | 218 | { MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_runtime_serial_connected_obj) },
|
140 | 219 | { MP_ROM_QSTR(MP_QSTR_serial_bytes_available), MP_ROM_PTR(&supervisor_runtime_serial_bytes_available_obj) },
|
141 | 220 | { MP_ROM_QSTR(MP_QSTR_run_reason), MP_ROM_PTR(&supervisor_runtime_run_reason_obj) },
|
142 | 221 | { MP_ROM_QSTR(MP_QSTR_autoreload), MP_ROM_PTR(&supervisor_runtime_autoreload_obj) },
|
| 222 | + { MP_ROM_QSTR(MP_QSTR_ble_workflow), MP_ROM_PTR(&supervisor_runtime_ble_workflow_obj) }, |
| 223 | + { MP_ROM_QSTR(MP_QSTR_next_stack_limit), MP_ROM_PTR(&supervisor_runtime_next_stack_limit_obj) }, |
| 224 | + { MP_ROM_QSTR(MP_QSTR_rgb_status_brightness), MP_ROM_PTR(&supervisor_runtime_rgb_status_brightness_obj) }, |
143 | 225 | };
|
144 | 226 |
|
145 | 227 | STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table);
|
|
0 commit comments