summaryrefslogtreecommitdiff
path: root/src/gpio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpio.cpp')
-rw-r--r--src/gpio.cpp38
1 files changed, 7 insertions, 31 deletions
diff --git a/src/gpio.cpp b/src/gpio.cpp
index 6746a48..7f473ec 100644
--- a/src/gpio.cpp
+++ b/src/gpio.cpp
@@ -5,8 +5,6 @@
#include <Arduino.h>
-#define BUTTON_PIN 0
-
#if UVOK_EPAP_BOARD == BOARD_ESP32_CROWPANEL
// Elecrow
#define EXIT_KEY 1
@@ -62,7 +60,7 @@ void de::uvok::badge::gpio_init(void)
gpio_task_stuff.queue_handle =
xQueueCreateStatic(4, sizeof(pin_notification_t), &(gpio_task_stuff.queue_storage[0]), &gpio_task_stuff.queue);
#if UVOK_EPAP_BOARD == BOARD_ESP32_CROWPANEL
- uint8_t inPins[] = {EXIT_KEY, HOME_KEY, NEXT_KEY, OK_KEY, PRV_KEY};
+ uint8_t inPins[] = {BOOT_KEY, EXIT_KEY, HOME_KEY, NEXT_KEY, OK_KEY, PRV_KEY};
for (uint8_t p : inPins)
{
pinMode(p, GPIO_MODE_INPUT);
@@ -73,41 +71,19 @@ void de::uvok::badge::gpio_init(void)
#endif
}
-static volatile uint8_t event;
+static volatile uint32_t event;
// "Poll task", for button 0.
-long de::uvok::badge::gpio_poll(void)
+de::uvok::badge::gpio_poll_result_t de::uvok::badge::gpio_poll(void)
{
- static unsigned long pressedTime = 0;
- static unsigned long releasedTime = 0;
-
- int x = 0;
- static int lastState = HIGH;
- int buttonState = digitalRead(BUTTON_PIN);
- long pressDuration = 0;
- if (lastState == HIGH && buttonState == LOW)
- {
- Serial.println("``\\__");
- pressedTime = millis();
- lastState = LOW;
- }
- else if (lastState == LOW && buttonState == HIGH)
- {
- lastState = HIGH;
- Serial.println("__/``");
- releasedTime = millis();
-
- pressDuration = releasedTime - pressedTime;
- };
-
if (event)
{
- uint8_t r = event;
+ uint32_t r = event;
event = 0;
- return r;
+ return {.duration_ms = (r >> 8), .pin_number = (r & 0xff), .has_data = true};
}
- return pressDuration;
+ return {0};
}
//! GPIO task loop, read / handle queue.
@@ -134,7 +110,7 @@ static void gpio_loop(void *ctx)
continue;
LOG_F(" Handling\n");
- event = pin;
+ event = ((inputs[pin].released - inputs[pin].pressed) << 8) | (pin & 0xff);
}
}
}