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.
*/
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "am_fix.h"
@@ -72,6 +74,23 @@
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)
{
@@ -1580,8 +1599,6 @@ static void ALARM_Off(void)
}
#endif
static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{
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
}
else if (Key != KEY_SIDE1 && Key != KEY_SIDE2) {
switch (gScreenToDisplay) {
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 if (Key != KEY_SIDE1 && Key != KEY_SIDE2 && gScreenToDisplay != DISPLAY_INVALID) {
ProcessKeysFunctions[gScreenToDisplay](Key, bKeyPressed, bKeyHeld);
}
else
#ifdef ENABLE_AIRCOPY

View File

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

39
ui/ui.c
View File

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