Skip to content

Commit

Permalink
Reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
JuantAldea committed Jan 1, 2024
1 parent ec955a2 commit b04f9e4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
18 changes: 10 additions & 8 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,26 +1113,28 @@ void APP_TimeSlice10ms(void)
}
#endif

if (gReducedService)
if (gReducedService) {
return;
}

if (gCurrentFunction != FUNCTION_POWER_SAVE || !gRxIdleMode)
if (gCurrentFunction != FUNCTION_POWER_SAVE || !gRxIdleMode) {
CheckRadioInterrupts();
}

if (gCurrentFunction == FUNCTION_TRANSMIT)
{ // transmitting
#ifdef ENABLE_AUDIO_BAR
if (gSetting_mic_bar && (gFlashLightBlinkCounter % (150 / 10)) == 0) // once every 150ms
UI_DisplayAudioBar();
#endif
if (gCurrentFunction == FUNCTION_TRANSMIT && gSetting_mic_bar && (gFlashLightBlinkCounter % (150 / 10)) == 0) {
// transmitting
UI_DisplayAudioBar();
}
#endif

if (gUpdateDisplay) {
GUI_DisplayScreen();
}

if (gUpdateStatus)
if (gUpdateStatus) {
UI_DisplayStatus();
}

// Skipping authentic device checks

Expand Down
50 changes: 26 additions & 24 deletions app/flashlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,36 @@ void FlashlightTimeSlice()
return;
}

if (gFlashLightState == FLASHLIGHT_SOS) {
const uint16_t u = 15;
static uint8_t c;
static uint16_t next;
if (gFlashLightState != FLASHLIGHT_SOS) {
return;
}

if (gFlashLightBlinkCounter - next > 7 * u) {
c = 0;
next = gFlashLightBlinkCounter + 1;
return;
}
const uint16_t u = 15;
static uint8_t c;
static uint16_t next;

if (gFlashLightBlinkCounter - next > 7 * u) {
c = 0;
next = gFlashLightBlinkCounter + 1;
return;
}

if (gFlashLightBlinkCounter == next) {
if (c==0) {
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT);
} else {
GPIO_FlipBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT);
}
if (gFlashLightBlinkCounter == next) {
if (c==0) {
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT);
} 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;
}
c++;
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++;
}
}

Expand Down

0 comments on commit b04f9e4

Please sign in to comment.