0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-19 06:39:49 +03:00

removed round to step when user enters freq

This commit is contained in:
OneOfEleven
2023-11-04 09:51:01 +00:00
parent d59d4eae15
commit e795b90bf5
8 changed files with 106 additions and 149 deletions

View File

@ -569,33 +569,6 @@ bool APP_start_listening(void)
return true;
}
uint32_t APP_set_frequency_by_step(vfo_info_t *pInfo, int8_t Step)
{
uint32_t Frequency = pInfo->freq_config_rx.frequency + (Step * pInfo->step_freq);
if (pInfo->step_freq == 833)
{
const uint32_t Lower = FREQ_BAND_TABLE[pInfo->channel_attributes.band].lower;
const uint32_t Delta = Frequency - Lower;
uint32_t Base = (Delta / 2500) * 2500;
const uint32_t Index = ((Delta - Base) % 2500) / 833;
if (Index == 2)
Base++;
Frequency = Lower + Base + (Index * 833);
}
// if (Frequency >= FREQ_BAND_TABLE[pInfo->channel_attributes.band].upper)
// Frequency = FREQ_BAND_TABLE[pInfo->channel_attributes.band].lower;
// else
// if (Frequency < FREQ_BAND_TABLE[pInfo->channel_attributes.band].lower)
// Frequency = FREQUENCY_floor_to_step(FREQ_BAND_TABLE[pInfo->channel_attributes.band].upper, pInfo->step_freq, FREQ_BAND_TABLE[pInfo->channel_attributes.band].lower);
Frequency = FREQUENCY_wrap_to_step_band(Frequency, pInfo->step_freq, pInfo->channel_attributes.band);
return Frequency;
}
void APP_stop_scan(void)
{
if (g_scan_state_dir == SCAN_STATE_DIR_OFF)
@ -674,37 +647,40 @@ void APP_stop_scan(void)
static void APP_next_freq(void)
{
frequency_band_t new_band;
const frequency_band_t old_band = FREQUENCY_GetBand(g_rx_vfo->freq_config_rx.frequency);
uint32_t frequency = APP_set_frequency_by_step(g_rx_vfo, g_scan_state_dir);
g_rx_vfo->freq_config_rx.frequency = frequency;
uint32_t freq = g_rx_vfo->freq_config_rx.frequency;
const uint32_t step = g_rx_vfo->step_freq;
const frequency_band_t band = FREQUENCY_GetBand(freq);
const uint32_t upper = FREQ_BAND_TABLE[band].upper;
const uint32_t lower = FREQ_BAND_TABLE[band].lower;
#ifdef ENABLE_SCAN_IGNORE_LIST
while (FI_freq_ignored(frequency) >= 0)
{
uint32_t next_frequency;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf("skipping %u\r\n", frequency);
#endif
next_frequency = APP_set_frequency_by_step(g_rx_vfo, g_scan_state_dir); // skip to next frequency
if (frequency == next_frequency)
break;
frequency = next_frequency;
g_rx_vfo->freq_config_rx.frequency = frequency;
}
do {
#endif
freq += step * g_scan_state_dir;
new_band = FREQUENCY_GetBand(frequency);
// wrap-a-round
while (freq >= upper)
freq -= upper - lower;
while (freq < lower)
freq += upper - lower;
if (band == BAND2_108MHz) // air band uses set channels
freq = lower + ((((freq - lower) + (step / 2)) / step) * step);
#ifdef ENABLE_SCAN_IGNORE_LIST
} while (FI_freq_ignored(freq) >= 0);
#endif
g_rx_vfo->freq_in_channel = 0xff;
g_rx_vfo->freq_config_rx.frequency = freq;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf("APP_next_freq %u %u\r\n", frequency, new_band);
// UART_printf("APP_next_freq %u %u\r\n", freq, new_band);
#endif
if (new_band != old_band)
{ // original slower method
#if 0
// original slower method
RADIO_ApplyOffset(g_rx_vfo, false);
RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo);
@ -716,20 +692,23 @@ static void APP_next_freq(void)
#else
g_scan_pause_tick_10ms = scan_pause_freq_10ms;
#endif
}
else
{ // don't need to go through all the other stuff .. lets speed things up !!
BK4819_set_rf_frequency(frequency, true);
BK4819_set_rf_filter_path(frequency);
#else
// don't need to go through all the other stuff .. speed things up !!
// RADIO_ApplyOffset(g_rx_vfo, false);
BK4819_set_rf_frequency(g_rx_vfo->freq_config_rx.frequency, true);
BK4819_set_rf_filter_path(g_rx_vfo->freq_config_rx.frequency);
#ifdef ENABLE_FASTER_CHANNEL_SCAN
// g_scan_pause_tick_10ms = 10; // 100ms
//g_scan_pause_tick_10ms = 10; // 100ms
g_scan_pause_tick_10ms = 6; // 60ms
#else
g_scan_pause_tick_10ms = scan_pause_freq_10ms;
#endif
}
#endif
g_scan_pause_time_mode = false;
g_update_display = true;

View File

@ -32,7 +32,6 @@ void APP_end_tx(void);
void APP_stop_scan(void);
void APP_channel_next(const bool remember_current, const scan_state_dir_t scan_direction);
bool APP_start_listening(void);
uint32_t APP_set_frequency_by_step(vfo_info_t *pInfo, int8_t Step);
void APP_time_slice_10ms(void);
void APP_time_slice_500ms(void);

View File

@ -577,8 +577,10 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
RADIO_configure_channel(vfo, VFO_CONFIGURE_RELOAD);
}
Frequency += g_tx_vfo->step_freq / 2; // for rounding to nearest step size
Frequency = FREQUENCY_floor_to_step(Frequency, g_tx_vfo->step_freq, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].lower, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].upper);
#if 0
Frequency += g_tx_vfo->step_freq / 2; // for rounding to nearest step size
Frequency = FREQUENCY_floor_to_step(Frequency, g_tx_vfo->step_freq, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].lower, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].upper);
#endif
if (Frequency >= BX4819_BAND1.upper && Frequency < BX4819_BAND2.lower)
{ // clamp the frequency to the limit
@ -875,7 +877,7 @@ void MAIN_Key_STAR(bool key_pressed, bool key_held)
g_update_status = true;
}
void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Direction)
void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t direction)
{
#ifdef ENABLE_SQ_OPEN_WITH_UP_DN_BUTTS
static bool monitor_was_enabled = false;
@ -904,17 +906,18 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
}
#endif
g_tx_vfo->freq_config_tx.frequency = g_tx_vfo->freq_config_rx.frequency;
g_rx_vfo->freq_config_tx.frequency = g_rx_vfo->freq_config_rx.frequency;
// find the first channel that contains this frequency
g_tx_vfo->freq_in_channel = SETTINGS_find_channel(g_tx_vfo->freq_config_rx.frequency);
g_rx_vfo->freq_in_channel = SETTINGS_find_channel(g_rx_vfo->freq_config_rx.frequency);
SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, 1);
// SETTINGS_save_channel(g_rx_vfo->channel_save, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, 1);
SETTINGS_save_channel(g_rx_vfo->channel_save, g_rx_vfo_num, g_rx_vfo, 1);
RADIO_ApplyOffset(g_tx_vfo, true);
RADIO_ApplyOffset(g_rx_vfo, true);
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf("save chan %u\r\n", g_tx_vfo->channel_save);
// UART_printf("save chan %u\r\n", g_rx_vfo->channel_save);
#endif
}
@ -964,43 +967,46 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
if (IS_FREQ_CHANNEL(Channel))
{ // frequency mode
frequency_band_t new_band;
const frequency_band_t old_band = FREQUENCY_GetBand(g_tx_vfo->freq_config_rx.frequency);
const uint32_t frequency = APP_set_frequency_by_step(g_tx_vfo, Direction);
uint32_t freq = g_rx_vfo->freq_config_rx.frequency;
const uint32_t step = g_rx_vfo->step_freq;
const frequency_band_t band = FREQUENCY_GetBand(freq);
const uint32_t upper = FREQ_BAND_TABLE[band].upper;
const uint32_t lower = FREQ_BAND_TABLE[band].lower;
freq += step * direction;
if (FREQUENCY_rx_freq_check(frequency) < 0)
// wrap-a-round
while (freq >= upper)
freq -= upper - lower;
while (freq < lower)
freq += upper - lower;
if (band == BAND2_108MHz) // air band uses set channels. so round to those channels
freq = lower + ((((freq - lower) + (step / 2)) / step) * step);
if (FREQUENCY_rx_freq_check(freq) < 0)
{ // frequency not allowed
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
// compute the frequency band for the frequency
new_band = FREQUENCY_GetBand(frequency);
g_rx_vfo->freq_config_rx.frequency = freq;
// save the new frequency into the VFO
g_tx_vfo->freq_config_rx.frequency = frequency;
g_tx_vfo->freq_config_tx.frequency = frequency;
RADIO_ApplyOffset(g_rx_vfo, false);
// find the first channel that contains this frequency
//
// this currently takes to long to look through all the channels (200)
// with every frequency step, because we have to read each channel from eeprom
// before checking the channels frequency
//
// TODO: include this once we have the entire eeprom loaded
// find the first channel that contains this frequency .. currently takes too long
//
//if (!key_held && key_pressed)
// g_tx_vfo->freq_in_channel = SETTINGS_find_channel(frequency);
// g_rx_vfo->freq_in_channel = SETTINGS_find_channel(freq);
//else
//if (key_held && key_pressed)
g_tx_vfo->freq_in_channel = 0xff;
g_rx_vfo->freq_in_channel = 0xff;
if (new_band != old_band)
{ // original slow method
#if 0
// original slow method
g_request_save_channel = 1;
}
else
{ // don't need to go through all the other stuff
#else
// don't need to go through all the other stuff
// lets speed things up by simply setting the VCO/PLL frequency
// and the RF filter path (LNA and PA)
@ -1017,9 +1023,9 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
}
#endif
BK4819_set_rf_frequency(frequency, true); // set the VCO/PLL
BK4819_set_rf_filter_path(frequency); // set the proper LNA/PA filter path
}
BK4819_set_rf_frequency(freq, true); // set the VCO/PLL
BK4819_set_rf_filter_path(freq); // set the proper LNA/PA filter path
#endif
return;
}
@ -1028,7 +1034,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
g_tx_vfo->freq_in_channel = 0xff;
Next = RADIO_FindNextChannel(Channel + Direction, Direction, false, 0);
Next = RADIO_FindNextChannel(Channel + direction, direction, false, 0);
if (Next == 0xFF)
return;
@ -1048,7 +1054,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
}
#endif
g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user = Next;
g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user = Next;
g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].screen = Next;
if (!key_held)
@ -1079,7 +1085,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
// jump to the next channel
APP_channel_next(false, Direction);
APP_channel_next(false, direction);
// go NOW
g_scan_pause_tick_10ms = 0;