Update WebUI and convert ButtonHandler to class
Some checks failed
BTClock CI / build (push) Failing after 19m28s
BTClock CI / merge (map[name:btclock_v8 version:esp32s3], 213epd) (push) Has been skipped
BTClock CI / merge (map[name:btclock_rev_b version:esp32s3], 213epd) (push) Has been skipped
BTClock CI / merge (map[name:lolin_s3_mini version:esp32s3], 213epd) (push) Has been skipped
BTClock CI / release (push) Has been skipped
BTClock CI / merge (map[name:lolin_s3_mini version:esp32s3], 29epd) (push) Has been skipped
Some checks failed
BTClock CI / build (push) Failing after 19m28s
BTClock CI / merge (map[name:btclock_v8 version:esp32s3], 213epd) (push) Has been skipped
BTClock CI / merge (map[name:btclock_rev_b version:esp32s3], 213epd) (push) Has been skipped
BTClock CI / merge (map[name:lolin_s3_mini version:esp32s3], 213epd) (push) Has been skipped
BTClock CI / release (push) Has been skipped
BTClock CI / merge (map[name:lolin_s3_mini version:esp32s3], 29epd) (push) Has been skipped
This commit is contained in:
parent
17fef80253
commit
cff6131fc4
5 changed files with 53 additions and 93 deletions
|
@ -1,7 +1,8 @@
|
|||
#include "button_handler.hpp"
|
||||
|
||||
TaskHandle_t buttonTaskHandle = NULL;
|
||||
ButtonState buttonStates[4];
|
||||
// Initialize static members
|
||||
TaskHandle_t ButtonHandler::buttonTaskHandle = NULL;
|
||||
ButtonState ButtonHandler::buttonStates[4] = {};
|
||||
|
||||
#ifdef IS_BTCLOCK_V8
|
||||
#define BTN_1 256
|
||||
|
@ -15,7 +16,7 @@ ButtonState buttonStates[4];
|
|||
#define BTN_4 256
|
||||
#endif
|
||||
|
||||
void buttonTask(void *parameter) {
|
||||
void ButtonHandler::buttonTask(void *parameter) {
|
||||
while (1) {
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
|
||||
|
@ -48,16 +49,6 @@ void buttonTask(void *parameter) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for long press on pressed buttons
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (buttonStates[i].isPressed && !buttonStates[i].longPressHandled) {
|
||||
if ((currentTime - buttonStates[i].pressStartTime) >= longPressDelay) {
|
||||
handleLongPress(i);
|
||||
buttonStates[i].longPressHandled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear interrupt state
|
||||
|
@ -68,56 +59,34 @@ void buttonTask(void *parameter) {
|
|||
}
|
||||
}
|
||||
|
||||
void handleButtonPress(int buttonIndex) {
|
||||
void ButtonHandler::handleButtonPress(int buttonIndex) {
|
||||
TickType_t currentTime = xTaskGetTickCount();
|
||||
ButtonState &state = buttonStates[buttonIndex];
|
||||
|
||||
if ((currentTime - state.lastPressTime) >= debounceDelay) {
|
||||
state.isPressed = true;
|
||||
state.pressStartTime = currentTime;
|
||||
state.longPressHandled = false;
|
||||
|
||||
// Check for double click
|
||||
if ((currentTime - state.lastPressTime) <= doubleClickDelay) {
|
||||
state.clickCount++;
|
||||
if (state.clickCount == 2) {
|
||||
handleDoubleClick(buttonIndex);
|
||||
state.clickCount = 0;
|
||||
}
|
||||
} else {
|
||||
state.clickCount = 1;
|
||||
}
|
||||
|
||||
state.lastPressTime = currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
void handleButtonRelease(int buttonIndex) {
|
||||
TickType_t currentTime = xTaskGetTickCount();
|
||||
void ButtonHandler::handleButtonRelease(int buttonIndex) {
|
||||
ButtonState &state = buttonStates[buttonIndex];
|
||||
|
||||
state.isPressed = false;
|
||||
if (!state.isPressed) return; // Ignore if button wasn't pressed
|
||||
|
||||
// If this wasn't a long press or double click, handle as single click
|
||||
if (!state.longPressHandled && state.clickCount == 1 &&
|
||||
(currentTime - state.pressStartTime) < longPressDelay) {
|
||||
handleSingleClick(buttonIndex);
|
||||
state.clickCount = 0;
|
||||
}
|
||||
state.isPressed = false;
|
||||
handleSingleClick(buttonIndex);
|
||||
}
|
||||
|
||||
// Button action handlers
|
||||
void handleSingleClick(int buttonIndex) {
|
||||
void ButtonHandler::handleSingleClick(int buttonIndex) {
|
||||
switch (buttonIndex) {
|
||||
case 0:
|
||||
toggleTimerActive();
|
||||
break;
|
||||
case 1:
|
||||
Serial.println("Button 2 single click");
|
||||
ScreenHandler::nextScreen();
|
||||
break;
|
||||
case 2:
|
||||
Serial.println("Button 3 single click");
|
||||
ScreenHandler::previousScreen();
|
||||
break;
|
||||
case 3:
|
||||
|
@ -126,15 +95,7 @@ void handleSingleClick(int buttonIndex) {
|
|||
}
|
||||
}
|
||||
|
||||
void handleDoubleClick(int buttonIndex) {
|
||||
Serial.printf("Button %d double clicked\n", buttonIndex + 1);
|
||||
}
|
||||
|
||||
void handleLongPress(int buttonIndex) {
|
||||
Serial.printf("Button %d long press detected\n", buttonIndex + 1);
|
||||
}
|
||||
|
||||
void IRAM_ATTR handleButtonInterrupt() {
|
||||
void IRAM_ATTR ButtonHandler::handleButtonInterrupt() {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
xTaskNotifyFromISR(buttonTaskHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
|
||||
if (xHigherPriorityTaskWoken == pdTRUE) {
|
||||
|
@ -142,7 +103,7 @@ void IRAM_ATTR handleButtonInterrupt() {
|
|||
}
|
||||
}
|
||||
|
||||
void setupButtonTask() {
|
||||
void ButtonHandler::setup() {
|
||||
xTaskCreate(buttonTask, "ButtonTask", 3072, NULL, tskIDLE_PRIORITY,
|
||||
&buttonTaskHandle);
|
||||
attachInterrupt(MCP_INT_PIN, handleButtonInterrupt, FALLING);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue