From af3109fe80d7851e04b5309f34f71767ea0f362a Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Mon, 6 Mar 2023 10:46:57 -1000 Subject: [PATCH] Fix button press LEDs behavior --- Firmware/LoRaSerial/LoRaSerial.ino | 1 + Firmware/LoRaSerial/System.ino | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Firmware/LoRaSerial/LoRaSerial.ino b/Firmware/LoRaSerial/LoRaSerial.ino index f907dc65..6a33749f 100644 --- a/Firmware/LoRaSerial/LoRaSerial.ino +++ b/Firmware/LoRaSerial/LoRaSerial.ino @@ -490,6 +490,7 @@ bool trainingPreviousRxInProgress = false; //Previous RX status float originalChannel; //Original channel from HOP table while training is in progress uint8_t trainingPartnerID[UNIQUE_ID_BYTES]; //Unique ID of the training partner uint8_t myUniqueId[UNIQUE_ID_BYTES]; // Unique ID of this system +uint32_t buttonPressedTime; //Virtual-Circuit int8_t cmdVc; //VC index for ATI commands only diff --git a/Firmware/LoRaSerial/System.ino b/Firmware/LoRaSerial/System.ino index 374f1b4d..d1c76b13 100644 --- a/Firmware/LoRaSerial/System.ino +++ b/Firmware/LoRaSerial/System.ino @@ -261,7 +261,6 @@ void updateButton() static bool buttonWasPressed; uint32_t deltaTime; static Settings originalSettings; - static uint32_t pressedTime; if (trainBtn != NULL) { @@ -271,9 +270,7 @@ void updateButton() //Determine the current button state if (buttonWasPressed) { - //Update the LEDs - deltaTime = millis() - pressedTime; - buttonLeds(deltaTime); + deltaTime = millis() - buttonPressedTime; if (!buttonPressed) { //Button just released @@ -319,8 +316,6 @@ void updateButton() else { //The user has stopped training with the button - //Restore the previous settings - settings = originalSettings; if (inTraining) { inTraining = false; @@ -338,11 +333,14 @@ void updateButton() if (buttonPressed) { //Button just pressed - pressedTime = millis(); + buttonPressedTime = millis(); //Save the previous led state if (!inTraining) + { originalSettings = settings; + settings.selectLedUse = LEDS_BUTTON_PRESS; + } } } @@ -1064,14 +1062,16 @@ void updateCylonLEDs() } //Acknowledge the button press -void buttonLeds(uint32_t pressedMilliseconds) +void buttonLeds() { const uint32_t blinkTime = 1000 / 4; //Blink 4 times per second uint8_t on; const uint32_t onTime = blinkTime / 2; + uint32_t pressedMilliseconds; uint8_t seconds; //Display the number of seconds the button has been pushed + pressedMilliseconds = millis() - buttonPressedTime; seconds = pressedMilliseconds / 1000; setRSSI((pressedMilliseconds >= trainButtonFactoryResetTime) ? 15 : seconds); @@ -1146,6 +1146,10 @@ void updateLeds() radioLeds(); break; + case LEDS_BUTTON_PRESS: + buttonLeds(); + break; + //Turn off all the LEDs case LEDS_ALL_OFF: break;