Skip to content

Commit bdf20a8

Browse files
committed
pybricks.common.ble: use const modifier on observed_data_t
Add some const-correctness to observed_data_t in a few places.
1 parent 462c1a6 commit bdf20a8

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

pybricks/common/pb_type_ble.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pb_module_ble_broadcast_obj, 1, pb_module_ble_
309309
* @returns The decoded value as a Python object.
310310
* @throws RuntimeError If the data was invalid and could not be decoded.
311311
*/
312-
STATIC mp_obj_t pb_module_ble_decode(observed_data_t *data, size_t *index) {
312+
STATIC mp_obj_t pb_module_ble_decode(const observed_data_t *data, size_t *index) {
313313
uint8_t size = data->data[*index] & 0x1F;
314314
pb_ble_broadcast_data_type_t data_type = data->data[*index] >> 5;
315315

@@ -389,7 +389,7 @@ STATIC mp_obj_t pb_module_ble_decode(observed_data_t *data, size_t *index) {
389389
* @throws ValueError If the channel is out of range.
390390
* @throws RuntimeError If the last received data was invalid.
391391
*/
392-
STATIC observed_data_t *pb_module_ble_get_channel_data(mp_obj_t channel_in) {
392+
STATIC const observed_data_t *pb_module_ble_get_channel_data(mp_obj_t channel_in) {
393393
mp_int_t channel = mp_obj_get_int(channel_in);
394394

395395
observed_data_t *ch_data = lookup_observed_data(channel);
@@ -425,7 +425,7 @@ STATIC mp_obj_t pb_module_ble_observe(mp_obj_t self_in, mp_obj_t channel_in) {
425425
// during any MicroPython function call that allocates memory. So, we have
426426
// to make a copy of it since we are potentially allocating multiple times
427427
// in a loop below.
428-
observed_data_t ch_data = *pb_module_ble_get_channel_data(channel_in);
428+
const observed_data_t ch_data = *pb_module_ble_get_channel_data(channel_in);
429429

430430
// Have not received data yet or timed out.
431431
if (ch_data.rssi == INT8_MIN) {
@@ -465,7 +465,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pb_module_ble_observe_obj, pb_module_ble_observ
465465
* @throws ValueError If the channel is out of range.
466466
*/
467467
STATIC mp_obj_t pb_module_ble_signal_strength(mp_obj_t self_in, mp_obj_t channel_in) {
468-
observed_data_t *ch_data = pb_module_ble_get_channel_data(channel_in);
468+
const observed_data_t *ch_data = pb_module_ble_get_channel_data(channel_in);
469469
return mp_obj_new_int(ch_data->rssi);
470470
}
471471
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pb_module_ble_signal_strength_obj, pb_module_ble_signal_strength);

0 commit comments

Comments
 (0)