diff options
author | Anton Oleynikov <len0x@rockbox.org> | 2005-11-19 19:23:44 +0000 |
---|---|---|
committer | Anton Oleynikov <len0x@rockbox.org> | 2005-11-19 19:23:44 +0000 |
commit | c94557e0b9415fdfe31154b75d320bf2ebd39168 (patch) | |
tree | 336234e1f3f3b09edcd047c19d5b1d4dccf54654 | |
parent | a51a5b711db09848ca9c569d2975ff8217a17261 (diff) | |
download | rockbox-c94557e0b9415fdfe31154b75d320bf2ebd39168.tar.gz rockbox-c94557e0b9415fdfe31154b75d320bf2ebd39168.zip |
refactored radio status code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7999 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/playback.c | 3 | ||||
-rw-r--r-- | apps/recorder/radio.c | 45 | ||||
-rw-r--r-- | apps/recorder/radio.h | 5 | ||||
-rw-r--r-- | firmware/drivers/power.c | 18 | ||||
-rw-r--r-- | firmware/export/power.h | 8 | ||||
-rw-r--r-- | firmware/powermgmt.c | 2 |
6 files changed, 46 insertions, 35 deletions
diff --git a/apps/playback.c b/apps/playback.c index d895716359..b662d0329b 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -61,7 +61,6 @@ | |||
61 | #include "talk.h" | 61 | #include "talk.h" |
62 | #ifdef CONFIG_TUNER | 62 | #ifdef CONFIG_TUNER |
63 | #include "radio.h" | 63 | #include "radio.h" |
64 | #include "power.h" | ||
65 | #endif | 64 | #endif |
66 | #include "splash.h" | 65 | #include "splash.h" |
67 | 66 | ||
@@ -1707,7 +1706,7 @@ void audio_thread(void) | |||
1707 | 1706 | ||
1708 | #ifdef CONFIG_TUNER | 1707 | #ifdef CONFIG_TUNER |
1709 | /* check if radio is playing */ | 1708 | /* check if radio is playing */ |
1710 | if (radio_get_status() != FMRADIO_OFF) { | 1709 | if (get_radio_status() != FMRADIO_OFF) { |
1711 | radio_stop(); | 1710 | radio_stop(); |
1712 | } | 1711 | } |
1713 | #endif | 1712 | #endif |
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; |
diff --git a/apps/recorder/radio.h b/apps/recorder/radio.h index 127bea0723..b4f4da2f4f 100644 --- a/apps/recorder/radio.h +++ b/apps/recorder/radio.h | |||
@@ -19,11 +19,16 @@ | |||
19 | #ifndef RADIO_H | 19 | #ifndef RADIO_H |
20 | #define RADIO_H | 20 | #define RADIO_H |
21 | 21 | ||
22 | #define FMRADIO_OFF 0 | ||
23 | #define FMRADIO_PLAYING 1 | ||
24 | #define FMRADIO_PAUSED 2 | ||
25 | |||
22 | #ifdef CONFIG_TUNER | 26 | #ifdef CONFIG_TUNER |
23 | void radio_init(void); | 27 | void radio_init(void); |
24 | bool radio_screen(void); | 28 | bool radio_screen(void); |
25 | void radio_stop(void); | 29 | void radio_stop(void); |
26 | bool radio_hardware_present(void); | 30 | bool radio_hardware_present(void); |
31 | int get_radio_status(void); | ||
27 | 32 | ||
28 | struct fmstation | 33 | struct fmstation |
29 | { | 34 | { |
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c index 055ca07ab7..830270d08a 100644 --- a/firmware/drivers/power.c +++ b/firmware/drivers/power.c | |||
@@ -34,11 +34,17 @@ bool charger_enabled; | |||
34 | 34 | ||
35 | #ifdef CONFIG_TUNER | 35 | #ifdef CONFIG_TUNER |
36 | 36 | ||
37 | static int fmstatus = 0; | 37 | static bool powered = false; |
38 | 38 | ||
39 | void radio_set_status(int status) | 39 | bool radio_powered() |
40 | { | 40 | { |
41 | fmstatus = status; | 41 | return powered; |
42 | } | ||
43 | |||
44 | bool radio_power(bool status) | ||
45 | { | ||
46 | bool old_status = powered; | ||
47 | powered = status; | ||
42 | #ifdef HAVE_TUNER_PWR_CTRL | 48 | #ifdef HAVE_TUNER_PWR_CTRL |
43 | if (status) | 49 | if (status) |
44 | { | 50 | { |
@@ -48,11 +54,7 @@ void radio_set_status(int status) | |||
48 | else | 54 | else |
49 | or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */ | 55 | or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */ |
50 | #endif | 56 | #endif |
51 | } | 57 | return old_status; |
52 | |||
53 | int radio_get_status(void) | ||
54 | { | ||
55 | return fmstatus; | ||
56 | } | 58 | } |
57 | 59 | ||
58 | #endif /* #ifdef CONFIG_TUNER */ | 60 | #endif /* #ifdef CONFIG_TUNER */ |
diff --git a/firmware/export/power.h b/firmware/export/power.h index f0c4c302ea..bf645522ef 100644 --- a/firmware/export/power.h +++ b/firmware/export/power.h | |||
@@ -35,12 +35,8 @@ void spdif_power_enable(bool on); | |||
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #ifdef CONFIG_TUNER | 37 | #ifdef CONFIG_TUNER |
38 | /* status values */ | 38 | extern bool radio_power(bool status); |
39 | #define FMRADIO_OFF 0 /* switched off */ | 39 | extern bool radio_powered(void); |
40 | #define FMRADIO_POWERED 1 /* left powered, but idle */ | ||
41 | #define FMRADIO_PLAYING 2 /* actively in use */ | ||
42 | extern void radio_set_status(int status); | ||
43 | extern int radio_get_status(void); | ||
44 | #endif | 40 | #endif |
45 | 41 | ||
46 | #endif | 42 | #endif |
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index cdf29f53b1..ed3f42287c 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -385,7 +385,7 @@ static void handle_auto_poweroff(void) | |||
385 | 385 | ||
386 | if(timeout && | 386 | if(timeout && |
387 | #ifdef CONFIG_TUNER | 387 | #ifdef CONFIG_TUNER |
388 | (radio_get_status() != FMRADIO_PLAYING) && | 388 | (!radio_powered()) && |
389 | #endif | 389 | #endif |
390 | !usb_inserted() && | 390 | !usb_inserted() && |
391 | ((audio_stat == 0) || | 391 | ((audio_stat == 0) || |