summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/radio/radio.c39
1 files changed, 20 insertions, 19 deletions
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)
167 return in_screen; 167 return in_screen;
168} 168}
169 169
170/* Keep freq on the grid for the current region */
171int snap_freq_to_grid(int freq)
172{
173 const struct fm_region_data * const fmr =
174 &fm_region_data[global_settings.fm_region];
175
176 /* Range clamp if out of range or just round to nearest */
177 if (freq < fmr->freq_min)
178 freq = fmr->freq_min;
179 else if (freq > fmr->freq_max)
180 freq = fmr->freq_max;
181 else
182 freq = (freq - fmr->freq_min + fmr->freq_step/2) /
183 fmr->freq_step * fmr->freq_step + fmr->freq_min;
184
185 return freq;
186}
187
170/* TODO: Move some more of the control functionality to firmware 188/* TODO: Move some more of the control functionality to firmware
171 and clean up the mess */ 189 and clean up the mess */
172 190
@@ -186,7 +204,8 @@ void radio_start(void)
186 /* clear flag before any yielding */ 204 /* clear flag before any yielding */
187 radio_status &= ~FMRADIO_START_PAUSED; 205 radio_status &= ~FMRADIO_START_PAUSED;
188 206
189 curr_freq = global_status.last_frequency * fmr->freq_step + fmr->freq_min; 207 /* ensure the frequency is in range otherwise bad things happen --Bilgus */
208 curr_freq = snap_freq_to_grid(global_status.last_frequency * fmr->freq_step + fmr->freq_min);
190 209
191 tuner_set(RADIO_SLEEP, 0); /* wake up the tuner */ 210 tuner_set(RADIO_SLEEP, 0); /* wake up the tuner */
192 211
@@ -261,24 +280,6 @@ bool radio_hardware_present(void)
261 return tuner_get(RADIO_PRESENT); 280 return tuner_get(RADIO_PRESENT);
262} 281}
263 282
264/* Keep freq on the grid for the current region */
265int snap_freq_to_grid(int freq)
266{
267 const struct fm_region_data * const fmr =
268 &fm_region_data[global_settings.fm_region];
269
270 /* Range clamp if out of range or just round to nearest */
271 if (freq < fmr->freq_min)
272 freq = fmr->freq_min;
273 else if (freq > fmr->freq_max)
274 freq = fmr->freq_max;
275 else
276 freq = (freq - fmr->freq_min + fmr->freq_step/2) /
277 fmr->freq_step * fmr->freq_step + fmr->freq_min;
278
279 return freq;
280}
281
282void remember_frequency(void) 283void remember_frequency(void)
283{ 284{
284 const struct fm_region_data * const fmr = 285 const struct fm_region_data * const fmr =