diff options
Diffstat (limited to 'apps/recorder/radio.c')
-rw-r--r-- | apps/recorder/radio.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index 3dc74cd2ce..ff1d49bd2a 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c | |||
@@ -56,6 +56,7 @@ | |||
56 | #include "textarea.h" | 56 | #include "textarea.h" |
57 | #include "splash.h" | 57 | #include "splash.h" |
58 | #include "yesno.h" | 58 | #include "yesno.h" |
59 | #include "power.h" | ||
59 | 60 | ||
60 | #ifdef CONFIG_TUNER | 61 | #ifdef CONFIG_TUNER |
61 | 62 | ||
@@ -122,6 +123,8 @@ static int curr_preset = -1; | |||
122 | static int curr_freq; | 123 | static int curr_freq; |
123 | static int radio_mode = RADIO_SCAN_MODE; | 124 | static int radio_mode = RADIO_SCAN_MODE; |
124 | 125 | ||
126 | static int radio_status = FMRADIO_OFF; | ||
127 | |||
125 | #define MAX_PRESETS 64 | 128 | #define MAX_PRESETS 64 |
126 | static bool presets_loaded = false; | 129 | static bool presets_loaded = false; |
127 | static struct fmstation presets[MAX_PRESETS]; | 130 | static struct fmstation presets[MAX_PRESETS]; |
@@ -172,21 +175,26 @@ void radio_init(void) | |||
172 | radio_stop(); | 175 | radio_stop(); |
173 | } | 176 | } |
174 | 177 | ||
178 | int get_radio_status(void) | ||
179 | { | ||
180 | return radio_status; | ||
181 | } | ||
182 | |||
175 | void radio_stop(void) | 183 | void radio_stop(void) |
176 | { | 184 | { |
177 | radio_set(RADIO_MUTE, 1); | 185 | radio_set(RADIO_MUTE, 1); |
178 | radio_set(RADIO_SLEEP, 1); /* low power mode, if available */ | 186 | radio_set(RADIO_SLEEP, 1); /* low power mode, if available */ |
179 | radio_set_status(FMRADIO_OFF); /* status update, power off if avail. */ | 187 | radio_status = FMRADIO_OFF; |
188 | radio_power(false); /* status update, power off if avail. */ | ||
180 | } | 189 | } |
181 | 190 | ||
182 | bool radio_hardware_present(void) | 191 | bool radio_hardware_present(void) |
183 | { | 192 | { |
184 | #ifdef HAVE_TUNER_PWR_CTRL | 193 | #ifdef HAVE_TUNER_PWR_CTRL |
185 | bool ret; | 194 | bool ret; |
186 | int fmstatus = radio_get_status(); /* get current state */ | 195 | bool fmstatus = radio_power(true); /* power it up */ |
187 | radio_set_status(FMRADIO_POWERED); /* power it up */ | ||
188 | ret = radio_get(RADIO_PRESENT); | 196 | ret = radio_get(RADIO_PRESENT); |
189 | radio_set_status(fmstatus); /* restore previous state */ | 197 | radio_power(fmstatus); /* restore previous state */ |
190 | return ret; | 198 | return ret; |
191 | #else | 199 | #else |
192 | return radio_get(RADIO_PRESENT); | 200 | return radio_get(RADIO_PRESENT); |
@@ -352,15 +360,16 @@ bool radio_screen(void) | |||
352 | 360 | ||
353 | curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ; | 361 | curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ; |
354 | 362 | ||
355 | if(radio_get_status() == FMRADIO_OFF){ | 363 | if(radio_status != FMRADIO_PLAYING){ |
364 | radio_power(true); | ||
356 | radio_set(RADIO_SLEEP, 0); /* wake up the tuner */ | 365 | radio_set(RADIO_SLEEP, 0); /* wake up the tuner */ |
357 | radio_set(RADIO_FREQUENCY, curr_freq); | 366 | radio_set(RADIO_FREQUENCY, curr_freq); |
358 | radio_set(RADIO_IF_MEASUREMENT, 0); | 367 | radio_set(RADIO_IF_MEASUREMENT, 0); |
359 | radio_set(RADIO_SENSITIVITY, 0); | 368 | radio_set(RADIO_SENSITIVITY, 0); |
360 | radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono); | 369 | radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono); |
361 | radio_set(RADIO_MUTE, 0); | 370 | radio_set(RADIO_MUTE, 0); |
371 | radio_status = FMRADIO_PLAYING; | ||
362 | } | 372 | } |
363 | radio_set_status(FMRADIO_PLAYING); | ||
364 | 373 | ||
365 | curr_preset = find_preset(curr_freq); | 374 | curr_preset = find_preset(curr_freq); |
366 | #ifdef FM_MODE | 375 | #ifdef FM_MODE |
@@ -577,18 +586,18 @@ bool radio_screen(void) | |||
577 | ) | 586 | ) |
578 | break; | 587 | break; |
579 | #endif | 588 | #endif |
580 | if(radio_get_status() != FMRADIO_PLAYING) | 589 | if(radio_status != FMRADIO_PLAYING) |
581 | { | 590 | { |
582 | radio_set(RADIO_SLEEP, 0); | 591 | radio_set(RADIO_SLEEP, 0); |
583 | radio_set(RADIO_FREQUENCY, curr_freq); | 592 | radio_set(RADIO_FREQUENCY, curr_freq); |
584 | radio_set(RADIO_MUTE, 0); | 593 | radio_set(RADIO_MUTE, 0); |
585 | radio_set_status(FMRADIO_PLAYING); | 594 | radio_status = FMRADIO_PLAYING; |
586 | } | 595 | } |
587 | else | 596 | else |
588 | { | 597 | { |
589 | radio_set(RADIO_MUTE, 1); | 598 | radio_set(RADIO_MUTE, 1); |
590 | radio_set(RADIO_SLEEP, 1); | 599 | radio_set(RADIO_SLEEP, 1); |
591 | radio_set_status(FMRADIO_POWERED); | 600 | radio_status = FMRADIO_PAUSED; |
592 | } | 601 | } |
593 | update_screen = true; | 602 | update_screen = true; |
594 | break; | 603 | break; |
@@ -848,7 +857,6 @@ bool radio_screen(void) | |||
848 | sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN); | 857 | sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN); |
849 | mas_codec_writereg(6, 0x4000); | 858 | mas_codec_writereg(6, 0x4000); |
850 | #endif | 859 | #endif |
851 | radio_set_status(FMRADIO_POWERED); /* leave it powered */ | ||
852 | } | 860 | } |
853 | else | 861 | else |
854 | { | 862 | { |
@@ -954,11 +962,13 @@ bool radio_add_preset(void) | |||
954 | buf[27] = 0; | 962 | buf[27] = 0; |
955 | strcpy(presets[num_presets].name, buf); | 963 | strcpy(presets[num_presets].name, buf); |
956 | presets[num_presets].frequency = curr_freq; | 964 | presets[num_presets].frequency = curr_freq; |
965 | #ifdef FM_PRESET_ADD /* only for archos */ | ||
957 | menu_insert(preset_menu, -1, | 966 | menu_insert(preset_menu, -1, |
958 | presets[num_presets].name, 0); | 967 | presets[num_presets].name, 0); |
959 | /* We must still rebuild the menu table, since the | 968 | /* We must still rebuild the menu table, since the |
960 | item name pointers must be updated */ | 969 | item name pointers must be updated */ |
961 | rebuild_preset_menu(); | 970 | rebuild_preset_menu(); |
971 | #endif | ||
962 | num_presets++; | 972 | num_presets++; |
963 | radio_save_presets(); | 973 | radio_save_presets(); |
964 | } | 974 | } |
@@ -1183,11 +1193,10 @@ static bool toggle_mono_mode(void) | |||
1183 | return false; | 1193 | return false; |
1184 | } | 1194 | } |
1185 | 1195 | ||
1186 | |||
1187 | static bool scan_presets(void) | 1196 | static bool scan_presets(void) |
1188 | { | 1197 | { |
1189 | bool tuned = false; | 1198 | bool tuned = false; |
1190 | char buf[32]; | 1199 | char buf[27]; |
1191 | int freq, i; | 1200 | int freq, i; |
1192 | char *lines[]={str(LANG_FM_CLEAR_PRESETS)}; | 1201 | char *lines[]={str(LANG_FM_CLEAR_PRESETS)}; |
1193 | struct text_message message={lines, 1}; | 1202 | struct text_message message={lines, 1}; |
@@ -1202,7 +1211,7 @@ static bool scan_presets(void) | |||
1202 | break; | 1211 | break; |
1203 | 1212 | ||
1204 | freq = curr_freq /100000; | 1213 | freq = curr_freq /100000; |
1205 | snprintf(buf, 32, str(LANG_FM_SCANNING), freq/10, freq % 10); | 1214 | snprintf(buf, 27, str(LANG_FM_SCANNING), freq/10, freq % 10); |
1206 | gui_syncsplash(0, true, buf); | 1215 | gui_syncsplash(0, true, buf); |
1207 | 1216 | ||
1208 | /* Tune in and delay */ | 1217 | /* Tune in and delay */ |
@@ -1218,11 +1227,9 @@ static bool scan_presets(void) | |||
1218 | 1227 | ||
1219 | /* add preset */ | 1228 | /* add preset */ |
1220 | if(tuned){ | 1229 | if(tuned){ |
1221 | snprintf(buf, 32, str(LANG_FM_DEFAULT_PRESET_NAME),freq/10, freq % 10); | 1230 | snprintf(buf, 27, str(LANG_FM_DEFAULT_PRESET_NAME),freq/10, freq % 10); |
1222 | strcpy(presets[num_presets].name, buf); | 1231 | strcpy(presets[num_presets].name,buf); |
1223 | presets[num_presets].frequency = curr_freq; | 1232 | presets[num_presets].frequency = curr_freq; |
1224 | menu_insert(preset_menu, -1, | ||
1225 | presets[num_presets].name, 0); | ||
1226 | num_presets++; | 1233 | num_presets++; |
1227 | } | 1234 | } |
1228 | 1235 | ||
@@ -1230,13 +1237,15 @@ static bool scan_presets(void) | |||
1230 | 1237 | ||
1231 | } | 1238 | } |
1232 | 1239 | ||
1233 | rebuild_preset_menu(); | ||
1234 | radio_save_presets(); | 1240 | radio_save_presets(); |
1235 | 1241 | ||
1236 | if(num_presets > 0 ){ | 1242 | if(num_presets > 0 ){ |
1237 | curr_freq = presets[0].frequency; | 1243 | curr_freq = presets[0].frequency; |
1238 | radio_set(RADIO_FREQUENCY, curr_freq); | 1244 | radio_set(RADIO_FREQUENCY, curr_freq); |
1239 | remember_frequency(); | 1245 | remember_frequency(); |
1246 | #ifdef FM_MODE | ||
1247 | radio_mode = RADIO_PRESET_MODE; | ||
1248 | #endif | ||
1240 | } | 1249 | } |
1241 | } | 1250 | } |
1242 | return true; | 1251 | return true; |