Skip to content

Commit

Permalink
Use enum for Flaslight & return early
Browse files Browse the repository at this point in the history
  • Loading branch information
JuantAldea committed Dec 4, 2023
1 parent a1360f6 commit 13b7b27
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
7 changes: 4 additions & 3 deletions app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 18 additions & 14 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2095,33 +2095,37 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)

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;
if (c >= 18) {
next = gFlashLightBlinkCounter + 7 * u;
c = 0;
}
else if(c==7 || c==9 || c==11)
next = gFlashLightBlinkCounter + 3*u;
else
} else if(c==7 || c==9 || c==11) {
next = gFlashLightBlinkCounter + 3 * u;
} else {
next = gFlashLightBlinkCounter + u;

}
c++;
}
}
Expand Down
4 changes: 3 additions & 1 deletion misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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;
Expand Down
4 changes: 2 additions & 2 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum {
LAST_CHANNEL
};

enum {
enum FlashlightMode_t {
FLASHLIGHT_OFF = 0,
FLASHLIGHT_ON,
FLASHLIGHT_BLINK,
Expand Down Expand Up @@ -286,7 +286,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;
Expand Down

0 comments on commit 13b7b27

Please sign in to comment.