Use function table. Simplify logic

Size: 60364 -> 60220
This commit is contained in:
Juan Antonio 2023-12-25 01:11:43 +01:00 committed by egzumer
parent 7a7010da55
commit cbf4a7c140
4 changed files with 30 additions and 47 deletions

View File

@ -140,8 +140,8 @@ static const t_gain_table gain_table[] =
{0x03BF,-4}, // 40 .. 3 5 3 7 .. 0dB -4dB 0dB 0dB .. -4dB
{0x03DF,-2}, // 41 .. 3 6 3 7 .. 0dB - 2dB 0dB 0dB .. -2dB
{0x03FF,0} // 42 .. 3 7 3 7 .. 0dB 0dB 0dB 0dB .. 0dB
};
const uint8_t gain_table_size = ARRAY_SIZE(gain_table);
#else
@ -260,22 +260,11 @@ void AM_fix_10ms(const unsigned vfo)
if(!gSetting_AM_fix || !enabled || vfo > 1 )
return;
switch (gCurrentFunction)
{
case FUNCTION_TRANSMIT:
case FUNCTION_BAND_SCOPE:
case FUNCTION_POWER_SAVE:
if (gCurrentFunction != FUNCTION_FOREGROUND && !FUNCTION_IsRx()) {
#ifdef ENABLE_AM_FIX_SHOW_DATA
counter = display_update_rate; // queue up a display update as soon as we switch to RX mode
counter = display_update_rate; // queue up a display update as soon as we switch to RX mode
#endif
return;
// only adjust stuff if we're in one of these modes
case FUNCTION_FOREGROUND:
case FUNCTION_RECEIVE:
case FUNCTION_MONITOR:
case FUNCTION_INCOMING:
break;
return;
}
#ifdef ENABLE_AM_FIX_SHOW_DATA

View File

@ -409,36 +409,28 @@ Skip:
}
}
static void HandlePowerSave()
{
if (!gRxIdleMode) {
CheckForIncoming();
}
}
static void (*HandleFunction_fn_table[])(void) = {
[FUNCTION_FOREGROUND] = &CheckForIncoming,
[FUNCTION_TRANSMIT] = &FUNCTION_NOP,
[FUNCTION_MONITOR] = &FUNCTION_NOP,
[FUNCTION_INCOMING] = &HandleIncoming,
[FUNCTION_RECEIVE] = &HandleReceive,
[FUNCTION_POWER_SAVE] = &HandlePowerSave,
[FUNCTION_BAND_SCOPE] = &FUNCTION_NOP,
};
static_assert(ARRAY_SIZE(HandleFunction_fn_table) == FUNCTION_N_ELEM);
static void HandleFunction(void)
{
switch (gCurrentFunction)
{
case FUNCTION_FOREGROUND:
CheckForIncoming();
break;
case FUNCTION_TRANSMIT:
break;
case FUNCTION_MONITOR:
break;
case FUNCTION_INCOMING:
HandleIncoming();
break;
case FUNCTION_RECEIVE:
HandleReceive();
break;
case FUNCTION_POWER_SAVE:
if (!gRxIdleMode)
CheckForIncoming();
break;
case FUNCTION_BAND_SCOPE:
break;
}
HandleFunction_fn_table[gCurrentFunction]();
}
void APP_StartListening(FUNCTION_Type_t function)

View File

@ -261,6 +261,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
case FUNCTION_INCOMING:
case FUNCTION_RECEIVE:
case FUNCTION_BAND_SCOPE:
default:
break;
}

View File

@ -27,7 +27,8 @@ enum FUNCTION_Type_t
FUNCTION_INCOMING, // receiving a signal (squelch is open)
FUNCTION_RECEIVE, // RX mode, squelch closed
FUNCTION_POWER_SAVE, // sleeping
FUNCTION_BAND_SCOPE // bandscope mode (panadpter/spectrum) .. not yet implemented
FUNCTION_BAND_SCOPE, // bandscope mode (panadpter/spectrum) .. not yet implemented
FUNCTION_N_ELEM
};
typedef enum FUNCTION_Type_t FUNCTION_Type_t;