Drop gScreenToDisplay switch and use function table

Saves some bytes
This commit is contained in:
Juan Antonio
2023-12-08 16:51:50 +01:00
committed by egzumer
parent 1203fdf0ca
commit 4322a7d8a9
4 changed files with 204 additions and 202 deletions

View File

@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include <assert.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include "am_fix.h" #include "am_fix.h"
@@ -72,6 +74,23 @@
static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
void (*ProcessKeysFunctions[])(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) = {
[DISPLAY_MAIN] = &MAIN_ProcessKeys,
[DISPLAY_MENU] = &MENU_ProcessKeys,
[DISPLAY_SCANNER] = &SCANNER_ProcessKeys,
#ifdef ENABLE_FMRADIO
[DISPLAY_FM] = &FM_ProcessKeys,
#endif
#ifdef ENABLE_AIRCOPY
[DISPLAY_AIRCOPY] = &AIRCOPY_ProcessKeys,
#endif
};
static_assert(ARRAY_SIZE(ProcessKeysFunctions) == DISPLAY_N_ELEM);
static void CheckForIncoming(void) static void CheckForIncoming(void)
{ {
@@ -1580,8 +1599,6 @@ static void ALARM_Off(void)
} }
#endif #endif
static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{ {
if (Key == KEY_EXIT && !BACKLIGHT_IsOn() && gEeprom.BACKLIGHT_TIME > 0) if (Key == KEY_EXIT && !BACKLIGHT_IsOn() && gEeprom.BACKLIGHT_TIME > 0)
@@ -1849,33 +1866,8 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
} }
#endif #endif
} }
else if (Key != KEY_SIDE1 && Key != KEY_SIDE2) { else if (Key != KEY_SIDE1 && Key != KEY_SIDE2 && gScreenToDisplay != DISPLAY_INVALID) {
switch (gScreenToDisplay) { ProcessKeysFunctions[gScreenToDisplay](Key, bKeyPressed, bKeyHeld);
case DISPLAY_MAIN:
MAIN_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
#ifdef ENABLE_FMRADIO
case DISPLAY_FM:
FM_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
#endif
case DISPLAY_MENU:
MENU_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
case DISPLAY_SCANNER:
SCANNER_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
#ifdef ENABLE_AIRCOPY
case DISPLAY_AIRCOPY:
AIRCOPY_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
#endif
case DISPLAY_INVALID:
default:
break;
}
} }
else else
#ifdef ENABLE_AIRCOPY #ifdef ENABLE_AIRCOPY

View File

@@ -92,36 +92,19 @@ void FUNCTION_Init(void)
gUpdateStatus = true; gUpdateStatus = true;
} }
void FUNCTION_Select(FUNCTION_Type_t Function) void FUNCTION_Foreground(const FUNCTION_Type_t PreviousFunction)
{ {
const FUNCTION_Type_t PreviousFunction = gCurrentFunction;
const bool bWasPowerSave = (PreviousFunction == FUNCTION_POWER_SAVE);
gCurrentFunction = Function;
if (bWasPowerSave && Function != FUNCTION_POWER_SAVE)
{
BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable();
gRxIdleMode = false;
UI_DisplayStatus();
}
switch (Function)
{
case FUNCTION_FOREGROUND:
#ifdef ENABLE_DTMF_CALLING #ifdef ENABLE_DTMF_CALLING
if (gDTMF_ReplyState != DTMF_REPLY_NONE) if (gDTMF_ReplyState != DTMF_REPLY_NONE)
RADIO_PrepareCssTX(); RADIO_PrepareCssTX();
#endif #endif
if (PreviousFunction == FUNCTION_TRANSMIT) if (PreviousFunction == FUNCTION_TRANSMIT) {
{
ST7565_FixInterfGlitch(); ST7565_FixInterfGlitch();
gVFO_RSSI_bar_level[0] = 0; gVFO_RSSI_bar_level[0] = 0;
gVFO_RSSI_bar_level[1] = 0; gVFO_RSSI_bar_level[1] = 0;
} else if (PreviousFunction != FUNCTION_RECEIVE) {
return;
} }
else
if (PreviousFunction != FUNCTION_RECEIVE)
break;
#if defined(ENABLE_FMRADIO) #if defined(ENABLE_FMRADIO)
if (gFmRadioMode) if (gFmRadioMode)
@@ -137,17 +120,9 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
} }
#endif #endif
gUpdateStatus = true; gUpdateStatus = true;
return; }
case FUNCTION_MONITOR: void FUNCTION_PowerSave() {
gMonitor = true;
break;
case FUNCTION_INCOMING:
case FUNCTION_RECEIVE:
break;
case FUNCTION_POWER_SAVE:
gPowerSave_10ms = gEeprom.BATTERY_SAVE * 10; gPowerSave_10ms = gEeprom.BATTERY_SAVE * 10;
gPowerSaveCountdownExpired = false; gPowerSaveCountdownExpired = false;
@@ -164,11 +139,10 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu
GUI_SelectNextDisplay(DISPLAY_MAIN); GUI_SelectNextDisplay(DISPLAY_MAIN);
}
return; void FUNCTION_Transmit()
{
case FUNCTION_TRANSMIT:
// if DTMF is enabled when TX'ing, it changes the TX audio filtering !! .. 1of11 // if DTMF is enabled when TX'ing, it changes the TX audio filtering !! .. 1of11
BK4819_DisableDTMF(); BK4819_DisableDTMF();
@@ -206,7 +180,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
BK4819_ExitTxMute(); BK4819_ExitTxMute();
gAlarmToneCounter = 0; gAlarmToneCounter = 0;
break; return;
} }
#endif #endif
@@ -242,7 +216,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
AUDIO_AudioPathOn(); AUDIO_AudioPathOn();
gEnableSpeaker = true; gEnableSpeaker = true;
break; return;
} }
#endif #endif
@@ -254,9 +228,44 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
if (gSetting_backlight_on_tx_rx & BACKLIGHT_ON_TR_TX) { if (gSetting_backlight_on_tx_rx & BACKLIGHT_ON_TR_TX) {
BACKLIGHT_TurnOn(); BACKLIGHT_TurnOn();
} }
}
void FUNCTION_Select(FUNCTION_Type_t Function)
{
const FUNCTION_Type_t PreviousFunction = gCurrentFunction;
const bool bWasPowerSave = PreviousFunction == FUNCTION_POWER_SAVE;
gCurrentFunction = Function;
if (bWasPowerSave && Function != FUNCTION_POWER_SAVE)
{
BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable();
gRxIdleMode = false;
UI_DisplayStatus();
}
switch (Function)
{
case FUNCTION_FOREGROUND:
FUNCTION_Foreground(PreviousFunction);
return;
case FUNCTION_POWER_SAVE:
FUNCTION_PowerSave();
return;
case FUNCTION_TRANSMIT:
FUNCTION_Transmit();
break; break;
case FUNCTION_MONITOR:
gMonitor = true;
break;
case FUNCTION_INCOMING:
case FUNCTION_RECEIVE:
case FUNCTION_BAND_SCOPE: case FUNCTION_BAND_SCOPE:
break; break;
} }

