88#include <string.h>
99
1010#include <pbdrv/bluetooth.h>
11+ #include <pbdrv/reset.h>
12+ #include <pbsys/program_stop.h>
13+ #include <pbsys/status.h>
1114#include <pbsys/storage.h>
1215
1316#include "py/obj.h"
1417#include "py/objstr.h"
1518#include "py/runtime.h"
1619
1720#include <pybricks/common.h>
21+ #include <pybricks/parameters.h>
1822#include <pybricks/util_pb/pb_error.h>
1923#include <pybricks/util_mp/pb_kwarg_helper.h>
2024#include <pybricks/util_mp/pb_obj_helper.h>
@@ -27,8 +31,6 @@ static MP_DEFINE_CONST_FUN_OBJ_0(pb_type_System_name_obj, pb_type_System_name);
2731
2832#if PBDRV_CONFIG_RESET
2933
30- #include <pbdrv/reset.h>
31-
3234static mp_obj_t pb_type_System_reset_reason (void ) {
3335 pbdrv_reset_reason_t reason = pbdrv_reset_get_reason ();
3436 return MP_OBJ_NEW_SMALL_INT (reason );
@@ -37,12 +39,28 @@ static MP_DEFINE_CONST_FUN_OBJ_0(pb_type_System_reset_reason_obj, pb_type_System
3739
3840#endif // PBDRV_CONFIG_RESET
3941
40- #if PBIO_CONFIG_ENABLE_SYS
42+ static mp_obj_t pb_type_System_info (void ) {
43+ const char * hub_name = pbdrv_bluetooth_get_hub_name ();
4144
42- #include <pbsys/status.h>
43- #include <pbsys/program_stop.h>
45+ mp_map_elem_t info [] = {
46+ {MP_OBJ_NEW_QSTR (MP_QSTR_name ), mp_obj_new_str (hub_name , strlen (hub_name ))},
47+ #if PBDRV_CONFIG_RESET
48+ {MP_OBJ_NEW_QSTR (MP_QSTR_reset_reason ), mp_obj_new_int (pbdrv_reset_get_reason ())},
49+ #endif // PBDRV_CONFIG_RESET
50+ {MP_OBJ_NEW_QSTR (MP_QSTR_host_connected_ble ), mp_obj_new_bool (pbsys_status_test (PBIO_PYBRICKS_STATUS_BLE_HOST_CONNECTED ))},
51+ };
52+ mp_obj_t info_dict = mp_obj_new_dict (MP_ARRAY_SIZE (info ));
53+
54+ for (size_t i = 0 ; i < MP_ARRAY_SIZE (info ); i ++ ) {
55+ mp_map_elem_t * elem = & info [i ];
56+ mp_obj_dict_store (info_dict , elem -> key , elem -> value );
57+ }
4458
45- #include <pybricks/parameters.h>
59+ return info_dict ;
60+ }
61+ static MP_DEFINE_CONST_FUN_OBJ_0 (pb_type_System_info_obj , pb_type_System_info ) ;
62+
63+ #if PBIO_CONFIG_ENABLE_SYS
4664
4765static mp_obj_t pb_type_System_set_stop_button (mp_obj_t buttons_in ) {
4866 pbio_button_flags_t buttons = 0 ;
@@ -127,6 +145,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(pb_type_System_storage_obj, 0, pb_type_System_
127145// dir(pybricks.common.System)
128146static const mp_rom_map_elem_t common_System_locals_dict_table [] = {
129147 { MP_ROM_QSTR (MP_QSTR_name ), MP_ROM_PTR (& pb_type_System_name_obj ) },
148+ { MP_ROM_QSTR (MP_QSTR_info ), MP_ROM_PTR (& pb_type_System_info_obj ) },
130149 #if PBDRV_CONFIG_RESET
131150 { MP_ROM_QSTR (MP_QSTR_reset_reason ), MP_ROM_PTR (& pb_type_System_reset_reason_obj ) },
132151 #endif // PBDRV_CONFIG_RESET
0 commit comments