Skip to content

Commit 86cd905

Browse files
committed
Merge branch 'fix/button_long_press_start_up_check' into 'master'
fix(button): fix incorrect long press start and release check See merge request ae_group/esp-iot-solution!1256
2 parents 5c6aa20 + 86aac6c commit 86cd905

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed

components/button/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog
22

3+
## v4.1.2 - 2025-03-24
4+
5+
### Fix:
6+
7+
* fix incorrect long press start and release check.
8+
39
## v4.1.1 - 2025-03-13
410

511
### Improve:

components/button/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "4.1.1"
1+
version: "4.1.2"
22
description: GPIO and ADC and Matrix button driver
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/button
44
repository: https://github.com/espressif/esp-iot-solution.git

components/button/iot_button.c

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
1+
/* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*/
@@ -232,54 +232,54 @@ static void button_handler(button_dev_t *btn)
232232
btn->event = (uint8_t)BUTTON_LONG_PRESS_HOLD;
233233
btn->long_press_hold_cnt++;
234234
CALL_EVENT_CB(BUTTON_LONG_PRESS_HOLD);
235+
}
235236

236-
/** Calling callbacks for BUTTON_LONG_PRESS_START based on press_time */
237-
uint32_t ticks_time = iot_button_get_ticks_time(btn);
238-
if (btn->cb_info[BUTTON_LONG_PRESS_START]) {
239-
button_cb_info_t *cb_info = btn->cb_info[BUTTON_LONG_PRESS_START];
240-
uint16_t time = cb_info[btn->count[0]].event_args.long_press.press_time;
241-
if (btn->long_press_ticks * TICKS_INTERVAL > time) {
242-
for (int i = btn->count[0] + 1; i < btn->size[BUTTON_LONG_PRESS_START]; i++) {
243-
time = cb_info[i].event_args.long_press.press_time;
244-
if (btn->long_press_ticks * TICKS_INTERVAL <= time) {
245-
btn->count[0] = i;
246-
break;
247-
}
237+
/** Calling callbacks for BUTTON_LONG_PRESS_START based on press_time */
238+
uint32_t ticks_time = iot_button_get_ticks_time(btn);
239+
if (btn->cb_info[BUTTON_LONG_PRESS_START]) {
240+
button_cb_info_t *cb_info = btn->cb_info[BUTTON_LONG_PRESS_START];
241+
uint16_t time = cb_info[btn->count[0]].event_args.long_press.press_time;
242+
if (btn->long_press_ticks * TICKS_INTERVAL > time) {
243+
for (int i = btn->count[0] + 1; i < btn->size[BUTTON_LONG_PRESS_START]; i++) {
244+
time = cb_info[i].event_args.long_press.press_time;
245+
if (btn->long_press_ticks * TICKS_INTERVAL <= time) {
246+
btn->count[0] = i;
247+
break;
248248
}
249249
}
250-
if (btn->count[0] < btn->size[BUTTON_LONG_PRESS_START] && abs((int)ticks_time - (int)time) <= TOLERANCE) {
251-
btn->event = (uint8_t)BUTTON_LONG_PRESS_START;
252-
do {
253-
cb_info[btn->count[0]].cb(btn, cb_info[btn->count[0]].usr_data);
254-
btn->count[0]++;
255-
if (btn->count[0] >= btn->size[BUTTON_LONG_PRESS_START]) {
256-
break;
257-
}
258-
} while (time == cb_info[btn->count[0]].event_args.long_press.press_time);
259-
}
260250
}
251+
if (btn->count[0] < btn->size[BUTTON_LONG_PRESS_START] && abs((int)ticks_time - (int)time) <= TOLERANCE) {
252+
btn->event = (uint8_t)BUTTON_LONG_PRESS_START;
253+
do {
254+
cb_info[btn->count[0]].cb(btn, cb_info[btn->count[0]].usr_data);
255+
btn->count[0]++;
256+
if (btn->count[0] >= btn->size[BUTTON_LONG_PRESS_START]) {
257+
break;
258+
}
259+
} while (time == cb_info[btn->count[0]].event_args.long_press.press_time);
260+
}
261+
}
261262

262-
/** Updating counter for BUTTON_LONG_PRESS_UP press_time */
263-
if (btn->cb_info[BUTTON_LONG_PRESS_UP]) {
264-
button_cb_info_t *cb_info = btn->cb_info[BUTTON_LONG_PRESS_UP];
265-
uint16_t time = cb_info[btn->count[1] + 1].event_args.long_press.press_time;
266-
if (btn->long_press_ticks * TICKS_INTERVAL > time) {
267-
for (int i = btn->count[1] + 1; i < btn->size[BUTTON_LONG_PRESS_UP]; i++) {
268-
time = cb_info[i].event_args.long_press.press_time;
269-
if (btn->long_press_ticks * TICKS_INTERVAL <= time) {
270-
btn->count[1] = i;
271-
break;
272-
}
263+
/** Updating counter for BUTTON_LONG_PRESS_UP press_time */
264+
if (btn->cb_info[BUTTON_LONG_PRESS_UP]) {
265+
button_cb_info_t *cb_info = btn->cb_info[BUTTON_LONG_PRESS_UP];
266+
uint16_t time = cb_info[btn->count[1] + 1].event_args.long_press.press_time;
267+
if (btn->long_press_ticks * TICKS_INTERVAL > time) {
268+
for (int i = btn->count[1] + 1; i < btn->size[BUTTON_LONG_PRESS_UP]; i++) {
269+
time = cb_info[i].event_args.long_press.press_time;
270+
if (btn->long_press_ticks * TICKS_INTERVAL <= time) {
271+
btn->count[1] = i;
272+
break;
273273
}
274274
}
275-
if (btn->count[1] + 1 < btn->size[BUTTON_LONG_PRESS_UP] && abs((int)ticks_time - (int)time) <= TOLERANCE) {
276-
do {
277-
btn->count[1]++;
278-
if (btn->count[1] + 1 >= btn->size[BUTTON_LONG_PRESS_UP]) {
279-
break;
280-
}
281-
} while (time == cb_info[btn->count[1] + 1].event_args.long_press.press_time);
282-
}
275+
}
276+
if (btn->count[1] + 1 < btn->size[BUTTON_LONG_PRESS_UP] && abs((int)ticks_time - (int)time) <= TOLERANCE) {
277+
do {
278+
btn->count[1]++;
279+
if (btn->count[1] + 1 >= btn->size[BUTTON_LONG_PRESS_UP]) {
280+
break;
281+
}
282+
} while (time == cb_info[btn->count[1] + 1].event_args.long_press.press_time);
283283
}
284284
}
285285
} else { //releasd

0 commit comments

Comments
 (0)