From 2521bf5d2675ddd8c07637d021198134a7e12445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Wallm=C3=A9nius?= Date: Sun, 20 Apr 2008 11:02:42 +0000 Subject: Fix speaking of decimal values to work when decimals != 1, spell the fractional part instead of speaking it like a number, break out a part of output_dyn_value into a separate function and use it git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17185 a1c6a512-1295-4272-9138-f99709370657 --- apps/misc.c | 13 +------------ apps/talk.c | 33 +++++++++++++++++++++++++++------ apps/talk.h | 5 ++++- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/apps/misc.c b/apps/misc.c index 1d83640..f6e5e6b 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -89,7 +89,6 @@ char *output_dyn_value(char *buf, int buf_size, int value, int scale = bin_scale ? 1024 : 1000; int fraction = 0; int unit_no = 0; - int i; char tbuf[5]; while (value >= scale) @@ -118,17 +117,7 @@ char *output_dyn_value(char *buf, int buf_size, int value, } else { - /* strip trailing zeros from the fraction */ - for (i = strlen(tbuf) - 1; (i >= 0) && (tbuf[i] == '0'); i--) - tbuf[i] = '\0'; - - talk_number(value, true); - if (tbuf[0] != 0) - { - talk_id(LANG_POINT, true); - talk_spell(tbuf, true); - } - talk_id(P2ID(units[unit_no]), true); + talk_fractional(tbuf, value, P2ID(units[unit_no])); } return buf; } diff --git a/apps/talk.c b/apps/talk.c index db70a51..e9d54fd 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -763,6 +763,22 @@ static int talk_time_unit(long secs, bool exact, bool enqueue) return 0; } +void talk_fractional(char *tbuf, int value, int unit) +{ + int i; + /* strip trailing zeros from the fraction */ + for (i = strlen(tbuf) - 1; (i >= 0) && (tbuf[i] == '0'); i--) + tbuf[i] = '\0'; + + talk_number(value, true); + if (tbuf[0] != 0) + { + talk_id(LANG_POINT, true); + talk_spell(tbuf, true); + } + talk_id(unit, true); +} + int talk_value(long n, int unit, bool enqueue) { return talk_value_decimal(n, unit, 0, enqueue); @@ -805,6 +821,12 @@ int talk_value_decimal(long n, int unit, int decimals, bool enqueue) = VOICE_PM_UNITS_PER_TICK, }; + static const int pow10[] = { /* 10^0 - 10^7 */ + 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000 + }; + + char tbuf[8]; + if (talk_temp_disable_count > 0) return -1; /* talking has been disabled */ #if CONFIG_CODEC != SWCODEC @@ -841,18 +863,17 @@ int talk_value_decimal(long n, int unit, int decimals, bool enqueue) { talk_id(VOICE_MINUS, enqueue); n = -n; - enqueue = true; } - talk_number(n / (10*decimals), enqueue); - talk_id(LANG_POINT, true); - n %= (10*decimals); - enqueue = true; + snprintf(tbuf, sizeof(tbuf), "%0*d", decimals, n % pow10[decimals]); + talk_fractional(tbuf, n / pow10[decimals], unit_id); + + return 0; } talk_number(n, enqueue); /* say the number */ talk_id(unit_id, true); /* say the unit, if any */ - + return 0; } diff --git a/apps/talk.h b/apps/talk.h index afd280e..d949794 100644 --- a/apps/talk.h +++ b/apps/talk.h @@ -62,7 +62,7 @@ enum { #define TALK_ID(n,u) (((long)(u))<