forked from len0rd/rockbox
Format FM frequency depending on the regional settings (FS#11273)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26069 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9eed2f71cc
commit
edb6bedddb
2 changed files with 35 additions and 26 deletions
|
@ -346,11 +346,29 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3,
|
||||||
#if CONFIG_TUNER
|
#if CONFIG_TUNER
|
||||||
|
|
||||||
/* Formats the frequency (specified in Hz) in MHz, */
|
/* Formats the frequency (specified in Hz) in MHz, */
|
||||||
/* with two digits after the decimal point */
|
/* with one or two digits after the decimal point -- */
|
||||||
static void format_freq_MHz(int freq, char *buf, int buf_size)
|
/* depending on the frequency changing step. */
|
||||||
|
/* Returns buf */
|
||||||
|
static char *format_freq_MHz(int freq, int freq_step, char *buf, int buf_size)
|
||||||
{
|
{
|
||||||
freq = freq / 10000;
|
int scale, div;
|
||||||
snprintf(buf, buf_size, "%d.%02d", freq/100, freq%100);
|
char *fmt;
|
||||||
|
if (freq_step < 100000)
|
||||||
|
{
|
||||||
|
/* Format with two digits after decimal point */
|
||||||
|
scale = 10000;
|
||||||
|
fmt = "%d.%02d";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Format with one digit after decimal point */
|
||||||
|
scale = 100000;
|
||||||
|
fmt = "%d.%d";
|
||||||
|
}
|
||||||
|
div = 1000000 / scale;
|
||||||
|
freq = freq / scale;
|
||||||
|
snprintf(buf, buf_size, fmt, freq/div, freq%div);
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -358,6 +376,8 @@ static void format_freq_MHz(int freq, char *buf, int buf_size)
|
||||||
const char *get_radio_token(struct wps_token *token, int preset_offset,
|
const char *get_radio_token(struct wps_token *token, int preset_offset,
|
||||||
char *buf, int buf_size, int limit, int *intval)
|
char *buf, int buf_size, int limit, int *intval)
|
||||||
{
|
{
|
||||||
|
const struct fm_region_data *region_data =
|
||||||
|
&(fm_region_data[global_settings.fm_region]);
|
||||||
(void)limit;
|
(void)limit;
|
||||||
switch (token->type)
|
switch (token->type)
|
||||||
{
|
{
|
||||||
|
@ -375,23 +395,14 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
|
||||||
return "s";
|
return "s";
|
||||||
return NULL;
|
return NULL;
|
||||||
case WPS_TOKEN_TUNER_MINFREQ: /* changes based on "region" */
|
case WPS_TOKEN_TUNER_MINFREQ: /* changes based on "region" */
|
||||||
{
|
return format_freq_MHz(region_data->freq_min,
|
||||||
format_freq_MHz(fm_region_data[global_settings.fm_region].freq_min,
|
region_data->freq_step, buf, buf_size);
|
||||||
buf, buf_size);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
case WPS_TOKEN_TUNER_MAXFREQ: /* changes based on "region" */
|
case WPS_TOKEN_TUNER_MAXFREQ: /* changes based on "region" */
|
||||||
{
|
return format_freq_MHz(region_data->freq_max,
|
||||||
format_freq_MHz(fm_region_data[global_settings.fm_region].freq_max,
|
region_data->freq_step, buf, buf_size);
|
||||||
buf, buf_size);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
case WPS_TOKEN_TUNER_CURFREQ:
|
case WPS_TOKEN_TUNER_CURFREQ:
|
||||||
{
|
return format_freq_MHz(radio_current_frequency(),
|
||||||
format_freq_MHz(radio_current_frequency(),
|
region_data->freq_step, buf, buf_size);
|
||||||
buf, buf_size);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
case WPS_TOKEN_PRESET_ID:
|
case WPS_TOKEN_PRESET_ID:
|
||||||
snprintf(buf, buf_size, "%d", radio_current_preset() + 1 + preset_offset);
|
snprintf(buf, buf_size, "%d", radio_current_preset() + 1 + preset_offset);
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -414,7 +425,7 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
format_freq_MHz(radio_get_preset(preset)->frequency,
|
format_freq_MHz(radio_get_preset(preset)->frequency,
|
||||||
buf, buf_size);
|
region_data->freq_step, buf, buf_size);
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,11 +386,9 @@ Examples:
|
||||||
\config{\%tt} & Is the tuner tuned?\\
|
\config{\%tt} & Is the tuner tuned?\\
|
||||||
\config{\%tm} & Scan or preset mode? Scan is ``true'', preset is ``false''.\\
|
\config{\%tm} & Scan or preset mode? Scan is ``true'', preset is ``false''.\\
|
||||||
\config{\%ts} & Is the station in stereo?\\
|
\config{\%ts} & Is the station in stereo?\\
|
||||||
\config{\%ta} & Minimum frequency (region specific) in MHz, with two
|
\config{\%ta} & Minimum frequency (region specific) in MHz.\\
|
||||||
decimal digits.\\
|
\config{\%tb} & Maximum frequency (region specific) in MHz.\\
|
||||||
\config{\%tb} & Maximum frequency (region specific) in MHz, with two
|
\config{\%tf} & Current frequency in MHz.\\
|
||||||
decimal digits.\\
|
|
||||||
\config{\%tf} & Current frequency in MHz, with two decimal digits.\\
|
|
||||||
\config{\%Ti} & Current preset id, i.e. 1-based number of the preset
|
\config{\%Ti} & Current preset id, i.e. 1-based number of the preset
|
||||||
within the presets list (usable in playlist viewer).\\
|
within the presets list (usable in playlist viewer).\\
|
||||||
\config{\%Tn} & Current preset name (usable in playlist viewer).\\
|
\config{\%Tn} & Current preset name (usable in playlist viewer).\\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue