summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Levin <al.le@rockbox.org>2010-05-15 21:47:30 +0000
committerAlexander Levin <al.le@rockbox.org>2010-05-15 21:47:30 +0000
commitedb6bedddb9bfb9838631a2ac99f8d92fc6daa67 (patch)
tree1a0e633fc947930191ceb9064f847eb044633b70
parent9eed2f71cc14fa30282a18c57ee3942177f8aabe (diff)
downloadrockbox-edb6bedddb9bfb9838631a2ac99f8d92fc6daa67.tar.gz
rockbox-edb6bedddb9bfb9838631a2ac99f8d92fc6daa67.tar.bz2
rockbox-edb6bedddb9bfb9838631a2ac99f8d92fc6daa67.zip
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
-rw-r--r--apps/gui/skin_engine/skin_tokens.c53
-rw-r--r--manual/appendix/wps_tags.tex8
2 files changed, 35 insertions, 26 deletions
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c
index b9d4bd6b15..3d944a5315 100644
--- a/apps/gui/skin_engine/skin_tokens.c
+++ b/apps/gui/skin_engine/skin_tokens.c
@@ -345,12 +345,30 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3,
#if CONFIG_TUNER
-/* Formats the frequency (specified in Hz) in MHz, */
-/* with two digits after the decimal point */
-static void format_freq_MHz(int freq, char *buf, int buf_size)
+/* Formats the frequency (specified in Hz) in MHz, */
+/* with one or two digits after the decimal point -- */
+/* 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;
- snprintf(buf, buf_size, "%d.%02d", freq/100, freq%100);
+ int scale, div;
+ 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,
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;
switch (token->type)
{
@@ -375,23 +395,14 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
return "s";
return NULL;
case WPS_TOKEN_TUNER_MINFREQ: /* changes based on "region" */
- {
- format_freq_MHz(fm_region_data[global_settings.fm_region].freq_min,
- buf, buf_size);
- return buf;
- }
+ return format_freq_MHz(region_data->freq_min,
+ region_data->freq_step, buf, buf_size);
case WPS_TOKEN_TUNER_MAXFREQ: /* changes based on "region" */
- {
- format_freq_MHz(fm_region_data[global_settings.fm_region].freq_max,
- buf, buf_size);
- return buf;
- }
+ return format_freq_MHz(region_data->freq_max,
+ region_data->freq_step, buf, buf_size);
case WPS_TOKEN_TUNER_CURFREQ:
- {
- format_freq_MHz(radio_current_frequency(),
- buf, buf_size);
- return buf;
- }
+ return format_freq_MHz(radio_current_frequency(),
+ region_data->freq_step, buf, buf_size);
case WPS_TOKEN_PRESET_ID:
snprintf(buf, buf_size, "%d", radio_current_preset() + 1 + preset_offset);
return buf;
@@ -414,7 +425,7 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
else
{
format_freq_MHz(radio_get_preset(preset)->frequency,
- buf, buf_size);
+ region_data->freq_step, buf, buf_size);
}
return buf;
}
diff --git a/manual/appendix/wps_tags.tex b/manual/appendix/wps_tags.tex
index 591d8ea7bd..577d31eeef 100644
--- a/manual/appendix/wps_tags.tex
+++ b/manual/appendix/wps_tags.tex
@@ -386,11 +386,9 @@ Examples:
\config{\%tt} & Is the tuner tuned?\\
\config{\%tm} & Scan or preset mode? Scan is ``true'', preset is ``false''.\\
\config{\%ts} & Is the station in stereo?\\
- \config{\%ta} & Minimum frequency (region specific) in MHz, with two
- decimal digits.\\
- \config{\%tb} & Maximum frequency (region specific) in MHz, with two
- decimal digits.\\
- \config{\%tf} & Current frequency in MHz, with two decimal digits.\\
+ \config{\%ta} & Minimum frequency (region specific) in MHz.\\
+ \config{\%tb} & Maximum frequency (region specific) in MHz.\\
+ \config{\%tf} & Current frequency in MHz.\\
\config{\%Ti} & Current preset id, i.e. 1-based number of the preset
within the presets list (usable in playlist viewer).\\
\config{\%Tn} & Current preset name (usable in playlist viewer).\\