Skip to content

Commit 0bf0e2b

Browse files
committed
this works more stable..
1 parent 4370b22 commit 0bf0e2b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

esp32/modbadge.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(badge_nvs_set_u16_obj, badge_nvs_set_u16_);
215215

216216
// Mpr121 (badge_mpr121.h)
217217
#ifdef I2C_MPR121_ADDR
218+
#define store_dict_int(dict, field, contents) mp_obj_dict_store(dict, mp_obj_new_str(field, strlen(field), false), mp_obj_new_int(contents));
218219
STATIC mp_obj_t badge_mpr121_get_touch_info_(void) {
219220
struct badge_mpr121_touch_info info;
220221
esp_err_t err = badge_mpr121_get_touch_info(&info);
@@ -225,11 +226,14 @@ STATIC mp_obj_t badge_mpr121_get_touch_info_(void) {
225226
mp_obj_t list_items[8];
226227
int i;
227228
for (i=0; i<8; i++) {
228-
list_items[i] = mp_obj_new_dict(4);
229-
mp_obj_dict_store(list_items[i], MP_OBJ_NEW_QSTR(MP_QSTR_data), mp_obj_new_int(info.data[i]));
230-
mp_obj_dict_store(list_items[i], MP_OBJ_NEW_QSTR(MP_QSTR_baseline), mp_obj_new_int(info.baseline[i]));
231-
mp_obj_dict_store(list_items[i], MP_OBJ_NEW_QSTR(MP_QSTR_touch), mp_obj_new_int(info.touch[i]));
232-
mp_obj_dict_store(list_items[i], MP_OBJ_NEW_QSTR(MP_QSTR_release), mp_obj_new_int(info.release[i]));
229+
list_items[i] = mp_obj_new_dict(0);
230+
231+
mp_obj_dict_t *dict = MP_OBJ_TO_PTR(list_items[i]);
232+
233+
store_dict_int(dict, "data", info.data[i]);
234+
store_dict_int(dict, "baseline", info.baseline[i]);
235+
store_dict_int(dict, "touch", info.touch[i]);
236+
store_dict_int(dict, "release", info.release[i]);
233237
}
234238
mp_obj_t list = mp_obj_new_list(8, list_items);
235239
return list;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy