diff --git a/am_fix.c b/am_fix.c index 63203da..838b332 100644 --- a/am_fix.c +++ b/am_fix.c @@ -120,7 +120,7 @@ static const t_gain_table gain_table[] = {0x003E,-50}, // 20 .. 0 1 3 6 .. -28dB -19dB 0dB -3dB .. -50dB {0x003F,-47}, // 21 .. 0 1 3 7 .. -28dB -19dB 0dB 0dB .. -47dB {0x005E,-45}, // 22 .. 0 2 3 6 .. -28dB -14dB 0dB -3dB .. -45dB - {0x005F,-42}, // 23 .. 0 2 3 7 .. -28dB -14dB 0dB 0dB .. -42dB + {0x005F,-42}, // 23 .. 0 2 3 7 .. -28dB -14dB 0dB 0dB .. -42dB {0x007E,-40}, // 24 .. 0 3 3 6 .. -28dB -9dB 0dB -3dB .. -40dB {0x007F,-37}, // 25 .. 0 3 3 7 .. -28dB -9dB 0dB 0dB .. -37dB {0x009F,-34}, // 26 .. 0 4 3 7 .. -28dB -6dB 0dB 0dB .. -34dB @@ -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 @@ -304,11 +293,11 @@ void AM_fix_10ms(const unsigned vfo) #ifdef ENABLE_AM_FIX_SHOW_DATA { static int16_t lastRssi; - + if (lastRssi != rssi) { // rssi changed lastRssi = rssi; - if (counter == 0) { + if (counter == 0) { counter = 1; gUpdateDisplay = true; // trigger a display update } diff --git a/app/app.c b/app/app.c index 4c08fca..5643680 100644 --- a/app/app.c +++ b/app/app.c @@ -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) diff --git a/functions.c b/functions.c index b72641d..54875f1 100644 --- a/functions.c +++ b/functions.c @@ -261,6 +261,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function) case FUNCTION_INCOMING: case FUNCTION_RECEIVE: case FUNCTION_BAND_SCOPE: + default: break; } diff --git a/functions.h b/functions.h index 12c72cc..bfec351 100644 --- a/functions.h +++ b/functions.h @@ -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;