From 30482bd9087444c434ee4c4cc1756ca9a402f5ad Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Mon, 6 May 2024 10:28:27 -0400 Subject: [BugFix] Radio make sure resume frequency is in range out of range frequencies hang the device (clip zip, others?) Change-Id: I0d3af83a05479f70a958168f57c8cc305195b06b --- apps/radio/radio.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'apps/radio') diff --git a/apps/radio/radio.c b/apps/radio/radio.c index bf8ad865dd..bf36f1d32d 100644 --- a/apps/radio/radio.c +++ b/apps/radio/radio.c @@ -167,6 +167,24 @@ bool in_radio_screen(void) return in_screen; } +/* Keep freq on the grid for the current region */ +int snap_freq_to_grid(int freq) +{ + const struct fm_region_data * const fmr = + &fm_region_data[global_settings.fm_region]; + + /* Range clamp if out of range or just round to nearest */ + if (freq < fmr->freq_min) + freq = fmr->freq_min; + else if (freq > fmr->freq_max) + freq = fmr->freq_max; + else + freq = (freq - fmr->freq_min + fmr->freq_step/2) / + fmr->freq_step * fmr->freq_step + fmr->freq_min; + + return freq; +} + /* TODO: Move some more of the control functionality to firmware and clean up the mess */ @@ -186,7 +204,8 @@ void radio_start(void) /* clear flag before any yielding */ radio_status &= ~FMRADIO_START_PAUSED; - curr_freq = global_status.last_frequency * fmr->freq_step + fmr->freq_min; + /* ensure the frequency is in range otherwise bad things happen --Bilgus */ + curr_freq = snap_freq_to_grid(global_status.last_frequency * fmr->freq_step + fmr->freq_min); tuner_set(RADIO_SLEEP, 0); /* wake up the tuner */ @@ -261,24 +280,6 @@ bool radio_hardware_present(void) return tuner_get(RADIO_PRESENT); } -/* Keep freq on the grid for the current region */ -int snap_freq_to_grid(int freq) -{ - const struct fm_region_data * const fmr = - &fm_region_data[global_settings.fm_region]; - - /* Range clamp if out of range or just round to nearest */ - if (freq < fmr->freq_min) - freq = fmr->freq_min; - else if (freq > fmr->freq_max) - freq = fmr->freq_max; - else - freq = (freq - fmr->freq_min + fmr->freq_step/2) / - fmr->freq_step * fmr->freq_step + fmr->freq_min; - - return freq; -} - void remember_frequency(void) { const struct fm_region_data * const fmr = -- cgit v1.2.3