From aced667f48c29a160aa4e5c0a8df037092b28189 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Mon, 18 Sep 2017 06:00:05 -0400 Subject: Undo hacks to meant to get around string formatting limitations The new vuprintf makes unnecessary workarounds due to formatting limitations. I checked grep output for whatever appeared to fit but it's possible I missed some instances because they weren't so obvious. Also, this means sound settings can dynamically work with any number of decimals rather than the current assumption of one or two. Add an ipow() function to help and take advantage of dynamic field width and precision. Consolidate string formatting of sound settings. Change-Id: I46caf534859dfd1916cd440cd25e5206b192fcd8 --- apps/gui/option_select.c | 20 +++----------------- apps/gui/skin_engine/skin_tokens.c | 21 +++++---------------- 2 files changed, 8 insertions(+), 33 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 0452467994..f99e833a1e 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c @@ -106,23 +106,9 @@ const char *option_get_valuestring(const struct settings_list *setting, } else if ((setting->flags & F_T_SOUND) == F_T_SOUND) { - char sign = ' '; - const char *unit = sound_unit(setting->sound_setting->setting); - int val = sound_val2phys(setting->sound_setting->setting, (int)temp_var); - if (sound_numdecimals(setting->sound_setting->setting)) - { - int integer, dec; - if(val < 0) - { - sign = '-'; - val = abs(val); - } - integer = val / 10; - dec = val % 10; - snprintf(buffer, buf_len, "%c%d.%d %s", sign, integer, dec, unit); - } - else - snprintf(buffer, buf_len, "%d %s", val, unit); + format_sound_value(buffer, buf_len, + setting->sound_setting->setting, + temp_var); } else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) { diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index cbf732fe10..1cff83eb9a 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -70,6 +70,7 @@ #if CONFIG_TUNER #include "radio.h" #include "tuner.h" +#include "fixedpoint.h" #endif #include "list.h" @@ -432,23 +433,11 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, /* Returns buf */ static char *format_freq_MHz(int freq, int freq_step, char *buf, int buf_size) { - 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; + int decimals = (freq_step < 100000) + 1; + int scale = ipow(10, 6 - decimals); + int div = 1000000 / scale; freq = freq / scale; - snprintf(buf, buf_size, fmt, freq/div, freq%div); + snprintf(buf, buf_size, "%d.%.*d", freq/div, decimals, freq%div); return buf; } -- cgit v1.2.3