Skip to content

Commit 4d06b9b

Browse files
committed
autoconfig for modtouchpad
1 parent fc930ce commit 4d06b9b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

esp32/modtouchpad.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ STATIC mp_obj_t touchpad_config(mp_obj_t num_obj, mp_obj_t threshold_obj) {
7272
}
7373
STATIC MP_DEFINE_CONST_FUN_OBJ_2(touchpad_config_obj, touchpad_config);
7474

75+
STATIC mp_obj_t touchpad_autoconfig(mp_obj_t num_obj) {
76+
touch_pad_t num = mp_obj_get_int(num_obj);
77+
uint16_t threshold = 0;
78+
for (int i=0; i<5; i++) {
79+
uint16_t value = 0;
80+
touch_pad_read(num, &value);
81+
threshold += value * 2 / 3 / 5;
82+
}
83+
esp_err_t err = touch_pad_config(num, threshold);
84+
if (err != ESP_OK) ESP_LOGD("touchpad_config", "%d", err);
85+
return MP_OBJ_NEW_SMALL_INT(threshold);
86+
}
87+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(touchpad_autoconfig_obj, touchpad_autoconfig);
88+
7589
STATIC mp_obj_t touchpad_read(mp_obj_t num_obj) {
7690
touch_pad_t num = mp_obj_get_int(num_obj);
7791
uint16_t value = 0;
@@ -105,6 +119,7 @@ STATIC const mp_rom_map_elem_t touchpad_module_globals_table[] = {
105119
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_touchpad) },
106120
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&touchpad_init_obj) },
107121
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&touchpad_config_obj) },
122+
{ MP_ROM_QSTR(MP_QSTR_autoconfig), MP_ROM_PTR(&touchpad_autoconfig_obj) },
108123
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&touchpad_read_obj) },
109124
{ MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&touchpad_poll_obj) },
110125
{ MP_ROM_QSTR(MP_QSTR_pollall), MP_ROM_PTR(&touchpad_pollall_obj) },

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