diff --git a/apps/filetree.c b/apps/filetree.c index 10174dbb31..4a68d00f8b 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -445,7 +445,7 @@ int ft_enter(struct tree_context* c) { set_file(buf, global_settings.fmr_file, MAX_FILENAME); radio_load_presets(global_settings.fmr_file); - if(!in_radio_screen()) + if(!global_status.in_radio_screen) radio_screen(); } /* diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c index d3f4813e37..f1943f3356 100644 --- a/apps/gui/statusbar.c +++ b/apps/gui/statusbar.c @@ -258,8 +258,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw) #endif #ifdef HAVE_RECORDING /* turn off volume display in recording screen */ - bool recscreen_on = in_recording_screen(); - if (!recscreen_on) + if (!global_status.in_recording_screen) #endif bar->redraw_volume = gui_statusbar_icon_volume(bar, bar->info.volume); gui_statusbar_icon_play_state(display, current_playmode() + Icon_Play); @@ -267,7 +266,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw) #ifdef HAVE_RECORDING /* If in recording screen, replace repeat mode, volume and shuffle icons with recording info */ - if (recscreen_on) + if (global_status.in_recording_screen) gui_statusbar_icon_recording_info(display); else #endif diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index dc533cf017..97d6266a02 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -114,9 +114,6 @@ static int curr_preset = -1; static int curr_freq; static int radio_mode = RADIO_SCAN_MODE; -static int radio_status = FMRADIO_OFF; -static bool in_screen = false; - #define MAX_PRESETS 64 static bool presets_loaded = false, presets_changed = false; static struct fmstation presets[MAX_PRESETS]; @@ -185,14 +182,11 @@ void radio_init(void) radio_stop(); } +/* For powermgmt.c to check status for shutdown since it can't access + the global_status structure directly. */ int get_radio_status(void) { - return radio_status; -} - -bool in_radio_screen(void) -{ - return in_screen; + return global_status.radio_status; } /* secret flag for starting paused - prevents unmute */ @@ -202,14 +196,14 @@ void radio_start(void) bool start_paused; int mute_timeout; - if(radio_status == FMRADIO_PLAYING) + if(global_status.radio_status == FMRADIO_PLAYING) return; - start_paused = radio_status & FMRADIO_START_PAUSED; + start_paused = global_status.radio_status & FMRADIO_START_PAUSED; /* clear flag before any yielding */ - radio_status &= ~FMRADIO_START_PAUSED; + global_status.radio_status &= ~FMRADIO_START_PAUSED; - if(radio_status == FMRADIO_OFF) + if(global_status.radio_status == FMRADIO_OFF) radio_power(true); curr_freq = global_status.last_frequency @@ -219,7 +213,7 @@ void radio_start(void) radio_set(RADIO_SLEEP, 0); /* wake up the tuner */ radio_set(RADIO_FREQUENCY, curr_freq); - if(radio_status == FMRADIO_OFF) + if(global_status.radio_status == FMRADIO_OFF) { radio_set(RADIO_IF_MEASUREMENT, 0); radio_set(RADIO_SENSITIVITY, 0); @@ -248,34 +242,34 @@ void radio_start(void) if(!start_paused) radio_set(RADIO_MUTE, 0); - radio_status = FMRADIO_PLAYING; + global_status.radio_status = FMRADIO_PLAYING; } /* radio_start */ void radio_pause(void) { - if(radio_status == FMRADIO_PAUSED) + if(global_status.radio_status == FMRADIO_PAUSED) return; - if(radio_status == FMRADIO_OFF) + if(global_status.radio_status == FMRADIO_OFF) { - radio_status |= FMRADIO_START_PAUSED; + global_status.radio_status |= FMRADIO_START_PAUSED; radio_start(); } radio_set(RADIO_MUTE, 1); radio_set(RADIO_SLEEP, 1); - radio_status = FMRADIO_PAUSED; + global_status.radio_status = FMRADIO_PAUSED; } /* radio_pause */ void radio_stop(void) { - if(radio_status == FMRADIO_OFF) + if(global_status.radio_status == FMRADIO_OFF) return; radio_set(RADIO_MUTE, 1); radio_set(RADIO_SLEEP, 1); /* low power mode, if available */ - radio_status = FMRADIO_OFF; + global_status.radio_status = FMRADIO_OFF; radio_power(false); /* status update, power off if avail. */ } /* radio_stop */ @@ -397,7 +391,7 @@ bool radio_screen(void) gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) ); #endif /* change status to "in screen" */ - in_screen = true; + global_status.in_radio_screen = true; /* always display status bar in radio screen for now */ global_settings.statusbar = true; @@ -422,7 +416,7 @@ bool radio_screen(void) } #ifndef SIMULATOR - if(radio_status == FMRADIO_OFF) + if(global_status.radio_status == FMRADIO_OFF) audio_stop(); #if CONFIG_CODEC != SWCODEC @@ -449,10 +443,11 @@ bool radio_screen(void) /* turn on radio */ #if CONFIG_CODEC == SWCODEC - rec_set_source(AUDIO_SRC_FMRADIO, (radio_status == FMRADIO_PAUSED) ? + rec_set_source(AUDIO_SRC_FMRADIO, + (global_status.radio_status == FMRADIO_PAUSED) ? SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING); #else - if (radio_status == FMRADIO_OFF) + if (global_status.radio_status == FMRADIO_OFF) radio_start(); #endif @@ -676,7 +671,7 @@ bool radio_screen(void) break; case ACTION_FM_PLAY: - if (radio_status == FMRADIO_PLAYING) + if (global_status.radio_status == FMRADIO_PLAYING) radio_pause(); else radio_start(); @@ -819,7 +814,7 @@ bool radio_screen(void) timeout = current_tick + HZ; /* keep "mono" from always being displayed when paused */ - if (radio_status != FMRADIO_PAUSED) + if (global_status.radio_status != FMRADIO_PAUSED) { stereo = radio_get(RADIO_STEREO) && !global_settings.fm_force_mono; @@ -962,7 +957,7 @@ bool radio_screen(void) /* restore status bar settings */ global_settings.statusbar = statusbar; - in_screen = false; + global_status.in_radio_screen = false; return have_recorded; } /* radio_screen */ diff --git a/apps/recorder/radio.h b/apps/recorder/radio.h index a4f9f1a978..0bfda3bccf 100644 --- a/apps/recorder/radio.h +++ b/apps/recorder/radio.h @@ -31,7 +31,6 @@ void radio_start(void); void radio_pause(void); void radio_stop(void); bool radio_hardware_present(void); -bool in_radio_screen(void); #define MAX_FMPRESET_LEN 27 diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index cb934877a9..a0a929f3a6 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -70,13 +70,6 @@ #include "radio.h" #ifdef HAVE_RECORDING -static bool in_screen = false; - -bool in_recording_screen(void) -{ - return in_screen; -} - #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1) #if CONFIG_KEYPAD == RECORDER_PAD @@ -801,7 +794,7 @@ bool recording_screen(bool no_source) struct audio_recording_options rec_options; - in_screen = true; + global_status.in_recording_screen = true; cursor = 0; #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR) ata_set_led_enabled(false); @@ -1771,7 +1764,7 @@ bool recording_screen(bool no_source) peak_meter_trigger(false); peak_meter_set_trigger_listener(NULL); - in_screen = false; + global_status.in_recording_screen = false; sound_settings_apply(); FOR_NB_SCREENS(i) diff --git a/apps/recorder/recording.h b/apps/recorder/recording.h index 1b313ecab5..a67337b9b6 100644 --- a/apps/recorder/recording.h +++ b/apps/recorder/recording.h @@ -19,7 +19,6 @@ #ifndef RECORDING_H #define RECORDING_H -bool in_recording_screen(void); bool recording_screen(bool no_source); char *rec_create_filename(char *buf); int rec_create_directory(void); diff --git a/apps/settings.c b/apps/settings.c index f0833a65c2..4d06f9b09c 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -73,7 +73,20 @@ void dac_line_in(bool enable); #endif struct user_settings global_settings; -struct system_status global_status; + +/* Initial values for globally needed state data that shouldn't be saved + or reset should be defined here and not in settings_list */ +struct system_status global_status = +{ +#ifdef CONFIG_TUNER + .in_radio_screen = false, + .radio_status = FMRADIO_OFF, +#endif +#ifdef HAVE_RECORDING + .in_recording_screen = false, +#endif +}; + #ifdef HAVE_RECORDING const char rec_base_directory[] = REC_BASE_DIR; #endif diff --git a/apps/settings.h b/apps/settings.h index 7321d39cf5..379084b885 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -263,8 +263,17 @@ struct system_status #ifdef CONFIG_TUNER int last_frequency; /* Last frequency for resuming, in FREQ_STEP units, relative to MIN_FREQ */ + bool in_radio_screen; /* Currently in radio screen? + Set by radio_screen. */ + int radio_status; /* Current radio status (off, playing, paused) + Set by radio control functions. */ +#endif +#ifdef HAVE_RECORDING + bool in_recording_screen; /* Currently in recording screen? + Set by recording_screen. */ #endif }; + struct user_settings { /* audio settings */ diff --git a/apps/status.c b/apps/status.c index 75219d604c..d03cb98157 100644 --- a/apps/status.c +++ b/apps/status.c @@ -97,12 +97,10 @@ int current_playmode(void) #endif #ifdef CONFIG_TUNER - audio_stat = get_radio_status(); - - if(audio_stat & FMRADIO_PLAYING) + if(global_status.radio_status & FMRADIO_PLAYING) return STATUS_RADIO; - if(audio_stat & FMRADIO_PAUSED) + if(global_status.radio_status & FMRADIO_PAUSED) return STATUS_RADIO_PAUSE; #endif diff --git a/firmware/export/fmradio.h b/firmware/export/fmradio.h index 73113237c0..87fcfd191c 100644 --- a/firmware/export/fmradio.h +++ b/firmware/export/fmradio.h @@ -29,11 +29,6 @@ #define FMRADIO_PLAYING 0x1 #define FMRADIO_PAUSED 0x2 -/* returns the IN flag */ -#define FMRADIO_IN_SCREEN(s) ((s) & FMRADIO_IN_FLAG) -#define FMRADIO_STATUS_PLAYING(s) ((s) & FMRADIO_PLAYING_OUT) -#define FMRADIO_STATUS_PAUSED(s) ((s) & FMRADIO_PAUSED_OUT) - extern int get_radio_status(void); extern int fmradio_read(int addr);