Skip to content

Commit

Permalink
pybricks.common.System: Shutdown placeholder.
Browse files Browse the repository at this point in the history
Reset will not be part of the end-user API. We will only keep it for backwards-compatibility for system updates.

There will be a graceful shutdown instead. This adds the placeholder and moves the corresponding TODO note.

pybricks/support#379
  • Loading branch information
laurensvalk committed Jul 5, 2021
1 parent 491fc1c commit cbf1194
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pybricks/common/pb_type_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pb_type_System_name_obj, pb_type_System_name);

#if PBDRV_CONFIG_RESET

// REVISIT: there should be a pbio_reset() instead of pbdrv_reset() to gracefully
// shut down the hub (e.g. if the power button is pressed or USB is plugged in,
// some hubs will not actually shut down).

#include <pbdrv/reset.h>

STATIC mp_obj_t pb_type_System_reset(mp_obj_t action_in) {
Expand All @@ -48,6 +44,17 @@ STATIC mp_obj_t pb_type_System_reset_reason(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pb_type_System_reset_reason_obj, pb_type_System_reset_reason);

STATIC mp_obj_t pb_type_System_shutdown(void) {

// TODO: there should be a pbio function instead of pbdrv function to gracefully
// shut down the hub (e.g. if the power button is pressed or USB is plugged in,
// some hubs will not actually power off).

mp_raise_NotImplementedError(NULL);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pb_type_System_shutdown_obj, pb_type_System_shutdown);

#endif // PBDRV_CONFIG_RESET

#if PBIO_CONFIG_ENABLE_SYS
Expand Down Expand Up @@ -97,6 +104,7 @@ STATIC const mp_rom_map_elem_t common_System_locals_dict_table[] = {
#if PBDRV_CONFIG_RESET
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&pb_type_System_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_reason), MP_ROM_PTR(&pb_type_System_reset_reason_obj) },
{ MP_ROM_QSTR(MP_QSTR_shutdown), MP_ROM_PTR(&pb_type_System_shutdown_obj) },

This comment has been minimized.

Copy link
@dlech

dlech Jul 5, 2021

Member

This should depend on PBIO_CONFIG_ENABLE_SYS rather than PBDRV_CONFIG_RESET.

#endif // PBDRV_CONFIG_RESET
#if PBIO_CONFIG_ENABLE_SYS
{ MP_ROM_QSTR(MP_QSTR_set_stop_button), MP_ROM_PTR(&pb_type_System_set_stop_button_obj) },
Expand Down

0 comments on commit cbf1194

Please sign in to comment.