2018-07-23 08:25:23 +02:00
|
|
|
#ifdef HAS_BUTTON
|
|
|
|
|
|
|
|
#include "globals.h"
|
2018-10-04 22:08:54 +02:00
|
|
|
#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) {
|
2022-08-04 13:52:16 +02:00
|
|
|
#ifdef BUTTON_PULLUP
|
2019-05-03 20:24:42 +02:00
|
|
|
b = new ButtonPullup(pin);
|
2022-08-04 13:52:16 +02:00
|
|
|
#else
|
|
|
|
b = new Button(pin, !BUTTON_ACTIVEHIGH);
|
2019-05-03 20:24:42 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// attach events to the button
|
|
|
|
|
|
|
|
b->setOnDoubleClicked([]() {});
|
|
|
|
|
|
|
|
b->setOnClicked([]() {
|
2019-04-01 18:01:52 +02:00
|
|
|
#ifdef HAS_DISPLAY
|
2020-03-29 12:10:42 +02:00
|
|
|
dp_refresh(true); // switch to next display page
|
2019-05-31 13:20:11 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAS_MATRIX_DISPLAY
|
|
|
|
refreshTheMatrixDisplay(true); // switch to next display page
|
|
|
|
#endif
|
2019-07-13 18:21:13 +02:00
|
|
|
});
|
2019-05-31 13:20:11 +02:00
|
|
|
|
2019-07-13 18:21:13 +02:00
|
|
|
b->setOnHolding([]() {
|
2019-05-03 20:24:42 +02:00
|
|
|
payload.reset();
|
|
|
|
payload.addButton(0x01);
|
2020-12-09 11:01:54 +01:00
|
|
|
SendPayload(BUTTONPORT);
|
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
|