From 3f958f637df13e91728ff9fec0ac288412f276f3 Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Tue, 25 Aug 2026 22:06:24 +0200 Subject: [PATCH] Optimize FoxHunt Flash usage --- App/app/foxhunt.c | 28 +++++------------------ App/ui/status.c | 57 ++++++++++++++++++++--------------------------- App/ui/status.h | 6 ++++- 3 files changed, 35 insertions(+), 56 deletions(-) diff --git a/App/app/foxhunt.c b/App/app/foxhunt.c index f7ca6596..b996d548 100644 --- a/App/app/foxhunt.c +++ b/App/app/foxhunt.c @@ -26,6 +26,8 @@ #include "k5viewer.h" #endif +#include "ui/status.h" + // Signal window mapped onto the RSSI bar, in dBm. // Roughly S0 (empty) to S9 + 40 dB (full), IARU VHF/UHF scale. #define FOXHUNT_DBM_FLOOR (-141) @@ -439,24 +441,6 @@ static void FOXHUNT_DrawRightSmall(const char *s, uint8_t rightX, uint8_t line) UI_PrintStringSmallNormal(s, (uint8_t)(rightX - strlen(s) * 7), 0, line); } -// Battery icon plus the optional voltage/percentage text, top-right of the status -// line — shared by the hunt and beacon screens. -static void FOXHUNT_DrawStatusBattery(void) -{ - unsigned int bx = LCD_WIDTH - sizeof(BITMAP_BatteryLevel1); - UI_DrawBattery(gStatusLine + bx, gBatteryDisplayLevel, gLowBatteryBlink); - if (gSetting_battery_text != 0) { - if (gSetting_battery_text == 1) { // voltage - const uint16_t v = MIN(gBatteryVoltageAverage, 999); - sprintf(str, "%u.%02u", v / 100, v % 100); - } else { // percentage - sprintf(str, "%02u%%", BATTERY_VoltsToPercent(gBatteryVoltageAverage)); - } - bx -= 7 * strlen(str); - UI_PrintStringSmallBufferNormal(str, gStatusLine + bx); - } -} - // Right-aligned frequency on the bottom line (line 6), shared by the hunt and // beacon screens. static void FOXHUNT_DrawFreqBR(uint32_t freq) @@ -472,7 +456,7 @@ static void FOXHUNT_BeaconChrome(void) UI_DisplayClear(); UI_StatusClear(); GUI_DisplaySmallestInverse("BEACON", 2, 0, true, true, 26); - FOXHUNT_DrawStatusBattery(); + UI_DrawStatusBattery(gStatusLine, str); FOXHUNT_DrawFKey(); FOXHUNT_DrawFreqBR(gTxVfo->pTX->Frequency); } @@ -490,7 +474,7 @@ static void FOXHUNT_Draw(void) GUI_DisplaySmallestInverse("FOX HUNT", 2, 0, true, true, 34); // Battery (icon + optional percentage/voltage) top-right, as on the main screens. - FOXHUNT_DrawStatusBattery(); + UI_DrawStatusBattery(gStatusLine, str); FOXHUNT_DrawFKey(); // Gauge-mode icon (2 key), between the label and the audio icon: ascending @@ -571,7 +555,7 @@ static void FOXHUNT_Draw(void) // the burst end, fox at the next repeat), so cycling any of them is safe at any time. // Wrap a 0..count-1 index one step forward (dir > 0) or backward, both ways round. -static uint8_t FOXHUNT_WrapStep(uint8_t v, uint8_t count, int8_t dir) +static __attribute__((noinline)) uint8_t FOXHUNT_WrapStep(uint8_t v, uint8_t count, int8_t dir) { return (uint8_t)((v + (dir > 0 ? 1u : (unsigned)(count - 1u))) % count); } @@ -1317,7 +1301,7 @@ static void FOXHUNT_BeaconTick(void) static uint8_t foxCfgSaved[FOXHUNT_CFG_LEN]; // Pack the live settings into the on-flash layout. -static void FOXHUNT_ConfigPack(uint8_t out[FOXHUNT_CFG_LEN]) +static __attribute__((noinline)) void FOXHUNT_ConfigPack(uint8_t out[FOXHUNT_CFG_LEN]) { out[0] = FOXHUNT_CFG_MAGIC; out[1] = attStep; diff --git a/App/ui/status.c b/App/ui/status.c index 94b2e0f4..e55ad7fe 100644 --- a/App/ui/status.c +++ b/App/ui/status.c @@ -54,6 +54,29 @@ static void convertTime(uint8_t *line, uint8_t type) #endif #endif +#ifdef ENABLE_FEAT_F4HWN_FOXHUNT +void UI_DrawStatusBattery(uint8_t *line, char *str) +#else +static __attribute__((always_inline)) inline void UI_DrawStatusBattery(uint8_t *line, char *str) +#endif +{ + unsigned int x = LCD_WIDTH - sizeof(BITMAP_BatteryLevel1); + + UI_DrawBattery(line + x, gBatteryDisplayLevel, gLowBatteryBlink); + + if (gSetting_battery_text == 1) { + const uint16_t voltage = MIN(gBatteryVoltageAverage, 999); + sprintf(str, "%u.%02u", voltage / 100, voltage % 100); + } else if (gSetting_battery_text == 2) { + sprintf(str, "%02u%%", BATTERY_VoltsToPercent(gBatteryVoltageAverage)); + } else { + return; + } + + x -= 7 * strlen(str); + UI_PrintStringSmallBufferNormal(str, line + x); +} + void UI_DisplayStatus() { gUpdateStatus = false; @@ -314,39 +337,7 @@ void UI_DisplayStatus() memcpy(line + x + 1, src, size); } - // Battery - unsigned int x2 = LCD_WIDTH - sizeof(BITMAP_BatteryLevel1) - 0; - - UI_DrawBattery(line + x2, gBatteryDisplayLevel, gLowBatteryBlink); - - switch (gSetting_battery_text) { - default: - case 0: - break; - - case 1: // voltage - case 2: // percentage - if (gSetting_battery_text == 1) { - const uint16_t voltage = MIN(gBatteryVoltageAverage, 999); // limit to 9.99V - sprintf(str, "%u.%02u", voltage / 100, voltage % 100); - } else { - //gBatteryVoltageAverage = 999; - sprintf(str, "%02u%%", BATTERY_VoltsToPercent(gBatteryVoltageAverage)); - } - - x2 -= (7 * strlen(str)); - UI_PrintStringSmallBufferNormal(str, line + x2); - /* - uint8_t shift = (strlen(str) < 5) ? 92 : 88; - GUI_DisplaySmallest(str, shift, 1, true, true); - - for (uint8_t i = shift - 2; i < 110; i++) { - gStatusLine[i] ^= 0x7F; // invert - } - */ - - break; - } + UI_DrawStatusBattery(line, str); // ************** diff --git a/App/ui/status.h b/App/ui/status.h index ae71d1db..10dd9fe7 100644 --- a/App/ui/status.h +++ b/App/ui/status.h @@ -17,7 +17,11 @@ #ifndef UI_STATUS_H #define UI_STATUS_H +#include + +#ifdef ENABLE_FEAT_F4HWN_FOXHUNT +void UI_DrawStatusBattery(uint8_t *line, char *str); +#endif void UI_DisplayStatus(); #endif -