A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

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

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