0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 06:11:24 +03:00

Frequency enter tidy up

This commit is contained in:
OneOfEleven 2023-09-28 10:17:45 +01:00
parent f55a2b6a6d
commit 86525941bc
5 changed files with 39 additions and 62 deletions

View File

@ -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;
}
}

Binary file not shown.

Binary file not shown.

View File

@ -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)

View File

@ -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,