Missing files in commit
This commit is contained in:
parent
4538326990
commit
687bc1f60d
23 changed files with 1485 additions and 61 deletions
63
src/lib/button_handler.cpp
Normal file
63
src/lib/button_handler.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include "button_handler.hpp"
|
||||
|
||||
TaskHandle_t buttonTaskHandle = NULL;
|
||||
const TickType_t debounceDelay = pdMS_TO_TICKS(50);
|
||||
TickType_t lastDebounceTime = 0;
|
||||
|
||||
void buttonTask(void *parameter)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
TickType_t currentTime = xTaskGetTickCount();
|
||||
if ((currentTime - lastDebounceTime) >= debounceDelay)
|
||||
{
|
||||
lastDebounceTime = currentTime;
|
||||
|
||||
if (!digitalRead(MCP_INT_PIN))
|
||||
{
|
||||
uint pin = mcp.getLastInterruptPin();
|
||||
|
||||
Serial.printf("Button pressed: %d", pin);
|
||||
// switch (pin)
|
||||
// {
|
||||
// case 3:
|
||||
// toggleScreenTimer();
|
||||
// break;
|
||||
// case 2:
|
||||
// nextScreen();
|
||||
// break;
|
||||
// case 1:
|
||||
// previousScreen();
|
||||
// break;
|
||||
// case 0:
|
||||
// showNetworkSettings();
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
mcp.clearInterrupts();
|
||||
// Very ugly, but for some reason this is necessary
|
||||
while (!digitalRead(MCP_INT_PIN))
|
||||
{
|
||||
mcp.clearInterrupts();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR handleButtonInterrupt()
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
xTaskNotifyFromISR(buttonTaskHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
|
||||
if (xHigherPriorityTaskWoken == pdTRUE)
|
||||
{
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
void setupButtonTask()
|
||||
{
|
||||
xTaskCreate(buttonTask, "ButtonTask", 4096, NULL, tskIDLE_PRIORITY, &buttonTaskHandle); // Create the FreeRTOS task
|
||||
// Use interrupt instead of task
|
||||
attachInterrupt(MCP_INT_PIN, handleButtonInterrupt, CHANGE);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue