mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
SubGHz: Make sure prev frequency is in list, fix UI desync
This commit is contained in:
@@ -203,6 +203,28 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
||||
size_t preset_count = subghz_setting_get_preset_count(setting);
|
||||
subghz_last_settings_load(subghz->last_settings, preset_count);
|
||||
if(!alloc_for_tx_only) {
|
||||
// Make sure we select a frequency available in loaded setting configuration
|
||||
uint32_t last_frequency = subghz->last_settings->frequency;
|
||||
size_t count = subghz_setting_get_frequency_count(setting);
|
||||
bool found_last = false;
|
||||
bool found_default = false;
|
||||
for(size_t i = 0; i < count; i++) {
|
||||
uint32_t frequency = subghz_setting_get_frequency(setting, i);
|
||||
if(frequency == last_frequency) {
|
||||
found_last = true;
|
||||
break;
|
||||
}
|
||||
if(frequency == SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY) found_default = true;
|
||||
}
|
||||
if(!found_last) {
|
||||
if(found_default) {
|
||||
last_frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY;
|
||||
} else if(count > 0) {
|
||||
last_frequency = subghz_setting_get_frequency(setting, 0);
|
||||
}
|
||||
subghz->last_settings->frequency = last_frequency;
|
||||
}
|
||||
|
||||
subghz_txrx_set_preset_internal(
|
||||
subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index);
|
||||
subghz->history = subghz_history_alloc();
|
||||
|
||||
Reference in New Issue
Block a user