new button lib

This commit is contained in:
cyberman54 committed 2022-11-06 15:00:54 +01:00
1 parent 0a36377e66
commit 4015e9e989
10 files changed
+61 -53

No files matched your search

+34 -27
View File
@@ -3,42 +3,49 @@
#include "globals.h"
#include "button.h"
using namespace simplebutton;
// Local logging tag
static const char TAG[] = __FILE__;
static Button *b = NULL;
OneButton button(HAS_BUTTON, !BUTTON_ACTIVEHIGH, !!BUTTON_PULLUP);
TaskHandle_t buttonLoopTask;
void button_init(int pin) {
#ifdef BUTTON_PULLUP
b = new ButtonPullup(pin);
#else
b = new Button(pin, !BUTTON_ACTIVEHIGH);
#endif
void IRAM_ATTR readButton(void) { button.tick(); }
// attach events to the button
b->setOnDoubleClicked([]() {});
b->setOnClicked([]() {
void singleClick(void) {
#ifdef HAS_DISPLAY
dp_refresh(true); // switch to next display page
dp_refresh(true); // switch to next display page
#endif
#ifdef HAS_MATRIX_DISPLAY
refreshTheMatrixDisplay(true); // switch to next display page
refreshTheMatrixDisplay(true); // switch to next display page
#endif
});
b->setOnHolding([]() {
payload.reset();
payload.addButton(0x01);
SendPayload(BUTTONPORT);
});
// attach interrupt to the button
attachInterrupt(digitalPinToInterrupt(pin), ButtonIRQ, CHANGE);
}
void readButton() { b->update(); }
void longPressStart(void) {
payload.reset();
payload.addButton(0x01);
SendPayload(BUTTONPORT);
}
void buttonLoop(void *parameter) {
while (1) {
doIRQ(BUTTON_IRQ);
delay(20);
}
}
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);
};
#endif
+7
View File
@@ -71,6 +71,13 @@ void doHousekeeping() {
eTaskGetState(ledLoopTask));
#endif
#ifdef HAS_BUTTON
if (buttonLoopTask != NULL)
ESP_LOGD(TAG, "Buttonloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(buttonLoopTask),
eTaskGetState(buttonLoopTask));
#endif
// read battery voltage into global variable
#if (defined BAT_MEASURE_ADC || defined HAS_PMU || defined HAS_IP5306)
batt_level = read_battlevel();
+4 -12
View File
@@ -13,10 +13,10 @@ void irqHandler(void *pvParameters) {
// task remains in blocked state until it is notified by an irq
for (;;) {
xTaskNotifyWait(0x00, // Don't clear any bits on entry
ULONG_MAX, // Clear all bits on exit
&irqSource, // Receives the notification value
portMAX_DELAY); // wait forever
xTaskNotifyWait(0x00, // Don't clear any bits on entry
ULONG_MAX, // Clear all bits on exit
&irqSource, // Receives the notification value
portMAX_DELAY); // wait forever
if (irqSource & UNMASK_IRQ) // interrupt handler to be enabled?
irqSource &= ~MASK_IRQ; // then clear irq mask flag
@@ -102,14 +102,6 @@ void IRAM_ATTR DisplayIRQ() { doIRQ(DISPLAY_IRQ); }
void IRAM_ATTR MatrixDisplayIRQ() { doIRQ(MATRIX_DISPLAY_IRQ); }
#endif
#ifdef HAS_BUTTON
void IRAM_ATTR ButtonIRQ() { doIRQ(BUTTON_IRQ); }
#endif
#ifdef HAS_PMU
void IRAM_ATTR PMUIRQ() { doIRQ(PMU_IRQ); }
#endif
void mask_user_IRQ() { xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); }
void unmask_user_IRQ() { xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits); }
+2 -1
View File
@@ -28,6 +28,7 @@ licenses. Refer to LICENSE.txt file in repository for more details.
Task Core Prio Purpose
-------------------------------------------------------------------------------
ledloop* 1 1 blinks LEDs
buttonloop* 1 2 reads button
spiloop# 0 2 reads/writes data on spi interface
lmictask* 1 2 MCCI LMiC LORAWAN stack
clockloop# 1 6 generates realtime telegrams for external clock
@@ -468,7 +469,7 @@ void setup() {
#else
strcat_P(features, "PD");
#endif // BUTTON_PULLUP
button_init(HAS_BUTTON);
button_init();
#endif // HAS_BUTTON
// only if we have a timesource we do timesync
+2
View File
@@ -25,6 +25,8 @@ static const adc_unit_t unit = ADC_UNIT_1;
#ifdef HAS_PMU
XPowersPMU pmu;
void IRAM_ATTR PMUIRQ() { doIRQ(PMU_IRQ); }
void AXP192_powerevent_IRQ(void) {
pmu.getIrqStatus();