From 249b0b2bb708953361386768ba899741f73af4a2 Mon Sep 17 00:00:00 2001 From: mrkusypl Date: Thu, 26 Mar 2026 17:47:21 +0100 Subject: [PATCH] Optimizing the Audio Scope code --- App/app/app.c | 16 ++++++++-------- App/ui/main.c | 24 +++++++++++------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/App/app/app.c b/App/app/app.c index b5ed912f..f9e0b099 100644 --- a/App/app/app.c +++ b/App/app/app.c @@ -1371,14 +1371,14 @@ void APP_TimeSlice10ms(void) } #ifdef ENABLE_FEAT_F4HWN_AUDIO_SCOPE - // Sample audio amplitude every 30ms - if ((gFlashLightBlinkCounter % 3) == 0) - UI_AudioScope_AddSample(); - // Refresh display every 30ms during TX only (FM RX has no usable audio register) - if ((gFlashLightBlinkCounter % 3) == 0 && - gScreenToDisplay == DISPLAY_MAIN && - gCurrentFunction == FUNCTION_TRANSMIT) - UI_DisplayAudioScope(); + if (gCurrentFunction == FUNCTION_TRANSMIT) { // during TX only (FM RX has no usable audio register) + if (gSetting_mic_bar && (gFlashLightBlinkCounter % (30 / 10)) == 0) { // once every 30ms + // Sample audio amplitude + UI_AudioScope_AddSample(); + // Refresh display + UI_DisplayAudioScope(); + } + } #endif bool gUpdateDisplayCurrent = gUpdateDisplay; diff --git a/App/ui/main.c b/App/ui/main.c index 1aa29248..a6b9a62a 100644 --- a/App/ui/main.c +++ b/App/ui/main.c @@ -235,7 +235,7 @@ void UI_DisplayAudioBar(void) #ifdef ENABLE_FEAT_F4HWN_AUDIO_SCOPE -#define SCOPE_SAMPLES 42 +#define SCOPE_SAMPLES 43 static uint16_t g_scope_buf[SCOPE_SAMPLES]; static uint8_t g_scope_write = 0; @@ -245,8 +245,6 @@ void UI_AudioScope_AddSample(void) { // REG_64 (VoiceAmplitudeOut) is only meaningful in TX (mic input). // FM RX audio is frequency-encoded — no register gives the instantaneous waveform. - if (gCurrentFunction != FUNCTION_TRANSMIT) - return; const uint16_t value = BK4819_GetVoiceAmplitudeOut(); g_scope_buf[g_scope_write] = value; @@ -258,15 +256,6 @@ void UI_DisplayAudioScope(void) if (gLowBattery && !gLowBatteryConfirmed) return; -#ifdef ENABLE_FEAT_F4HWN - RxBlinkLed = 0; - RxBlinkLedCounter = 0; - BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, false); - const unsigned int line = isMainOnly() ? 5 : 3; -#else - const unsigned int line = 3; -#endif - if (gScreenToDisplay != DISPLAY_MAIN #ifdef ENABLE_DTMF_CALLING || gDTMF_CallState != DTMF_CALL_STATE_NONE @@ -279,6 +268,15 @@ void UI_DisplayAudioScope(void) return; #endif +#ifdef ENABLE_FEAT_F4HWN + RxBlinkLed = 0; + RxBlinkLedCounter = 0; + BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, false); + const unsigned int line = isMainOnly() ? 5 : 3; +#else + const unsigned int line = 3; +#endif + uint8_t *p_line = gFrameBuffer[line]; memset(p_line, 0, LCD_WIDTH); @@ -1563,7 +1561,7 @@ void UI_DisplayMain(void) const bool rx = FUNCTION_IsRx(); #ifdef ENABLE_FEAT_F4HWN_AUDIO_SCOPE - if (gCurrentFunction == FUNCTION_TRANSMIT) { + if (gSetting_mic_bar && gCurrentFunction == FUNCTION_TRANSMIT) { // Reserve the line so no other element overwrites it. // Actual drawing is handled exclusively by the app.c timeslice. center_line = CENTER_LINE_AUDIO_SCOPE;