diff options
Diffstat (limited to 'apps/recorder/radio.c')
-rw-r--r-- | apps/recorder/radio.c | 121 |
1 files changed, 74 insertions, 47 deletions
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index 0ae95053ee..3e45b712b5 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c | |||
@@ -40,11 +40,13 @@ | |||
40 | #include "misc.h" | 40 | #include "misc.h" |
41 | #include "keyboard.h" | 41 | #include "keyboard.h" |
42 | #include "screens.h" | 42 | #include "screens.h" |
43 | #include "peakmeter.h" | ||
44 | #include "lang.h" | ||
43 | 45 | ||
44 | #ifdef HAVE_FMRADIO | 46 | #ifdef HAVE_FMRADIO |
45 | 47 | ||
46 | #define MAX_FREQ (110000000) | 48 | #define MAX_FREQ (108000000) |
47 | #define MIN_FREQ (80000000) | 49 | #define MIN_FREQ (87500000) |
48 | #define PLL_FREQ_STEP 10000 | 50 | #define PLL_FREQ_STEP 10000 |
49 | #define FREQ_STEP 100000 | 51 | #define FREQ_STEP 100000 |
50 | 52 | ||
@@ -110,9 +112,12 @@ bool radio_screen(void) | |||
110 | int search_dir = 0; | 112 | int search_dir = 0; |
111 | int fw, fh; | 113 | int fw, fh; |
112 | 114 | ||
115 | bool update_screen = true; | ||
116 | int timeout = current_tick + HZ/10; | ||
117 | |||
113 | lcd_clear_display(); | 118 | lcd_clear_display(); |
114 | lcd_setmargins(0, 8); | 119 | lcd_setmargins(0, 8); |
115 | status_draw(false); | 120 | status_draw(true); |
116 | fmradio_set_status(FMRADIO_PLAYING); | 121 | fmradio_set_status(FMRADIO_PLAYING); |
117 | lcd_getstringsize("A", &fw, &fh); | 122 | lcd_getstringsize("A", &fw, &fh); |
118 | 123 | ||
@@ -129,6 +134,11 @@ bool radio_screen(void) | |||
129 | radio_set_frequency(curr_freq); | 134 | radio_set_frequency(curr_freq); |
130 | curr_preset = find_preset(curr_freq); | 135 | curr_preset = find_preset(curr_freq); |
131 | 136 | ||
137 | peak_meter_playback(true); | ||
138 | |||
139 | buttonbar_set(str(LANG_BUTTONBAR_MENU), str(LANG_FM_BUTTONBAR_PRESETS), | ||
140 | NULL); | ||
141 | |||
132 | while(!done) | 142 | while(!done) |
133 | { | 143 | { |
134 | if(search_dir) | 144 | if(search_dir) |
@@ -141,19 +151,15 @@ bool radio_screen(void) | |||
141 | 151 | ||
142 | /* Tune in and delay */ | 152 | /* Tune in and delay */ |
143 | radio_set_frequency(curr_freq); | 153 | radio_set_frequency(curr_freq); |
144 | sleep(10); | 154 | sleep(1); |
145 | 155 | ||
146 | /* Start IF measurement */ | 156 | /* Start IF measurement */ |
147 | fmradio_set(1, 0x100006 | pll_cnt << 3); | 157 | fmradio_set(1, 0x100006 | pll_cnt << 3); |
148 | sleep(10); | 158 | sleep(1); |
149 | 159 | ||
150 | /* Now check how close to the IF frequency we are */ | 160 | /* Now check how close to the IF frequency we are */ |
151 | val = fmradio_read(3); | 161 | val = fmradio_read(3); |
152 | i_freq = (val & 0x7ffff) / 80; | 162 | i_freq = (val & 0x7ffff) / 80; |
153 | lcd_puts(0, 5, "Debug data:"); | ||
154 | snprintf(buf, 128, "IF: %d.%dMHz", | ||
155 | i_freq / 100, (i_freq % 100) / 10); | ||
156 | lcd_puts(0, 6, buf); | ||
157 | 163 | ||
158 | /* Stop searching if the IF frequency is close to 10.7MHz */ | 164 | /* Stop searching if the IF frequency is close to 10.7MHz */ |
159 | if(i_freq > 1065 && i_freq < 1075) | 165 | if(i_freq > 1065 && i_freq < 1075) |
@@ -161,33 +167,14 @@ bool radio_screen(void) | |||
161 | search_dir = 0; | 167 | search_dir = 0; |
162 | curr_preset = find_preset(curr_freq); | 168 | curr_preset = find_preset(curr_freq); |
163 | } | 169 | } |
170 | |||
171 | update_screen = true; | ||
164 | } | 172 | } |
165 | 173 | ||
166 | freq = curr_freq / 100000; | ||
167 | snprintf(buf, 128, "Freq: %d.%dMHz", freq / 10, freq % 10); | ||
168 | lcd_puts(0, 2, buf); | ||
169 | |||
170 | val = fmradio_read(3); | ||
171 | stereo = (val & 0x100000)?true:false; | ||
172 | lock = (val & 0x80000)?true:false; | ||
173 | snprintf(buf, 128, "Mode: %s", stereo?"Stereo":"Mono"); | ||
174 | lcd_puts(0, 3, buf); | ||
175 | |||
176 | if(curr_preset >= 0) | ||
177 | { | ||
178 | lcd_puts_scroll(0, 1, presets[curr_preset].name); | ||
179 | } | ||
180 | else | ||
181 | { | ||
182 | lcd_clearrect(0, 8+fh*1, LCD_WIDTH, fh); | ||
183 | } | ||
184 | |||
185 | lcd_update(); | ||
186 | |||
187 | if(search_dir) | 174 | if(search_dir) |
188 | button = button_get(false); | 175 | button = button_get(false); |
189 | else | 176 | else |
190 | button = button_get_w_tmo(HZ/2); | 177 | button = button_get_w_tmo(HZ / peak_meter_fps); |
191 | switch(button) | 178 | switch(button) |
192 | { | 179 | { |
193 | case BUTTON_OFF: | 180 | case BUTTON_OFF: |
@@ -237,7 +224,7 @@ bool radio_screen(void) | |||
237 | if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME)) | 224 | if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME)) |
238 | global_settings.volume = mpeg_sound_max(SOUND_VOLUME); | 225 | global_settings.volume = mpeg_sound_max(SOUND_VOLUME); |
239 | mpeg_sound_set(SOUND_VOLUME, global_settings.volume); | 226 | mpeg_sound_set(SOUND_VOLUME, global_settings.volume); |
240 | status_draw(false); | 227 | update_screen = true; |
241 | settings_save(); | 228 | settings_save(); |
242 | break; | 229 | break; |
243 | 230 | ||
@@ -247,7 +234,7 @@ bool radio_screen(void) | |||
247 | if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME)) | 234 | if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME)) |
248 | global_settings.volume = mpeg_sound_min(SOUND_VOLUME); | 235 | global_settings.volume = mpeg_sound_min(SOUND_VOLUME); |
249 | mpeg_sound_set(SOUND_VOLUME, global_settings.volume); | 236 | mpeg_sound_set(SOUND_VOLUME, global_settings.volume); |
250 | status_draw(false); | 237 | update_screen = true; |
251 | settings_save(); | 238 | settings_save(); |
252 | break; | 239 | break; |
253 | 240 | ||
@@ -256,7 +243,10 @@ bool radio_screen(void) | |||
256 | curr_preset = find_preset(curr_freq); | 243 | curr_preset = find_preset(curr_freq); |
257 | lcd_clear_display(); | 244 | lcd_clear_display(); |
258 | lcd_setmargins(0, 8); | 245 | lcd_setmargins(0, 8); |
259 | status_draw(false); | 246 | buttonbar_set(str(LANG_BUTTONBAR_MENU), |
247 | str(LANG_FM_BUTTONBAR_PRESETS), | ||
248 | NULL); | ||
249 | update_screen = true; | ||
260 | break; | 250 | break; |
261 | 251 | ||
262 | case BUTTON_F2: | 252 | case BUTTON_F2: |
@@ -264,18 +254,56 @@ bool radio_screen(void) | |||
264 | curr_preset = find_preset(curr_freq); | 254 | curr_preset = find_preset(curr_freq); |
265 | lcd_clear_display(); | 255 | lcd_clear_display(); |
266 | lcd_setmargins(0, 8); | 256 | lcd_setmargins(0, 8); |
267 | status_draw(false); | 257 | buttonbar_set(str(LANG_BUTTONBAR_MENU), |
258 | str(LANG_FM_BUTTONBAR_PRESETS), | ||
259 | NULL); | ||
260 | update_screen = true; | ||
268 | break; | 261 | break; |
269 | 262 | ||
270 | case BUTTON_NONE: | ||
271 | status_draw(true); | ||
272 | break; | ||
273 | |||
274 | case SYS_USB_CONNECTED: | 263 | case SYS_USB_CONNECTED: |
275 | usb_screen(); | 264 | usb_screen(); |
276 | fmradio_set_status(0); | 265 | fmradio_set_status(0); |
277 | return true; | 266 | return true; |
278 | } | 267 | } |
268 | |||
269 | peak_meter_peek(); | ||
270 | |||
271 | lcd_clearrect(0, 8 + fh*4, LCD_WIDTH, fh); | ||
272 | peak_meter_draw(0, 8 + fh*4, LCD_WIDTH, fh); | ||
273 | lcd_update_rect(0, 8 + fh*4, LCD_WIDTH, fh); | ||
274 | |||
275 | if(update_screen || TIME_AFTER(current_tick, timeout)) | ||
276 | { | ||
277 | update_screen = false; | ||
278 | |||
279 | timeout = current_tick + HZ/2; | ||
280 | |||
281 | freq = curr_freq / 100000; | ||
282 | snprintf(buf, 128, str(LANG_FM_STATION), freq / 10, freq % 10); | ||
283 | lcd_puts(0, 2, buf); | ||
284 | |||
285 | val = fmradio_read(3); | ||
286 | stereo = (val & 0x100000)?true:false; | ||
287 | lock = (val & 0x80000)?true:false; | ||
288 | snprintf(buf, 128, | ||
289 | stereo?str(LANG_CHANNEL_STEREO):str(LANG_CHANNEL_MONO)); | ||
290 | lcd_puts(0, 3, buf); | ||
291 | |||
292 | if(curr_preset >= 0) | ||
293 | { | ||
294 | lcd_puts_scroll(0, 1, presets[curr_preset].name); | ||
295 | } | ||
296 | else | ||
297 | { | ||
298 | lcd_clearrect(0, 8+fh*1, LCD_WIDTH, fh); | ||
299 | } | ||
300 | |||
301 | status_draw(true); | ||
302 | |||
303 | buttonbar_draw(); | ||
304 | |||
305 | lcd_update(); | ||
306 | } | ||
279 | } | 307 | } |
280 | 308 | ||
281 | fmradio_set_status(0); | 309 | fmradio_set_status(0); |
@@ -321,7 +349,7 @@ void radio_save_presets(void) | |||
321 | } | 349 | } |
322 | else | 350 | else |
323 | { | 351 | { |
324 | splash(HZ*2, 0, true, "Preset save failed"); | 352 | splash(HZ*2, 0, true, str(LANG_FM_PRESET_SAVE_FAILED)); |
325 | } | 353 | } |
326 | } | 354 | } |
327 | 355 | ||
@@ -411,7 +439,7 @@ bool radio_preset_select(void) | |||
411 | } | 439 | } |
412 | else | 440 | else |
413 | { | 441 | { |
414 | splash(HZ*2, 0, true, "No presets"); | 442 | splash(HZ*2, 0, true, str(LANG_FM_NO_PRESETS)); |
415 | } | 443 | } |
416 | } | 444 | } |
417 | 445 | ||
@@ -437,7 +465,7 @@ static bool radio_add_preset(void) | |||
437 | } | 465 | } |
438 | else | 466 | else |
439 | { | 467 | { |
440 | splash(HZ*2, 0, true, "No free preset entries"); | 468 | splash(HZ*2, 0, true, str(LANG_FM_NO_FREE_PRESETS)); |
441 | } | 469 | } |
442 | return true; | 470 | return true; |
443 | } | 471 | } |
@@ -485,13 +513,12 @@ bool radio_delete_preset(void) | |||
485 | return reload_dir; | 513 | return reload_dir; |
486 | } | 514 | } |
487 | 515 | ||
488 | static struct menu_items radio_menu_items[] = { | ||
489 | { "Add preset", radio_add_preset }, | ||
490 | { "Delete preset", radio_delete_preset } | ||
491 | }; | ||
492 | |||
493 | bool radio_menu(void) | 516 | bool radio_menu(void) |
494 | { | 517 | { |
518 | struct menu_items radio_menu_items[] = { | ||
519 | { str(LANG_FM_SAVE_PRESET), radio_add_preset }, | ||
520 | { str(LANG_FM_DELETE_PRESET), radio_delete_preset } | ||
521 | }; | ||
495 | int m; | 522 | int m; |
496 | bool result; | 523 | bool result; |
497 | 524 | ||