Skip to content

Commit

Permalink
Use function table. Simplify logic
Browse files Browse the repository at this point in the history
Size: 60364 -> 60220
  • Loading branch information
JuantAldea committed Dec 25, 2023
1 parent da03d6a commit 162f428
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 45 deletions.
25 changes: 7 additions & 18 deletions am_fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
44 changes: 18 additions & 26 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,36 +409,28 @@ static void HandleReceive(void)
}
}

static void HandleFunction(void)
static void HandlePowerSave()
{
switch (gCurrentFunction)
{
case FUNCTION_FOREGROUND:
CheckForIncoming();
break;

case FUNCTION_TRANSMIT:
break;

case FUNCTION_MONITOR:
break;

case FUNCTION_INCOMING:
HandleIncoming();
break;
if (!gRxIdleMode) {
CheckForIncoming();
}
}

case FUNCTION_RECEIVE:
HandleReceive();
break;
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,
};

case FUNCTION_POWER_SAVE:
if (!gRxIdleMode)
CheckForIncoming();
break;
static_assert(ARRAY_SIZE(HandleFunction_fn_table) == FUNCTION_N_ELEM);

case FUNCTION_BAND_SCOPE:
break;
}
static void HandleFunction(void)
{
HandleFunction_fn_table[gCurrentFunction]();
}

void APP_StartListening(FUNCTION_Type_t function)
Expand Down
1 change: 1 addition & 0 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
case FUNCTION_INCOMING:
case FUNCTION_RECEIVE:
case FUNCTION_BAND_SCOPE:
default:
break;
}

Expand Down
3 changes: 2 additions & 1 deletion functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 162f428

Please sign in to comment.