From 103bdf212f6c80a6bd6de598e3f521e59111feb8 Mon Sep 17 00:00:00 2001 From: Juan Antonio Date: Mon, 4 Dec 2023 18:50:41 +0100 Subject: [PATCH] Use enum for Flaslight & return early --- app/action.c | 7 ++++--- app/app.c | 34 +++++++++++++++++++--------------- misc.c | 4 +++- misc.h | 4 ++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app/action.c b/app/action.c index 025732e..a4cd3ac 100644 --- a/app/action.c +++ b/app/action.c @@ -43,14 +43,15 @@ static void ACTION_FlashLight(void) { switch (gFlashLightState) { - case 0: + case FLASHLIGHT_OFF: gFlashLightState++; GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); break; - case 1: - case 2: + case FLASHLIGHT_ON: + case FLASHLIGHT_BLINK: gFlashLightState++; break; + case FLASHLIGHT_SOS: default: gFlashLightState = 0; GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); diff --git a/app/app.c b/app/app.c index e4c926e..e8674ce 100644 --- a/app/app.c +++ b/app/app.c @@ -2045,33 +2045,37 @@ Skip: static void FlashlightTimeSlice() { - if (gFlashLightState == FLASHLIGHT_BLINK && (gFlashLightBlinkCounter & 15u) == 0) + if (gFlashLightState == FLASHLIGHT_BLINK && (gFlashLightBlinkCounter & 15u) == 0) { GPIO_FlipBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); - else if(gFlashLightState == FLASHLIGHT_SOS) { + return; + } + + if (gFlashLightState == FLASHLIGHT_SOS) { const uint16_t u = 15; static uint8_t c; static uint16_t next; - if(gFlashLightBlinkCounter - next > 7*u) { + if (gFlashLightBlinkCounter - next > 7 * u) { c = 0; next = gFlashLightBlinkCounter + 1; + return; } - else if(gFlashLightBlinkCounter == next) { - if(c==0) { + + if (gFlashLightBlinkCounter == next) { + if (c==0) { GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); - } - else + } else { GPIO_FlipBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); - - if(c >= 18) { - next = gFlashLightBlinkCounter + 7*u; - c = 0; } - else if(c==7 || c==9 || c==11) - next = gFlashLightBlinkCounter + 3*u; - else - next = gFlashLightBlinkCounter + u; + if (c >= 18) { + next = gFlashLightBlinkCounter + 7 * u; + c = 0; + } else if(c==7 || c==9 || c==11) { + next = gFlashLightBlinkCounter + 3 * u; + } else { + next = gFlashLightBlinkCounter + u; + } c++; } } diff --git a/misc.c b/misc.c index 592fb09..038dbb1 100644 --- a/misc.c +++ b/misc.c @@ -198,7 +198,9 @@ bool g_CxCSS_TAIL_Found; uint16_t gVoxPauseCountdown; #endif bool g_SquelchLost; -uint8_t gFlashLightState; + +enum FlashlightMode_t gFlashLightState; + volatile uint16_t gFlashLightBlinkCounter; bool gFlagEndTransmission; uint8_t gNextMrChannel; diff --git a/misc.h b/misc.h index d635dca..59e70a0 100644 --- a/misc.h +++ b/misc.h @@ -47,7 +47,7 @@ enum { LAST_CHANNEL }; -enum { +enum FlashlightMode_t { FLASHLIGHT_OFF = 0, FLASHLIGHT_ON, FLASHLIGHT_BLINK, @@ -285,7 +285,7 @@ extern bool g_CxCSS_TAIL_Found; // true means we are receiving signal extern bool g_SquelchLost; -extern uint8_t gFlashLightState; +extern enum FlashlightMode_t gFlashLightState; extern volatile uint16_t gFlashLightBlinkCounter; extern bool gFlagEndTransmission; extern uint8_t gNextMrChannel;