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
This commit is contained in:
Nils Wallménius 2008-04-20 11:02:42 +00:00
parent db2d61f4ea
commit 2521bf5d26
3 changed files with 32 additions and 19 deletions

View file

@ -89,7 +89,6 @@ char *output_dyn_value(char *buf, int buf_size, int value,
int scale = bin_scale ? 1024 : 1000; int scale = bin_scale ? 1024 : 1000;
int fraction = 0; int fraction = 0;
int unit_no = 0; int unit_no = 0;
int i;
char tbuf[5]; char tbuf[5];
while (value >= scale) while (value >= scale)
@ -118,17 +117,7 @@ char *output_dyn_value(char *buf, int buf_size, int value,
} }
else else
{ {
/* strip trailing zeros from the fraction */ talk_fractional(tbuf, value, P2ID(units[unit_no]));
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);
} }
return buf; return buf;
} }

View file

@ -763,6 +763,22 @@ static int talk_time_unit(long secs, bool exact, bool enqueue)
return 0; 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) int talk_value(long n, int unit, bool enqueue)
{ {
return talk_value_decimal(n, unit, 0, 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, = 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) if (talk_temp_disable_count > 0)
return -1; /* talking has been disabled */ return -1; /* talking has been disabled */
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
@ -841,13 +863,12 @@ int talk_value_decimal(long n, int unit, int decimals, bool enqueue)
{ {
talk_id(VOICE_MINUS, enqueue); talk_id(VOICE_MINUS, enqueue);
n = -n; n = -n;
enqueue = true;
} }
talk_number(n / (10*decimals), enqueue); snprintf(tbuf, sizeof(tbuf), "%0*d", decimals, n % pow10[decimals]);
talk_id(LANG_POINT, true); talk_fractional(tbuf, n / pow10[decimals], unit_id);
n %= (10*decimals);
enqueue = true; return 0;
} }
talk_number(n, enqueue); /* say the number */ talk_number(n, enqueue); /* say the number */

View file

@ -62,7 +62,7 @@ enum {
#define TALK_ID(n,u) (((long)(u))<<UNIT_SHIFT | ((n) & ~(-1L<<UNIT_SHIFT))) #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 /* 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 |\ #define TALK_ID_DECIMAL(n,d,u) (((long)(u))<<UNIT_SHIFT |\
((long)(d))<<DECIMAL_SHIFT |\ ((long)(d))<<DECIMAL_SHIFT |\
((n) & ~(-1L<<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_force_shutup(void); /* kill voice unconditionally */
void talk_shutup(void); /* Interrupt voice, as when enqueue is false */ 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 #if CONFIG_RTC
void talk_time(struct tm *tm, bool enqueue); void talk_time(struct tm *tm, bool enqueue);
void talk_date(struct tm *tm, bool enqueue); void talk_date(struct tm *tm, bool enqueue);