38
38
//| import gnss
39
39
//| import time
40
40
//|
41
- //| gps = gnss.GNSS()
42
- //| gps.select(gnss.SatelliteSystem.GPS)
43
- //| gps.start()
41
+ //| nav = gnss.GNSS([gnss.SatelliteSystem.GPS, gnss.SatelliteSystem.GLONASS])
44
42
//| last_print = time.monotonic()
45
43
//| while True:
46
- //| gps .update()
44
+ //| nav .update()
47
45
//| current = time.monotonic()
48
46
//| if current - last_print >= 1.0:
49
47
//| last_print = current
50
- //| if gps .fix is gnss.PositionFix.INVALID:
48
+ //| if nav .fix is gnss.PositionFix.INVALID:
51
49
//| print("Waiting for fix...")
52
50
//| continue
53
- //| print("Latitude: {0:.6f} degrees".format(gps .latitude))
54
- //| print("Longitude: {0:.6f} degrees".format(gps .longitude))"""
51
+ //| print("Latitude: {0:.6f} degrees".format(nav .latitude))
52
+ //| print("Longitude: {0:.6f} degrees".format(nav .longitude))"""
55
53
//|
56
54
57
55
//| def __init__(self, ):
58
- //| """Turn on the GNSS."""
56
+ //| """Turn on the GNSS.
57
+ //|
58
+ //| :param gnss.SatelliteSystem system: satellite system to use"""
59
59
//| ...
60
60
//|
61
61
STATIC mp_obj_t gnss_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
62
62
gnss_obj_t * self = m_new_obj (gnss_obj_t );
63
63
self -> base .type = & gnss_type ;
64
+ enum { ARG_system };
65
+ static const mp_arg_t allowed_args [] = {
66
+ { MP_QSTR_system , MP_ARG_REQUIRED | MP_ARG_OBJ },
67
+ };
68
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
69
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
70
+
71
+ unsigned long selection = 0 ;
72
+ if (MP_OBJ_IS_TYPE (args [ARG_system ].u_obj , & gnss_satellitesystem_type )) {
73
+ selection |= gnss_satellitesystem_obj_to_type (args [ARG_system ].u_obj );
74
+ } else if (MP_OBJ_IS_TYPE (args [ARG_system ].u_obj , & mp_type_list )) {
75
+ size_t systems_size = 0 ;
76
+ mp_obj_t * systems ;
77
+ mp_obj_list_get (args [ARG_system ].u_obj , & systems_size , & systems );
78
+ for (size_t i = 0 ; i < systems_size ; ++ i ) {
79
+ if (!MP_OBJ_IS_TYPE (systems [i ], & gnss_satellitesystem_type )) {
80
+ mp_raise_TypeError (translate ("System entry must be gnss.SatelliteSystem" ));
81
+ }
82
+ selection |= gnss_satellitesystem_obj_to_type (systems [i ]);
83
+ }
84
+ } else {
85
+ mp_raise_TypeError (translate ("System entry must be gnss.SatelliteSystem" ));
86
+ }
64
87
65
- common_hal_gnss_construct (self );
88
+ common_hal_gnss_construct (self , selection );
66
89
return MP_OBJ_FROM_PTR (self );
67
90
}
68
91
@@ -83,64 +106,6 @@ STATIC void check_for_deinit(gnss_obj_t *self) {
83
106
}
84
107
}
85
108
86
- //| def select(self, system: gnss.SatelliteSystem) -> Any:
87
- //| """Add specified satellite system to selection for positioning.
88
- //|
89
- //| :param gnss.SatelliteSystem system: satellite system to use"""
90
- //| ...
91
- //|
92
- STATIC mp_obj_t gnss_obj_select (mp_obj_t self_in , mp_obj_t system_obj ) {
93
- gnss_obj_t * self = MP_OBJ_TO_PTR (self_in );
94
- check_for_deinit (self );
95
-
96
- gnss_satellitesystem_t system = gnss_satellitesystem_obj_to_type (system_obj );
97
- common_hal_gnss_select (self , system );
98
- return mp_const_none ;
99
- }
100
- STATIC MP_DEFINE_CONST_FUN_OBJ_2 (gnss_select_obj , gnss_obj_select );
101
-
102
- //| def deselect(self, system: gnss.SatelliteSystem) -> Any:
103
- //| """Remove specified satellite system from selection for positioning.
104
- //|
105
- //| :param gnss.SatelliteSystem system: satellite system to remove"""
106
- //| ...
107
- //|
108
- STATIC mp_obj_t gnss_obj_deselect (mp_obj_t self_in , mp_obj_t system_obj ) {
109
- gnss_obj_t * self = MP_OBJ_TO_PTR (self_in );
110
- check_for_deinit (self );
111
-
112
- gnss_satellitesystem_t system = gnss_satellitesystem_obj_to_type (system_obj );
113
- common_hal_gnss_deselect (self , system );
114
- return mp_const_none ;
115
- }
116
- STATIC MP_DEFINE_CONST_FUN_OBJ_2 (gnss_deselect_obj , gnss_obj_deselect );
117
-
118
- //| def start(self, ) -> Any:
119
- //| """Start positioning."""
120
- //| ...
121
- //|
122
- STATIC mp_obj_t gnss_obj_start (mp_obj_t self_in ) {
123
- gnss_obj_t * self = MP_OBJ_TO_PTR (self_in );
124
- check_for_deinit (self );
125
-
126
- common_hal_gnss_start (self );
127
- return mp_const_none ;
128
- }
129
- MP_DEFINE_CONST_FUN_OBJ_1 (gnss_start_obj , gnss_obj_start );
130
-
131
- //| def stop(self, ) -> Any:
132
- //| """Stop positioning."""
133
- //| ...
134
- //|
135
- STATIC mp_obj_t gnss_obj_stop (mp_obj_t self_in ) {
136
- gnss_obj_t * self = MP_OBJ_TO_PTR (self_in );
137
- check_for_deinit (self );
138
-
139
- common_hal_gnss_stop (self );
140
- return mp_const_none ;
141
- }
142
- MP_DEFINE_CONST_FUN_OBJ_1 (gnss_stop_obj , gnss_obj_stop );
143
-
144
109
//| def update(self, ) -> Any:
145
110
//| """Update GNSS positioning information."""
146
111
//| ...
@@ -189,7 +154,7 @@ const mp_obj_property_t gnss_longitude_obj = {
189
154
};
190
155
191
156
//| altitude: Any = ...
192
- //| """Altitude of current position in degrees (float)."""
157
+ //| """Altitude of current position in meters (float)."""
193
158
//|
194
159
STATIC mp_obj_t gnss_obj_get_altitude (mp_obj_t self_in ) {
195
160
gnss_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -224,10 +189,6 @@ const mp_obj_property_t gnss_fix_obj = {
224
189
225
190
STATIC const mp_rom_map_elem_t gnss_locals_dict_table [] = {
226
191
{ MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& gnss_deinit_obj ) },
227
- { MP_ROM_QSTR (MP_QSTR_select ), MP_ROM_PTR (& gnss_select_obj ) },
228
- { MP_ROM_QSTR (MP_QSTR_deselect ), MP_ROM_PTR (& gnss_deselect_obj ) },
229
- { MP_ROM_QSTR (MP_QSTR_start ), MP_ROM_PTR (& gnss_start_obj ) },
230
- { MP_ROM_QSTR (MP_QSTR_stop ), MP_ROM_PTR (& gnss_stop_obj ) },
231
192
{ MP_ROM_QSTR (MP_QSTR_update ), MP_ROM_PTR (& gnss_update_obj ) },
232
193
233
194
{ MP_ROM_QSTR (MP_QSTR_latitude ), MP_ROM_PTR (& gnss_latitude_obj ) },
0 commit comments