diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-11-30 15:24:47 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2024-11-30 16:42:43 -0500 |
commit | 80a0bf590fe58d69b73bba62fd941b9613ddafe2 (patch) | |
tree | ffcda728b491c1882db0d3c1221b69050110e60b | |
parent | fdc17096b54d45e283adb89ccdeeeb974c2ae43c (diff) | |
download | rockbox-80a0bf590f.tar.gz rockbox-80a0bf590f.zip |
radio.c presets.c small clean-up
remove some extern vars in favor of get/set functions
Change-Id: Ic4effae2acdd480beeab76c9f0319b1783a3bab3
-rw-r--r-- | apps/gui/skin_engine/skin_display.c | 2 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 8 | ||||
-rw-r--r-- | apps/menus/radio_menu.c | 11 | ||||
-rw-r--r-- | apps/radio/presets.c | 43 | ||||
-rw-r--r-- | apps/radio/radio.c | 22 | ||||
-rw-r--r-- | apps/radio/radio.h | 19 | ||||
-rw-r--r-- | apps/radio/radioart.c | 2 |
7 files changed, 65 insertions, 42 deletions
diff --git a/apps/gui/skin_engine/skin_display.c b/apps/gui/skin_engine/skin_display.c index aa2184a407..bcfb8273d4 100644 --- a/apps/gui/skin_engine/skin_display.c +++ b/apps/gui/skin_engine/skin_display.c @@ -237,7 +237,7 @@ void draw_progressbar(struct gui_wps *gwps, struct skin_viewport* skin_viewport, #endif { int min = fm_region_data[global_settings.fm_region].freq_min; - end = radio_current_frequency() - min; + end = radio_get_current_frequency() - min; length = fm_region_data[global_settings.fm_region].freq_max - min; } } diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 3e2d1efa83..d11f21d7b2 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -455,7 +455,7 @@ const char *get_radio_token(struct wps_token *token, int preset_offset, return "t"; return NULL; case SKIN_TOKEN_TUNER_SCANMODE: - if (radio_scan_mode()) + if (radio_get_mode() == RADIO_SCAN_MODE) return "s"; return NULL; case SKIN_TOKEN_TUNER_STEREO: @@ -469,7 +469,7 @@ const char *get_radio_token(struct wps_token *token, int preset_offset, return format_freq_MHz(region_data->freq_max, region_data->freq_step, buf, buf_size); case SKIN_TOKEN_TUNER_CURFREQ: - return format_freq_MHz(radio_current_frequency(), + return format_freq_MHz(radio_get_current_frequency(), region_data->freq_step, buf, buf_size); #ifdef HAVE_RADIO_RSSI case SKIN_TOKEN_TUNER_RSSI: @@ -510,9 +510,9 @@ const char *get_radio_token(struct wps_token *token, int preset_offset, if (preset < 0) preset += preset_count; if (token->type == SKIN_TOKEN_PRESET_NAME) - snprintf(buf, buf_size, "%s", radio_get_preset(preset)->name); + snprintf(buf, buf_size, "%s", radio_get_preset_name(preset)); else if (token->type == SKIN_TOKEN_PRESET_FREQ) - format_freq_MHz(radio_get_preset(preset)->frequency, + format_freq_MHz(radio_get_preset_freq(preset), region_data->freq_step, buf, buf_size); else snprintf(buf, buf_size, "%d", preset + 1); diff --git a/apps/menus/radio_menu.c b/apps/menus/radio_menu.c index 9fd25aa503..e245f82f13 100644 --- a/apps/menus/radio_menu.c +++ b/apps/menus/radio_menu.c @@ -92,10 +92,11 @@ MENUITEM_SETTING(sync_rds_time, &global_settings.sync_rds_time, NULL); #endif #ifndef FM_MODE -extern int radio_mode; + static char* get_mode_text(int selected_item, void * data, char *buffer, size_t buffer_len) { + int radio_mode = radio_get_mode(); (void)selected_item; (void)data; snprintf(buffer, buffer_len, "%s %s", str(LANG_MODE), @@ -105,19 +106,21 @@ static char* get_mode_text(int selected_item, void * data, } static int mode_speak_item(int selected_item, void * data) { + int radio_mode = radio_get_mode(); (void)selected_item; (void)data; long talk_ids[4]; talk_ids[0] = LANG_MODE; - talk_ids[1] = radio_mode ? LANG_PRESET : LANG_RADIO_SCAN_MODE; + talk_ids[1] = radio_mode != RADIO_SCAN_MODE? LANG_PRESET : LANG_RADIO_SCAN_MODE; talk_ids[2] = TALK_FINAL_ID; talk_idarray(talk_ids, true); return 0; } static int toggle_radio_mode(void) { - radio_mode = (radio_mode == RADIO_SCAN_MODE) ? - RADIO_PRESET_MODE : RADIO_SCAN_MODE; + int radio_mode = radio_get_mode(); + radio_set_mode((radio_mode == RADIO_SCAN_MODE) ? + RADIO_PRESET_MODE : RADIO_SCAN_MODE); return 0; } MENUITEM_FUNCTION_DYNTEXT(radio_mode_item, 0, toggle_radio_mode, diff --git a/apps/radio/presets.c b/apps/radio/presets.c index b87d2dd285..b518e75bf5 100644 --- a/apps/radio/presets.c +++ b/apps/radio/presets.c @@ -46,15 +46,19 @@ static int curr_preset = -1; -extern int curr_freq; /* from radio.c.. naughty but meh */ -extern int radio_mode; int snap_freq_to_grid(int freq); void remember_frequency(void); +#define FREQ_DISP_DIVISOR (10000) #define MAX_PRESETS 64 static bool presets_loaded = false; static bool presets_changed = false; -static struct fmstation presets[MAX_PRESETS]; + +static struct fmstation +{ + int frequency; /* In Hz */ + char name[MAX_FMPRESET_LEN+1]; +} presets[MAX_PRESETS]; static char filepreset[MAX_PATH]; /* preset filename variable */ @@ -68,10 +72,6 @@ int radio_preset_count(void) { return num_presets; } -const struct fmstation *radio_get_preset(int preset) -{ - return &presets[preset]; -} bool presets_have_changed(void) { @@ -149,6 +149,8 @@ void preset_next(int direction) if (num_presets < 1) return; + int curr_freq = radio_get_current_frequency(); + if (curr_preset == -1) curr_preset = find_closest_preset(curr_freq, direction); else @@ -156,7 +158,7 @@ void preset_next(int direction) /* Must stay on the current grid for the region */ curr_freq = snap_freq_to_grid(presets[curr_preset].frequency); - + radio_set_current_frequency(curr_freq); tuner_set(RADIO_FREQUENCY, curr_freq); remember_frequency(); } @@ -263,6 +265,13 @@ void radio_load_presets(char *filename) presets_changed = false; } +int radio_get_preset_freq(int preset) +{ + if (preset < num_presets) + return presets[preset].frequency; + return -1; +} + const char* radio_get_preset_name(int preset) { if (preset < num_presets) @@ -282,7 +291,7 @@ int handle_radio_add_preset(void) { struct fmstation * const fms = &presets[num_presets]; strcpy(fms->name, buf); - fms->frequency = curr_freq; + fms->frequency = radio_get_current_frequency(); num_presets++; presets_changed = true; presets_loaded = num_presets > 0; @@ -340,7 +349,7 @@ static int radio_delete_preset(void) if (!presets_changed) { /* The preset list will be cleared, switch to Scan Mode. */ - radio_mode = RADIO_SCAN_MODE; + radio_set_mode(RADIO_SCAN_MODE); curr_preset = -1; presets_loaded = false; } @@ -425,7 +434,7 @@ int preset_list_clear(void) num_presets = 0; presets_loaded = false; /* The preset list will be cleared switch to Scan Mode. */ - radio_mode = RADIO_SCAN_MODE; + radio_set_mode(RADIO_SCAN_MODE); curr_preset = -1; presets_changed = false; /* Don't ask to save when clearing the list. */ @@ -459,7 +468,7 @@ static const char* presets_get_name(int selected_item, void *data, struct fmstation *p = &presets[selected_item]; if(p->name[0]) return p->name; - int freq = p->frequency / 10000; + int freq = p->frequency / FREQ_DISP_DIVISOR; int frac = freq % 100; freq /= 100; snprintf(buffer, buffer_len, @@ -509,7 +518,7 @@ int handle_radio_presets(void) break; case ACTION_STD_OK: curr_preset = gui_synclist_get_sel_pos(&lists); - curr_freq = presets[curr_preset].frequency; + radio_set_current_frequency(presets[curr_preset].frequency); next_station(0); result = 1; break; @@ -532,6 +541,7 @@ int handle_radio_presets(void) int presets_scan(void *viewports) { bool do_scan = true; + int curr_freq = radio_get_current_frequency(); struct viewport *vp = (struct viewport *)viewports; FOR_NB_SCREENS(i) @@ -556,7 +566,7 @@ int presets_scan(void *viewports) if(num_presets >= MAX_PRESETS || action_userabort(TIMEOUT_NOBLOCK)) break; - freq = curr_freq / 10000; + freq = curr_freq / FREQ_DISP_DIVISOR; frac = freq % 100; freq /= 100; @@ -572,6 +582,7 @@ int presets_scan(void *viewports) curr_freq += fmr->freq_step; } + radio_set_current_frequency(curr_freq); if (get_radio_status() == FMRADIO_PLAYING) tuner_set(RADIO_MUTE, 0); @@ -586,8 +597,8 @@ int presets_scan(void *viewports) if(num_presets > 0) { - curr_freq = presets[0].frequency; - radio_mode = RADIO_PRESET_MODE; + radio_set_current_frequency(presets[0].frequency); + radio_set_mode(RADIO_PRESET_MODE); presets_loaded = true; next_station(0); } diff --git a/apps/radio/radio.c b/apps/radio/radio.c index bf36f1d32d..fb2555b93f 100644 --- a/apps/radio/radio.c +++ b/apps/radio/radio.c @@ -123,9 +123,8 @@ #endif -/* presets.c needs these so keep unstatic or redo the whole thing! */ -int curr_freq; /* current frequency in Hz */ -int radio_mode = RADIO_SCAN_MODE; +static int curr_freq; /* current frequency in Hz */ +static int radio_mode = RADIO_SCAN_MODE; static int search_dir = 0; static int radio_status = FMRADIO_OFF; @@ -134,20 +133,31 @@ static bool in_screen = false; static void radio_off(void); -bool radio_scan_mode(void) +enum radio_scan_mode radio_get_mode(void) { - return radio_mode == RADIO_SCAN_MODE; + return radio_mode; +} + +void radio_set_mode(enum radio_scan_mode mode) +{ + radio_mode = mode; } bool radio_is_stereo(void) { return tuner_get(RADIO_STEREO) && !global_settings.fm_force_mono; } -int radio_current_frequency(void) + +int radio_get_current_frequency(void) { return curr_freq; } +void radio_set_current_frequency(int freq) +{ + curr_freq = freq; +} + void radio_init(void) { tuner_init(); diff --git a/apps/radio/radio.h b/apps/radio/radio.h index 8c4b394137..2084d263e7 100644 --- a/apps/radio/radio.h +++ b/apps/radio/radio.h @@ -28,7 +28,7 @@ #include "screen_access.h" #include "bmp.h" -enum { +enum radio_scan_mode { RADIO_SCAN_MODE = 0, RADIO_PRESET_MODE, }; @@ -43,13 +43,16 @@ void radio_pause(void); void radio_stop(void); bool radio_hardware_present(void); bool in_radio_screen(void); - -bool radio_scan_mode(void); /* true for scan mode, false for preset mode */ bool radio_is_stereo(void); -int radio_current_frequency(void); + +enum radio_scan_mode radio_get_mode(void); /* RADIO_SCAN_MODE, RADIO_PRESET_MODE */ +void radio_set_mode(enum radio_scan_mode); + +int radio_get_current_frequency(void); +void radio_set_current_frequency(int freq); + int radio_current_preset(void); int radio_preset_count(void); -const struct fmstation *radio_get_preset(int preset); /* callbacks for the radio settings */ void set_radio_region(int region); @@ -57,11 +60,7 @@ void toggle_mono_mode(bool mono); #define MAX_FMPRESET_LEN 27 -struct fmstation -{ - int frequency; /* In Hz */ - char name[MAX_FMPRESET_LEN+1]; -}; +int radio_get_preset_freq(int preset); const char* radio_get_preset_name(int preset); #if 0 /* disabled in draw_progressbar() */ void presets_draw_markers(struct screen *screen, int x, int y, int w, int h); diff --git a/apps/radio/radioart.c b/apps/radio/radioart.c index ce774ac4b1..9eaec0aead 100644 --- a/apps/radio/radioart.c +++ b/apps/radio/radioart.c @@ -109,7 +109,7 @@ int radio_get_art_hid(struct dim *requested_dim) int free_idx = -1; const char* preset_name; - if (!buf || radio_scan_mode() || preset < 0) + if (!buf || (radio_get_mode() == RADIO_SCAN_MODE) || preset < 0) return -1; preset_name = radio_get_preset_name(preset); |