From 278de69a160c225519c94fb4411880c0f2867942 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 1 Jun 2022 14:31:17 +0200 Subject: [PATCH] button logic (WIP) --- src/gbmanager.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index ee9037b..48d1977 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -15,6 +15,9 @@ constexpr uint I2C_SDA_PIN = 26; constexpr uint I2C_SCL_PIN = 27; constexpr uint DS18B20_PIN = 28; constexpr uint RELAIS_PIN = 18; +constexpr uint BUTTON_1_PIN = 17; +constexpr uint BUTTON_2_PIN = 16; +constexpr uint BUTTON_3_PIN = 15; // Custom chars for the LCD constexpr char CUSTOM_CHAR_DEG = 0xDF; @@ -22,6 +25,23 @@ constexpr char CUSTOM_CHAR_AE = 0xE1; using std::string; +void buttonPressedCallback(uint gpio, uint32_t events) { + static absolute_time_t lastPressed = get_absolute_time(); + switch (gpio) { + case BUTTON_1_PIN: + break; + case BUTTON_2_PIN: + break; + case BUTTON_3_PIN: + if (absolute_time_diff_us(lastPressed, get_absolute_time()) > 750000) { + std::cout << "Button 3 pressed!" << std::endl; + lastPressed = get_absolute_time(); + } + + break; + } +} + int main() { // Enable UART so we can print status output stdio_init_all(); @@ -39,6 +59,12 @@ int main() { // Initialize the relais Relais relais(RELAIS_PIN); + // Initialize the Buttons + gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, true, + &buttonPressedCallback); + gpio_set_irq_enabled(BUTTON_2_PIN, GPIO_IRQ_EDGE_FALL, true); + gpio_set_irq_enabled(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, true); + float temp_act{0}; float temp_tgt{28.0}; float temp_diff{0.5};