ESP32-PaxCounter/src/button.cpp

51 lines
1.3 KiB
C++
Raw Normal View History

2018-07-23 08:25:23 +02:00
#ifdef HAS_BUTTON
#include "globals.h"
#include "button.h"
2018-07-23 08:25:23 +02:00
// Local logging tag
2019-02-27 00:49:32 +01:00
static const char TAG[] = __FILE__;
2018-07-23 08:25:23 +02:00
2022-11-06 15:00:54 +01:00
OneButton button(HAS_BUTTON, !BUTTON_ACTIVEHIGH, !!BUTTON_PULLUP);
TaskHandle_t buttonLoopTask;
2019-05-03 20:24:42 +02:00
2022-11-06 15:00:54 +01:00
void IRAM_ATTR readButton(void) { button.tick(); }
2019-05-03 20:24:42 +02:00
2022-11-06 15:00:54 +01:00
void singleClick(void) {
#ifdef HAS_DISPLAY
2022-11-06 15:00:54 +01:00
dp_refresh(true); // switch to next display page
2019-05-31 13:20:11 +02:00
#endif
#ifdef HAS_MATRIX_DISPLAY
2022-11-06 15:00:54 +01:00
refreshTheMatrixDisplay(true); // switch to next display page
2019-05-31 13:20:11 +02:00
#endif
2022-11-06 15:00:54 +01:00
}
2019-05-31 13:20:11 +02:00
2022-11-06 15:00:54 +01:00
void longPressStart(void) {
payload.reset();
payload.addButton(0x01);
SendPayload(BUTTONPORT);
}
2019-05-03 20:24:42 +02:00
2022-11-06 15:00:54 +01:00
void buttonLoop(void *parameter) {
while (1) {
doIRQ(BUTTON_IRQ);
delay(20);
}
2018-07-23 08:25:23 +02:00
}
2019-05-03 20:24:42 +02:00
2022-11-06 15:00:54 +01:00
void button_init(void) {
ESP_LOGI(TAG, "Starting button Controller...");
xTaskCreatePinnedToCore(buttonLoop, // task function
"buttonloop", // name of task
2048, // stack size of task
(void *)1, // parameter of the task
2, // priority of the task
&buttonLoopTask, // task handle
1); // CPU core
button.setPressTicks(1000);
button.attachClick(singleClick);
button.attachLongPressStart(longPressStart);
};
2018-07-23 08:25:23 +02:00
#endif