Skip to content

Commit efee7e2

Browse files
committed
fix(touch): avoid reading the button state when disabled (#162)
Closes #162
1 parent a5007cc commit efee7e2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/drivers/touch/esp_panel_touch.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ bool Touch::readRawData(int points_num, int buttons_num, int timeout_ms)
304304
// Get the points
305305
ESP_UTILS_CHECK_FALSE_RETURN(readRawDataPoints(points_num), false, "Read points failed");
306306

307+
#if CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0
307308
// Get the buttons
308309
ESP_UTILS_CHECK_FALSE_RETURN(readRawDataButtons(buttons_num), false, "Read buttons failed");
310+
#endif
309311

310312
ESP_UTILS_LOG_TRACE_EXIT_WITH_THIS();
311313

@@ -610,10 +612,10 @@ bool Touch::readRawDataButtons(int buttons_num)
610612
}
611613
// Limit the max buttons number
612614
if (buttons_num > BUTTONS_MAX_NUM) {
613-
buttons_num = BUTTONS_MAX_NUM;
614615
ESP_UTILS_LOGW(
615616
"The target buttons number(%d) out of range, use the max number(%d) instead", buttons_num, BUTTONS_MAX_NUM
616617
);
618+
buttons_num = BUTTONS_MAX_NUM;
617619
}
618620
if (buttons_num <= 0) {
619621
ESP_UTILS_LOGD("Ignore to read buttons");
@@ -627,13 +629,14 @@ bool Touch::readRawDataButtons(int buttons_num)
627629

628630
for (int i = 0; i < buttons_num; i++) {
629631
button_state = 0;
632+
#if CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0
630633
auto ret = esp_lcd_touch_get_button_state(touch_panel, i, &button_state);
631634
if (ret == ESP_ERR_INVALID_ARG) {
632635
ESP_UTILS_LOGD("Button(%d) is not supported", i);
633636
break;
634637
}
635638
ESP_UTILS_CHECK_ERROR_RETURN(ret, false, "Get button(%d) state failed", i);
636-
639+
#endif
637640
buttons.emplace_back(i, button_state);
638641
}
639642

0 commit comments

Comments
 (0)