From b04f9e4758d695b7e024c81e7d9b66f13068dd8e Mon Sep 17 00:00:00 2001 From: Juan Antonio Date: Mon, 1 Jan 2024 14:12:32 +0100 Subject: [PATCH] Reduce nesting --- app/app.c | 18 +++++++++-------- app/flashlight.c | 50 +++++++++++++++++++++++++----------------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/app/app.c b/app/app.c index b9616374e..e3dc5746f 100644 --- a/app/app.c +++ b/app/app.c @@ -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 diff --git a/app/flashlight.c b/app/flashlight.c index 32c6c1a19..9c31d4495 100644 --- a/app/flashlight.c +++ b/app/flashlight.c @@ -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++; } }