Skip to content

Commit

Permalink
pybricks.common.System: Implement reset_storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Dec 5, 2024
1 parent fc37994 commit a062942
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
### Added

- Added optional `calibrated=True` parameter to `acceleration()` and `up()` and
`angular_velocity()` methods of the IMU ([support#943]).
`angular_velocity()` and `rotation` methods of the IMU ([support#943]).
- Implemented `hub.imu.orientation()` to give the rotation matrix of the hub or
robot with respect to the inertial frame.
- Added calibration parameters that can be set for angular velocity offset and
scale and acceleration offset and scale.
- Added `hub.system.reset_storage` to restore storage and settings to default
state.

### Changed

Expand Down
5 changes: 4 additions & 1 deletion lib/pbio/sys/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ void pbsys_storage_request_write(void) {

/**
* Erases user data, erases user program meta data and restores user settings
* to default.
* to default. Does not actually erase program data, but it becomes
* inaccessible, thus effectively erased.
*
* This resets the data in RAM, which will be saved during power off just as
* with any other storage operations.
Expand All @@ -188,6 +189,8 @@ void pbsys_storage_request_write(void) {
void pbsys_storage_reset_storage(void) {
// Reset storage except for program data. It is sufficient to set its
// size to 0, which is what happens here since it is in the map.
// The program data itself is not overwritten with zeros because the user
// may be calling this while a program using this data is running.
memset(map, 0, sizeof(pbsys_storage_data_map_t));

// Apply default settings.
Expand Down
7 changes: 7 additions & 0 deletions pybricks/common/pb_type_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ static mp_obj_t pb_type_System_storage(size_t n_args, const mp_obj_t *pos_args,
}
static MP_DEFINE_CONST_FUN_OBJ_KW(pb_type_System_storage_obj, 0, pb_type_System_storage);

static mp_obj_t pb_type_System_reset_storage(void) {
pbsys_storage_reset_storage();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(pb_type_System_reset_storage_obj, pb_type_System_reset_storage);

#endif // PBIO_CONFIG_ENABLE_SYS

// dir(pybricks.common.System)
Expand All @@ -153,6 +159,7 @@ static const mp_rom_map_elem_t common_System_locals_dict_table[] = {
#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) },
{ MP_ROM_QSTR(MP_QSTR_reset_storage), MP_ROM_PTR(&pb_type_System_reset_storage_obj) },
{ MP_ROM_QSTR(MP_QSTR_shutdown), MP_ROM_PTR(&pb_type_System_shutdown_obj) },
{ MP_ROM_QSTR(MP_QSTR_storage), MP_ROM_PTR(&pb_type_System_storage_obj) },
#endif
Expand Down

0 comments on commit a062942

Please sign in to comment.