summaryrefslogtreecommitdiff
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.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,
345 345
346#if CONFIG_TUNER 346#if CONFIG_TUNER
347 347
348/* Formats the frequency (specified in Hz) in MHz, */ 348/* Formats the frequency (specified in Hz) in MHz, */
349/* with two digits after the decimal point */ 349/* with one or two digits after the decimal point -- */
350static void format_freq_MHz(int freq, char *buf, int buf_size) 350/* depending on the frequency changing step. */
351/* Returns buf */
352static char *format_freq_MHz(int freq, int freq_step, char *buf, int buf_size)
351{ 353{
352 freq = freq / 10000; 354 int scale, div;
353 snprintf(buf, buf_size, "%d.%02d", freq/100, freq%100); 355 char *fmt;
356 if (freq_step < 100000)
357 {
358 /* Format with two digits after decimal point */
359 scale = 10000;
360 fmt = "%d.%02d";
361 }
362 else
363 {
364 /* Format with one digit after decimal point */
365 scale = 100000;
366 fmt = "%d.%d";
367 }
368 div = 1000000 / scale;
369 freq = freq / scale;
370 snprintf(buf, buf_size, fmt, freq/div, freq%div);
371 return buf;
354} 372}
355 373
356 374
@@ -358,6 +376,8 @@ static void format_freq_MHz(int freq, char *buf, int buf_size)
358const char *get_radio_token(struct wps_token *token, int preset_offset, 376const char *get_radio_token(struct wps_token *token, int preset_offset,
359 char *buf, int buf_size, int limit, int *intval) 377 char *buf, int buf_size, int limit, int *intval)
360{ 378{
379 const struct fm_region_data *region_data =
380 &(fm_region_data[global_settings.fm_region]);
361 (void)limit; 381 (void)limit;
362 switch (token->type) 382 switch (token->type)
363 { 383 {
@@ -375,23 +395,14 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
375 return "s"; 395 return "s";
376 return NULL; 396 return NULL;
377 case WPS_TOKEN_TUNER_MINFREQ: /* changes based on "region" */ 397 case WPS_TOKEN_TUNER_MINFREQ: /* changes based on "region" */
378 { 398 return format_freq_MHz(region_data->freq_min,
379 format_freq_MHz(fm_region_data[global_settings.fm_region].freq_min, 399 region_data->freq_step, buf, buf_size);
380 buf, buf_size);
381 return buf;
382 }
383 case WPS_TOKEN_TUNER_MAXFREQ: /* changes based on "region" */ 400 case WPS_TOKEN_TUNER_MAXFREQ: /* changes based on "region" */
384 { 401 return format_freq_MHz(region_data->freq_max,
385 format_freq_MHz(fm_region_data[global_settings.fm_region].freq_max, 402 region_data->freq_step, buf, buf_size);
386 buf, buf_size);
387 return buf;
388 }
389 case WPS_TOKEN_TUNER_CURFREQ: 403 case WPS_TOKEN_TUNER_CURFREQ:
390 { 404 return format_freq_MHz(radio_current_frequency(),
391 format_freq_MHz(radio_current_frequency(), 405 region_data->freq_step, buf, buf_size);
392 buf, buf_size);
393 return buf;
394 }
395 case WPS_TOKEN_PRESET_ID: 406 case WPS_TOKEN_PRESET_ID:
396 snprintf(buf, buf_size, "%d", radio_current_preset() + 1 + preset_offset); 407 snprintf(buf, buf_size, "%d", radio_current_preset() + 1 + preset_offset);
397 return buf; 408 return buf;
@@ -414,7 +425,7 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
414 else 425 else
415 { 426 {
416 format_freq_MHz(radio_get_preset(preset)->frequency, 427 format_freq_MHz(radio_get_preset(preset)->frequency,
417 buf, buf_size); 428 region_data->freq_step, buf, buf_size);
418 } 429 }
419 return buf; 430 return buf;
420 } 431 }
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:
386 \config{\%tt} & Is the tuner tuned?\\ 386 \config{\%tt} & Is the tuner tuned?\\
387 \config{\%tm} & Scan or preset mode? Scan is ``true'', preset is ``false''.\\ 387 \config{\%tm} & Scan or preset mode? Scan is ``true'', preset is ``false''.\\
388 \config{\%ts} & Is the station in stereo?\\ 388 \config{\%ts} & Is the station in stereo?\\
389 \config{\%ta} & Minimum frequency (region specific) in MHz, with two 389 \config{\%ta} & Minimum frequency (region specific) in MHz.\\
390 decimal digits.\\ 390 \config{\%tb} & Maximum frequency (region specific) in MHz.\\
391 \config{\%tb} & Maximum frequency (region specific) in MHz, with two 391 \config{\%tf} & Current frequency in MHz.\\
392 decimal digits.\\
393 \config{\%tf} & Current frequency in MHz, with two decimal digits.\\
394 \config{\%Ti} & Current preset id, i.e. 1-based number of the preset 392 \config{\%Ti} & Current preset id, i.e. 1-based number of the preset
395 within the presets list (usable in playlist viewer).\\ 393 within the presets list (usable in playlist viewer).\\
396 \config{\%Tn} & Current preset name (usable in playlist viewer).\\ 394 \config{\%Tn} & Current preset name (usable in playlist viewer).\\