diff options
| author | Nils Wallménius <nils@rockbox.org> | 2008-04-20 11:02:42 +0000 |
|---|---|---|
| committer | Nils Wallménius <nils@rockbox.org> | 2008-04-20 11:02:42 +0000 |
| commit | 2521bf5d2675ddd8c07637d021198134a7e12445 (patch) | |
| tree | 72215a929b18362b672615981650aac5941073a2 /apps | |
| parent | db2d61f4eab4adc099abeaafa5e6f97d75f92824 (diff) | |
| download | rockbox-2521bf5d2675ddd8c07637d021198134a7e12445.zip rockbox-2521bf5d2675ddd8c07637d021198134a7e12445.tar.gz rockbox-2521bf5d2675ddd8c07637d021198134a7e12445.tar.bz2 rockbox-2521bf5d2675ddd8c07637d021198134a7e12445.tar.xz | |
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
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/misc.c | 13 | ||||
| -rw-r--r-- | apps/talk.c | 33 | ||||
| -rw-r--r-- | 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))<<UNIT_SHIFT | ((n) & ~(-1L<<UNIT_SHIFT))) /* make a "talkable" ID from a decimal number + unit, the decimal number - is represented like x*10*d where d is the number of decimal digits */ + is represented like x*10^d where d is the number of decimal digits */ #define TALK_ID_DECIMAL(n,d,u) (((long)(u))<<UNIT_SHIFT |\ ((long)(d))<<DECIMAL_SHIFT |\ ((n) & ~(-1L<<DECIMAL_SHIFT))) @@ -92,6 +92,9 @@ void talk_disable(bool disable); /* temporarily disable (or re-enable) talking ( void talk_force_shutup(void); /* kill voice unconditionally */ void talk_shutup(void); /* Interrupt voice, as when enqueue is false */ +/* helper function for speaking fractional numbers */ +void talk_fractional(char *tbuf, int value, int unit); + #if CONFIG_RTC void talk_time(struct tm *tm, bool enqueue); void talk_date(struct tm *tm, bool enqueue); |