button handling improvment

This commit is contained in:
Verkehrsrot committed 2019-05-03 20:24:42 +02:00
1 parent 2b82223d3d
commit 45b51441ec
4 files changed
+54 -35

No files matched your search

+34 -7
View File
@@ -3,17 +3,44 @@
#include "globals.h"
#include "button.h"
using namespace simplebutton;
// Local logging tag
static const char TAG[] = __FILE__;
void readButton() {
ESP_LOGI(TAG, "Button pressed");
#ifdef HAS_DISPLAY
refreshtheDisplay(true); // switch to next display page
static Button *b = NULL;
void button_init(int pin) {
#ifdef BUTTON_PULLDOWN
b = new Button(pin);
#else
payload.reset();
payload.addButton(0x01);
SendPayload(BUTTONPORT, prio_normal);
b = new ButtonPullup(pin);
#endif
// attach events to the button
b->setOnDoubleClicked([]() {});
b->setOnClicked([]() {
#ifdef HAS_DISPLAY
refreshtheDisplay(true); // switch to next display page
#else
payload.reset();
payload.addButton(0x01);
SendPayload(BUTTONPORT, prio_normal);
#endif
});
b->setOnHolding([]() {
#if (HAS_LORA)
cfg.adrmode = !cfg.adrmode;
LMIC_setAdrMode(cfg.adrmode);
#endif
});
// attach interrupt to the button
attachInterrupt(digitalPinToInterrupt(pin), ButtonIRQ, CHANGE);
}
void readButton() { b->update(); }
#endif
+15 -27
View File
@@ -265,20 +265,6 @@ void setup() {
esp_coex_prefer_t)ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib
#endif
// initialize button
#ifdef HAS_BUTTON
strcat_P(features, " BTN_");
#ifdef BUTTON_PULLUP
strcat_P(features, "PU");
// install button interrupt (pullup mode)
pinMode(HAS_BUTTON, INPUT_PULLUP);
#else
strcat_P(features, "PD");
// install button interrupt (pulldown mode)
pinMode(HAS_BUTTON, INPUT_PULLDOWN);
#endif // BUTTON_PULLUP
#endif // HAS_BUTTON
// initialize gps
#if (HAS_GPS)
strcat_P(features, " GPS");
@@ -364,9 +350,6 @@ void setup() {
esp_wifi_deinit();
#endif
// show compiled features
ESP_LOGI(TAG, "Features:%s", features);
// start state machine
ESP_LOGI(TAG, "Starting Interrupt Handler...");
xTaskCreatePinnedToCore(irqHandler, // task function
@@ -410,7 +393,18 @@ void setup() {
timerAlarmEnable(displayIRQ);
#endif
// gps buffer read interrupt
// initialize button
#ifdef HAS_BUTTON
strcat_P(features, " BTN_");
#ifdef BUTTON_PULLUP
strcat_P(features, "PU");
#else
strcat_P(features, "PD");
#endif // BUTTON_PULLUP
button_init(HAS_BUTTON);
#endif // HAS_BUTTON
// gps buffer read interrupt
#if (HAS_GPS)
gpsIRQ = timerBegin(2, 80, true);
timerAttachInterrupt(gpsIRQ, &GpsIRQ, true);
@@ -422,15 +416,6 @@ void setup() {
sendcycler.attach(SENDCYCLE * 2, sendcycle);
housekeeper.attach(HOMECYCLE, housekeeping);
// button interrupt
#ifdef HAS_BUTTON
#ifdef BUTTON_PULLUP
attachInterrupt(digitalPinToInterrupt(HAS_BUTTON), ButtonIRQ, RISING);
#else
attachInterrupt(digitalPinToInterrupt(HAS_BUTTON), ButtonIRQ, FALLING);
#endif
#endif // HAS_BUTTON
#if (TIME_SYNC_INTERVAL)
#if (!(TIME_SYNC_LORAWAN) && !(TIME_SYNC_LORASERVER) && !defined HAS_GPS && \
@@ -453,6 +438,9 @@ void setup() {
#endif // TIME_SYNC_INTERVAL
// show compiled features
ESP_LOGI(TAG, "Features:%s", features);
} // setup()
void loop() {