39
ui/ui.c
View File

@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include <assert.h>
#include <string.h> #include <string.h>
#include "app/chFrScanner.h" #include "app/chFrScanner.h"
@@ -34,6 +35,7 @@
#include "ui/menu.h" #include "ui/menu.h"
#include "ui/scanner.h" #include "ui/scanner.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "../misc.h"
GUI_DisplayType_t gScreenToDisplay; GUI_DisplayType_t gScreenToDisplay;
GUI_DisplayType_t gRequestDisplayScreen = DISPLAY_INVALID; GUI_DisplayType_t gRequestDisplayScreen = DISPLAY_INVALID;
@@ -42,36 +44,27 @@ uint8_t gAskForConfirmation;
bool gAskToSave; bool gAskToSave;
bool gAskToDelete; bool gAskToDelete;
void GUI_DisplayScreen(void)
{ void (*UI_DisplayFunctions[])(void) = {
switch (gScreenToDisplay) [DISPLAY_MAIN] = &UI_DisplayMain,
{ [DISPLAY_MENU] = &UI_DisplayMenu,
case DISPLAY_MAIN: [DISPLAY_SCANNER] = &UI_DisplayScanner,
UI_DisplayMain();
break;
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
case DISPLAY_FM: [DISPLAY_FM] = &UI_DisplayFM,
UI_DisplayFM();
break;
#endif #endif
case DISPLAY_MENU:
UI_DisplayMenu();
break;
case DISPLAY_SCANNER:
UI_DisplayScanner();
break;
#ifdef ENABLE_AIRCOPY #ifdef ENABLE_AIRCOPY
case DISPLAY_AIRCOPY: [DISPLAY_AIRCOPY] = &UI_DisplayAircopy,
UI_DisplayAircopy();
break;
#endif #endif
};
default: static_assert(ARRAY_SIZE(UI_DisplayFunctions) == DISPLAY_N_ELEM);
break;
void GUI_DisplayScreen(void)
{
if (gScreenToDisplay != DISPLAY_INVALID) {
UI_DisplayFunctions[gScreenToDisplay]();
} }
} }

10
ui/ui.h
View File

@@ -23,10 +23,18 @@
enum GUI_DisplayType_t enum GUI_DisplayType_t
{ {
DISPLAY_MAIN = 0, DISPLAY_MAIN = 0,
DISPLAY_FM,
DISPLAY_MENU, DISPLAY_MENU,
DISPLAY_SCANNER, DISPLAY_SCANNER,
#ifdef ENABLE_FMRADIO
DISPLAY_FM,
#endif
#ifdef ENABLE_AIRCOPY
DISPLAY_AIRCOPY, DISPLAY_AIRCOPY,
#endif
DISPLAY_N_ELEM,
DISPLAY_INVALID = 0xFFu DISPLAY_INVALID = 0xFFu
}; };