8
8
#include <string.h>
9
9
10
10
#include <pbdrv/bluetooth.h>
11
+ #include <pbdrv/reset.h>
12
+ #include <pbsys/program_stop.h>
13
+ #include <pbsys/status.h>
11
14
#include <pbsys/storage.h>
12
15
13
16
#include "py/obj.h"
14
17
#include "py/objstr.h"
15
18
#include "py/runtime.h"
16
19
17
20
#include <pybricks/common.h>
21
+ #include <pybricks/parameters.h>
18
22
#include <pybricks/util_pb/pb_error.h>
19
23
#include <pybricks/util_mp/pb_kwarg_helper.h>
20
24
#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);
27
31
28
32
#if PBDRV_CONFIG_RESET
29
33
30
- #include <pbdrv/reset.h>
31
-
32
34
static mp_obj_t pb_type_System_reset_reason (void ) {
33
35
pbdrv_reset_reason_t reason = pbdrv_reset_get_reason ();
34
36
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
37
39
38
40
#endif // PBDRV_CONFIG_RESET
39
41
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 ();
41
44
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
+ }
44
58
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
46
64
47
65
static mp_obj_t pb_type_System_set_stop_button (mp_obj_t buttons_in ) {
48
66
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_
127
145
// dir(pybricks.common.System)
128
146
static const mp_rom_map_elem_t common_System_locals_dict_table [] = {
129
147
{ 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 ) },
130
149
#if PBDRV_CONFIG_RESET
131
150
{ MP_ROM_QSTR (MP_QSTR_reset_reason ), MP_ROM_PTR (& pb_type_System_reset_reason_obj ) },
132
151
#endif // PBDRV_CONFIG_RESET
0 commit comments