How to configure iot_button_get_repeat() to only return total presses

markirwin
Posts: 10
Joined: Sun Nov 22, 2020 10:42 am

How to configure iot_button_get_repeat() to only return total presses

Postby markirwin » Fri Sep 17, 2021 1:46 am

Hi,

I am using the button_iot library and having an issue where the iot_button_get_repeat() function is working fine but it called the callback after every press, so if i press four times i get callbacks after 2, 3 and 4. I would prefer for it to only return the total number of presses? Is that possible? I want to select a file based on the number of presses.

Code below:
static void button_audio_play_repeat_cb(void *arg)
{

audio_btn_pressed_times = iot_button_get_repeat(g_btns[4]);
ESP_LOGI(TAG, "Audio Play Button pressed: %d times", audio_btn_pressed_times);
if (strcmp(localfiles[audio_btn_pressed_times], "") != 0) {audio_play(localfiles[audio_btn_pressed_times]);}

}

Any suggestions are welcome.

Best

Mark

markirwin
Posts: 10
Joined: Sun Nov 22, 2020 10:42 am

Re: How to configure iot_button_get_repeat() to only return total presses

Postby markirwin » Fri Sep 17, 2021 5:58 am

I changed the state machine in iot_button.c to only call repeat after specific times.

case 2:
if (btn->button_level == btn->active_level) {
btn->event = (uint8_t)BUTTON_PRESS_DOWN;
CALL_EVENT_CB(BUTTON_PRESS_DOWN);
btn->repeat++;
//CALL_EVENT_CB(BUTTON_PRESS_REPEAT); // repeat hit
btn->ticks = 0;
btn->state = 3;
} else if (btn->ticks > SHORT_TICKS) {
if (btn->repeat == 1) {
btn->event = (uint8_t)BUTTON_SINGLE_CLICK;
CALL_EVENT_CB(BUTTON_SINGLE_CLICK);
} else if (btn->repeat == 2) {
btn->event = (uint8_t)BUTTON_PRESS_REPEAT;
CALL_EVENT_CB(BUTTON_DOUBLE_CLICK); // repeat hit
} else if (btn->repeat == 3) {
btn->event = (uint8_t)BUTTON_PRESS_REPEAT;
CALL_EVENT_CB(BUTTON_PRESS_REPEAT); // repeat hit
} else if (btn->repeat == 4) {
btn->event = (uint8_t)BUTTON_PRESS_REPEAT;
CALL_EVENT_CB(BUTTON_PRESS_REPEAT); // repeat hit
} else if (btn->repeat == 5) {
btn->event = (uint8_t)BUTTON_PRESS_REPEAT;
CALL_EVENT_CB(BUTTON_PRESS_REPEAT); // repeat hit
}
btn->state = 0;
}
break;

Who is online

Users browsing this forum: No registered users and 33 guests