From 0ca1aa5fd0d8c872327ea4d1b23910d52bfeb6aa Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 25 Apr 2018 12:07:36 +0200 Subject: [PATCH] bugfixing LED blink (note yet fixed) --- src/main.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1256b5a5..5407dc15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,7 +50,7 @@ uint8_t channel = 0; // wifi channel rotation counter global for char display_lora[16], display_lmic[16], display_mem[16]; // display buffers enum states LEDState = LED_OFF, previousLEDState = LED_OFF; // LED state global for state machine bool joinstate = false; // LoRa network joined? global flag -bool oneblink = false, blinkdone = false; // flags for state machine for blinking LED once +bool blinkdone = false; // flag for state machine for blinking LED once const uint32_t heapmem = ESP.getFreeHeap(); // free heap memory after start (:= 100%) std::set macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE) @@ -71,11 +71,10 @@ int redirect_log(const char * fmt, va_list args) { #endif void blink_LED (uint16_t set_color, uint16_t set_blinkduration, uint16_t set_interval) { - ESP_LOGI(TAG, "blink_LED color: %d, duration: %d, interval: %d", set_color, set_blinkduration, set_interval); color = set_color; // set color for RGB LED LEDBlinkduration = set_blinkduration; // duration on LEDInterval = set_interval; // duration off - on - off - oneblink = set_interval ? false : true; // set blinking mode: continuous or single blink + blinkdone = false; } void reset_counters() { @@ -410,23 +409,17 @@ uint64_t uptime() { #endif previousLEDState = LEDState; + blinkdone = LEDState ? true : false; } }; // switchLED() void switchLEDstate() { - - if (oneblink && !blinkdone) { // keep LED on until one blink is done - LEDState = (currentMillis % LEDBlinkduration) > 0 ? LED_ON : LED_OFF; - blinkdone = LEDState ? false : true; - } - - else - if (LEDInterval) // LED is blinking, wait until time elapsed, then toggle LED LEDState = ((currentMillis % LEDInterval) < LEDBlinkduration) ? LED_ON : LED_OFF; - - + else // check if in oneblink mode + if (!blinkdone) { // keep LED on until one blink is done + LEDState = (currentMillis % LEDBlinkduration) > 0 ? LED_ON : LED_OFF; } // switchLEDstate() #endif