ESP32-PaxCounter/src/button.cpp

51 lines
1005 B
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
2019-05-03 20:24:42 +02:00
using namespace simplebutton;
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
2019-05-03 20:24:42 +02:00
static Button *b = NULL;
void button_init(int pin) {
#ifdef BUTTON_PULLDOWN
b = new Button(pin);
#else
b = new ButtonPullup(pin);
#endif
// attach events to the button
b->setOnDoubleClicked([]() {});
b->setOnClicked([]() {
#ifdef HAS_DISPLAY
2019-05-31 13:20:11 +02:00
refreshTheDisplay(true); // switch to next display page
#endif
#ifdef HAS_MATRIX_DISPLAY
refreshTheMatrixDisplay(true); // switch to next display page
#endif
#if (!defined HAS_DISPLAY) && (!defined HAS_MATRIX_DISPLAY)
2019-05-03 20:24:42 +02:00
payload.reset();
payload.addButton(0x01);
SendPayload(BUTTONPORT, prio_normal);
#endif
});
b->setOnHolding([]() {
#if (HAS_LORA)
cfg.adrmode = !cfg.adrmode;
LMIC_setAdrMode(cfg.adrmode);
#endif
2019-05-03 20:24:42 +02:00
});
// attach interrupt to the button
attachInterrupt(digitalPinToInterrupt(pin), ButtonIRQ, CHANGE);
2018-07-23 08:25:23 +02:00
}
2019-05-03 20:24:42 +02:00
void readButton() { b->update(); }
2018-07-23 08:25:23 +02:00
#endif