radio.c presets.c small clean-up

remove some extern vars in favor of get/set functions

Change-Id: Ic4effae2acdd480beeab76c9f0319b1783a3bab3
This commit is contained in:
William Wilgus 2024-11-30 15:24:47 -05:00
parent fdc17096b5
commit 80a0bf590f
7 changed files with 65 additions and 42 deletions

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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,

View file

@ -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);
}

View file

@ -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();

View file

@ -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);

View file

@ -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);