diff --git a/app/main.c b/app/main.c index 6f00065..2b2aa6b 100644 --- a/app/main.c +++ b/app/main.c @@ -351,9 +351,9 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } else if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz) - { // move the frequency to the closest limit + { const uint32_t center = (bx_stop1_Hz + bx_start2_Hz) / 2; - Frequency = (Frequency < center) ? bx_stop1_Hz - 10 : bx_start2_Hz; + Frequency = (Frequency < center) ? bx_stop1_Hz : bx_start2_Hz; } else if (Frequency > UpperLimitFrequencyBandTable[6]) @@ -362,46 +362,38 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } { - unsigned int i; - for (i = 0; i < 7; i++) + const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency); + + #ifdef ENABLE_VOICE + gAnotherVoiceID = (VOICE_ID_t)Key; + #endif + + if (gTxVfo->Band != band) { - if (Frequency >= LowerLimitFrequencyBandTable[i] && Frequency <= UpperLimitFrequencyBandTable[i]) - { - #ifdef ENABLE_VOICE - gAnotherVoiceID = (VOICE_ID_t)Key; - #endif - - if (gTxVfo->Band != i) - { - gTxVfo->Band = i; - gEeprom.ScreenChannel[Vfo] = i + FREQ_CHANNEL_FIRST; - gEeprom.FreqChannel[Vfo] = i + FREQ_CHANNEL_FIRST; - - SETTINGS_SaveVfoIndices(); - - RADIO_ConfigureChannel(Vfo, 2); - } - -// Frequency += 75; // is this for rounding - Frequency += gTxVfo->StepFrequency / 2; // this is though - - Frequency = FREQUENCY_FloorToStep(Frequency, gTxVfo->StepFrequency, LowerLimitFrequencyBandTable[gTxVfo->Band]); - - // clamp the frequency entered to some valid value - - if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz) - { // use the step size to properly limit the frequency - const uint32_t center = (bx_stop1_Hz + bx_start2_Hz) / 2; - Frequency = (Frequency < center) ? bx_stop1_Hz - gTxVfo->StepFrequency : bx_start2_Hz; - } - - gTxVfo->freq_config_RX.Frequency = Frequency; - - gRequestSaveChannel = 1; - return; - } + gTxVfo->Band = band; + gEeprom.ScreenChannel[Vfo] = band + FREQ_CHANNEL_FIRST; + gEeprom.FreqChannel[Vfo] = band + FREQ_CHANNEL_FIRST; + + SETTINGS_SaveVfoIndices(); + + RADIO_ConfigureChannel(Vfo, 2); } - + +// Frequency += 75; // is this meant to be rounding to step size? + Frequency += gTxVfo->StepFrequency / 2; // no idea, but this is + + Frequency = FREQUENCY_FloorToStep(Frequency, gTxVfo->StepFrequency, LowerLimitFrequencyBandTable[gTxVfo->Band]); + + if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz) + { // clamp the frequency to the limit + const uint32_t center = (bx_stop1_Hz + bx_start2_Hz) / 2; + Frequency = (Frequency < center) ? bx_stop1_Hz - gTxVfo->StepFrequency : bx_start2_Hz; + } + + gTxVfo->freq_config_RX.Frequency = Frequency; + + gRequestSaveChannel = 1; + return; } } diff --git a/firmware.bin b/firmware.bin index 1e5989f..8c42281 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 75d3bec..d6d0d2f 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/frequencies.c b/frequencies.c index f6d3df4..57460c1 100644 --- a/frequencies.c +++ b/frequencies.c @@ -110,27 +110,11 @@ const uint32_t UpperLimitFrequencyBandTable[7] = FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency) { -// if (Frequency >= 60000000 && Frequency <= bx_max_Hz) -// return BAND7_470MHz; - if (Frequency >= 47000000) - return BAND7_470MHz; - if (Frequency >= 40000000) - return BAND6_400MHz; - if (Frequency >= 35000000) - return BAND5_350MHz; - if (Frequency >= 17400000) - return BAND4_174MHz; - if (Frequency >= 13600000) - return BAND3_136MHz; - if (Frequency >= 10800000) - return BAND2_108MHz; - if (Frequency >= 5000000) - return BAND1_50MHz; -// if (Frequency >= bx_min_Hz) - return BAND1_50MHz; - - // TODO: Double check the assembly -// return BAND6_400MHz; + int band; + for (band = BAND7_470MHz; band >= BAND1_50MHz; band--) + if (Frequency >= LowerLimitFrequencyBandTable[band]) + return band; + return BAND1_50MHz; } uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency) diff --git a/frequencies.h b/frequencies.h index fa8a474..168936f 100644 --- a/frequencies.h +++ b/frequencies.h @@ -29,7 +29,8 @@ extern const uint32_t bx_stop2_Hz; enum FREQUENCY_Band_t { - BAND1_50MHz = 0, + BAND1_NONE = -1, + BAND1_50MHz = 0, BAND2_108MHz, BAND3_136MHz, BAND4_174MHz,