summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-01-31 00:39:20 +0000
committerJens Arnold <amiconn@rockbox.org>2005-01-31 00:39:20 +0000
commit2116bba296f12bd94024ec7c39ae03fbfcc5bdef (patch)
tree29c49672b2dcf2012bb6bb69f8130f024f52bdb9
parent19afad88f8bb973726af0c6a7850dbd992996a9f (diff)
downloadrockbox-2116bba296f12bd94024ec7c39ae03fbfcc5bdef.zip
rockbox-2116bba296f12bd94024ec7c39ae03fbfcc5bdef.tar.gz
rockbox-2116bba296f12bd94024ec7c39ae03fbfcc5bdef.tar.bz2
rockbox-2116bba296f12bd94024ec7c39ae03fbfcc5bdef.tar.xz
New function for formatting large-range values for output, both printed and voiced. This replaces num2max5(). It is currently used for the total/free space display in the info menu, for the recorded number of bytes (recorders) and the MMC debug info (Ondios).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5721 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/debug_menu.c43
-rw-r--r--apps/lang/deutsch.lang69
-rw-r--r--apps/lang/english.lang65
-rw-r--r--apps/main_menu.c29
-rw-r--r--apps/misc.c75
-rw-r--r--apps/misc.h12
-rw-r--r--apps/recorder/recording.c16
7 files changed, 209 insertions, 100 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 1c63320..5f1b5af 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -1268,32 +1268,19 @@ static bool view_runtime(void)
}
#ifdef HAVE_MMC
-/* value is 10 * real value */
-static unsigned char prep_value_unit(unsigned long *value,
- const unsigned char *units)
-{
- int unit_no = 0;
-
- while (*value >= 10000)
- {
- *value /= 1000;
- unit_no++;
- }
- return units[unit_no];
-}
-
bool dbg_mmc_info(void)
{
bool done = false;
int currval = 0;
unsigned long value;
tCardInfo *card;
- unsigned char pbuf[32];
+ unsigned char pbuf[32], pbuf2[32];
unsigned char card_name[7];
- unsigned char unit;
-
+
static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
+ static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
+ static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
card_name[6] = '\0';
@@ -1337,24 +1324,14 @@ bool dbg_mmc_info(void)
}
else /* Technical details */
{
- value = card->speed / 100;
- unit = prep_value_unit(&value, "kMG");
- if (value < 100)
- snprintf(pbuf, sizeof(pbuf), "Speed: %d.%01d %cBit/s",
- (int)(value / 10), (int)(value % 10), unit);
- else
- snprintf(pbuf, sizeof(pbuf), "Speed: %d %cBit/s",
- (int)(value / 10), unit);
+ output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000,
+ kbit_units, false);
+ snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2);
lcd_puts(0, 1, pbuf);
- value = card->tsac;
- unit = prep_value_unit(&value, "nµm");
- if (value < 100)
- snprintf(pbuf, sizeof(pbuf), "Tsac: %d.%01d %cs",
- (int)(value / 10), (int)(value % 10), unit);
- else
- snprintf(pbuf, sizeof(pbuf), "Tsac: %d %cs",
- (int)(value / 10), unit);
+ output_dyn_value(pbuf2, sizeof pbuf2, card->tsac,
+ nsec_units, false);
+ snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2);
lcd_puts(0, 2, pbuf);
snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac);
diff --git a/apps/lang/deutsch.lang b/apps/lang/deutsch.lang
index c5f8d9d..7fd3291 100644
--- a/apps/lang/deutsch.lang
+++ b/apps/lang/deutsch.lang
@@ -985,16 +985,16 @@ voice: "Aufnahmeeinstellungen"
new: "Aufnahmeeinstellungen"
id: LANG_DISK_STAT
-desc: disk size info
-eng: "Disk: %d.%dGB"
+desc: DEPRECATED
+eng: ""
voice: ""
-new: "HDD: %d,%dGB"
+new:
id: LANG_DISK_FREE_STAT
-desc: disk size info
-eng: "Free: %d.%dGB"
-voice: "Freier Plattenplatz:"
-new: "Frei: %d,%dGB"
+desc: DEPRECATED
+eng: ""
+voice: ""
+new:
id: LANG_POWEROFF
desc: disk poweroff flag
@@ -2256,9 +2256,9 @@ voice: "Plus"
new:
id: VOICE_POINT
-desc: spoken only, decimal separator for composing numbers
+desc: DEPRECATED
eng: ""
-voice: "Komma"
+voice: ""
new:
id: VOICE_MILLISECONDS
@@ -2322,15 +2322,15 @@ voice: "Prozent"
new:
id: VOICE_MEGABYTE
-desc: spoken only, a unit postfix
+desc: DEPRECATED
eng: ""
-voice: "Megabyte"
+voice: ""
new:
id: VOICE_GIGABYTE
-desc: spoken only, a unit postfix
+desc: DEPRECATED
eng: ""
-voice: "Gigabyte"
+voice: ""
new:
id: VOICE_MILLIAMPHOURS
@@ -2929,3 +2929,46 @@ desc: in battery settings
eng: "NiMH"
voice: "Nickel-Metallhydrid"
new: "NiMH"
+
+id: LANG_POINT
+desc: decimal separator for composing numbers
+eng: "."
+voice: "Komma"
+new: ","
+
+id: LANG_BYTE
+desc: a unit postfix
+eng: "B"
+voice: ""
+new: "B"
+
+id: LANG_KILOBYTE
+desc: a unit postfix, also voiced
+eng: "KB"
+voice: "Kilobyte"
+new: "KB"
+
+id: LANG_MEGABYTE
+desc: a unit postfix, also voiced
+eng: "MB"
+voice: "Megabyte"
+new: "MB"
+
+id: LANG_GIGABYTE
+desc: a unit postfix, also voiced
+eng: "GB"
+voice: "Gigabyte"
+new: "GB"
+
+id: LANG_DISK_SIZE_INFO
+desc: disk size info
+eng: "HDD:"
+voice: ""
+new: "Disk:"
+
+id: LANG_DISK_FREE_INFO
+desc: disk size info
+eng: "Free:"
+voice: "Freier Plattenplatz:"
+new: "Frei:"
+
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 910bfa4..5323fa0 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -998,15 +998,15 @@ voice: "Recording Settings"
new:
id: LANG_DISK_STAT
-desc: disk size info
-eng: "Disk: %d.%dGB"
+desc: DEPRECATED
+eng: ""
voice: ""
new:
id: LANG_DISK_FREE_STAT
-desc: disk size info
-eng: "Free: %d.%dGB"
-voice: "Free diskspace:"
+desc: DEPRECATED
+eng: ""
+voice: ""
new:
id: LANG_POWEROFF
@@ -2270,9 +2270,9 @@ voice: "plus"
new:
id: VOICE_POINT
-desc: spoken only, decimal separator for composing numbers
+desc: DEPRECATED
eng: ""
-voice: "point"
+voice: ""
new:
id: VOICE_MILLISECONDS
@@ -2336,15 +2336,15 @@ voice: "percent"
new:
id: VOICE_MEGABYTE
-desc: spoken only, a unit postfix, currently not used
+desc: DEPRECATED
eng: ""
-voice: "megabyte"
+voice: ""
new:
id: VOICE_GIGABYTE
-desc: spoken only, a unit postfix
+desc: DEPRECATED
eng: ""
-voice: "gigabyte"
+voice: ""
new:
id: VOICE_MILLIAMPHOURS
@@ -2943,3 +2943,46 @@ desc: in battery settings
eng: "NiMH"
voice: "Nickel metal hydride"
new:
+
+id: LANG_POINT
+desc: decimal separator for composing numbers
+eng: "."
+voice: "point"
+new:
+
+id: LANG_BYTE
+desc: a unit postfix
+eng: "B"
+voice: ""
+new:
+
+id: LANG_KILOBYTE
+desc: a unit postfix, also voiced
+eng: "KB"
+voice: "kilobyte"
+new:
+
+id: LANG_MEGABYTE
+desc: a unit postfix, also voiced
+eng: "MB"
+voice: "megabyte"
+new:
+
+id: LANG_GIGABYTE
+desc: a unit postfix, also voiced
+eng: "GB"
+voice: "gigabyte"
+new:
+
+id: LANG_DISK_SIZE_INFO
+desc: disk size info
+eng: "Disk:"
+voice: ""
+new:
+
+id: LANG_DISK_FREE_INFO
+desc: disk size info
+eng: "Free:"
+voice: "Free diskspace:"
+new:
+
diff --git a/apps/main_menu.c b/apps/main_menu.c
index 7ae57f1..21e8c09 100644
--- a/apps/main_menu.c
+++ b/apps/main_menu.c
@@ -137,7 +137,7 @@ extern bool simulate_usb(void);
#endif
bool show_info(void)
{
- char s[32];
+ char s[32], s2[32];
/* avoid overflow for 8MB mod :) was: ((mp3end - mp3buf) * 1000) / 0x100000; */
int buflen = ((mp3end - mp3buf) * 100) / 0x19999;
int integer, decimal;
@@ -146,9 +146,13 @@ bool show_info(void)
int state = 1;
unsigned long size, free;
+ const unsigned char *kbyte_units[] = {
+ ID2P(LANG_KILOBYTE),
+ ID2P(LANG_MEGABYTE),
+ ID2P(LANG_GIGABYTE)
+ };
+
fat_size( IF_MV2(0,) &size, &free );
- size /= 1024;
- free /= 1024;
if (global_settings.talk_menu)
{ /* say whatever is reasonable, no real connection to the screen */
@@ -160,11 +164,8 @@ bool show_info(void)
talk_value(battery_level(), UNIT_PERCENT, true);
}
- talk_id(LANG_DISK_FREE_STAT, enqueue);
- talk_number(free / 1024, true);
- decimal = free % 1024 / 100;
- talk_id(VOICE_POINT, true);
- talk_value(decimal, UNIT_GB, true);
+ talk_id(LANG_DISK_FREE_INFO, enqueue);
+ output_dyn_value(NULL, 0, free, kbyte_units, true); /* NULL == talk */
#ifdef HAVE_RTC
{
@@ -220,14 +221,12 @@ bool show_info(void)
}
if (state & 2) {
- integer = size / 1024;
- decimal = size % 1024 / 100;
- snprintf(s, sizeof s, str(LANG_DISK_STAT), integer, decimal);
+ output_dyn_value(s2, sizeof s2, size, kbyte_units, true);
+ snprintf(s, sizeof s, "%s %s", str(LANG_DISK_SIZE_INFO), s2);
lcd_puts(0, y++, s);
-
- integer = free / 1024;
- decimal = free % 1024 / 100;
- snprintf(s, sizeof s, str(LANG_DISK_FREE_STAT), integer, decimal);
+
+ output_dyn_value(s2, sizeof s2, free, kbyte_units, true);
+ snprintf(s, sizeof s, "%s %s", str(LANG_DISK_FREE_INFO), s2);
lcd_puts(0, y++, s);
}
lcd_update();
diff --git a/apps/misc.c b/apps/misc.c
index b4a21a1..1024f9b 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -28,6 +28,7 @@
#include "system.h"
#include "timefuncs.h"
#include "screens.h"
+#include "talk.h"
#include "mpeg.h"
#include "mp3_playback.h"
#include "settings.h"
@@ -42,33 +43,67 @@
#define ONE_KILOBYTE 1024
#define ONE_MEGABYTE (1024*1024)
-/* The point of this function would be to return a string of the input data,
- but never longer than 5 columns. Add suffix k and M when suitable...
- Make sure to have space for 6 bytes in the buffer. 5 letters plus the
- terminating zero byte. */
-char *num2max5(unsigned int bytes, char *max5)
+/* Format a large-range value for output, using the appropriate unit so that
+ * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
+ * units) if possible, and 3 significant digits are shown. If a buffer is
+ * given, the result is snprintf()'d into that buffer, otherwise the result is
+ * voiced.*/
+char *output_dyn_value(char *buf, int buf_size, int value,
+ const unsigned char **units, bool bin_scale)
{
- if(bytes < 100000) {
- snprintf(max5, 6, "%5d", bytes);
- return max5;
+ int scale = bin_scale ? 1024 : 1000;
+ int fraction = 0;
+ int unit_no = 0;
+ char tbuf[5];
+
+ while (value >= scale)
+ {
+ fraction = value % scale;
+ value /= scale;
+ unit_no++;
}
- if(bytes < (9999*ONE_KILOBYTE)) {
- snprintf(max5, 6, "%4dk", bytes/ONE_KILOBYTE);
- return max5;
+ if (bin_scale)
+ fraction = fraction * 1000 / 1024;
+
+ if (buf)
+ {
+ if (value >= 100 || !unit_no)
+ snprintf(tbuf, sizeof(tbuf), "%d", value);
+ else if (value >= 10)
+ snprintf(tbuf, sizeof(tbuf), "%d%s%01d", value, str(LANG_POINT),
+ fraction / 100);
+ else
+ snprintf(tbuf, sizeof(tbuf), "%d%s%02d", value, str(LANG_POINT),
+ fraction / 10);
+
+ snprintf(buf, buf_size, "%s %s", tbuf, P2STR(units[unit_no]));
}
- if(bytes < (100*ONE_MEGABYTE)) {
- /* 'XX.XM' is good as long as we're less than 100 megs */
- snprintf(max5, 6, "%2d.%0dM",
- bytes/ONE_MEGABYTE,
- (bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) );
- return max5;
+ else
+ {
+ if (value >= 100 || !unit_no)
+ tbuf[0] = '\0';
+ else if (value >= 10)
+ snprintf(tbuf, sizeof(tbuf), "%01d", fraction / 100);
+ else
+ snprintf(tbuf, sizeof(tbuf), "%02d", fraction / 10);
+
+ /* 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 (strlen(tbuf))
+ {
+ talk_id(LANG_POINT, true);
+ talk_spell(tbuf, true);
+ }
+ talk_id(P2ID(units[unit_no]), true);
}
- snprintf(max5, 6, "%4dM", bytes/ONE_MEGABYTE);
- return max5;
+ return buf;
}
/* Read (up to) a line of text from fd into buffer and return number of bytes
- * read (which may be larger than the number of bytes stored in buffer). If
+ * read (which may be larger than the number of bytes stored in buffer). If
* an error occurs, -1 is returned (and buffer contains whatever could be
* read). A line is terminated by a LF char. Neither LF nor CR chars are
* stored in buffer.
diff --git a/apps/misc.h b/apps/misc.h
index e312248..430afe1 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -19,11 +19,13 @@
#ifndef MISC_H
#define MISC_H
-/* The point of this function would be to return a string of the input data,
- but never longer than 5 columns. Add suffix k and M when suitable...
- Make sure to have space for 6 bytes in the buffer. 5 letters plus the
- terminating zero byte. */
-char *num2max5(unsigned int bytes, char *max5);
+/* Format a large-range value for output, using the appropriate unit so that
+ * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
+ * units) if possible, and 3 significant digits are shown. If a buffer is
+ * given, the result is snprintf()'d into that buffer, otherwise the result is
+ * voiced.*/
+void output_dyn_value(char *buf, int buf_size, int value,
+ const unsigned char **units, bool bin_scale);
/* Read (up to) a line of text from fd into buffer and return number of bytes
* read (which may be larger than the number of bytes stored in buffer). If
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index 0ffa16f..35da6f7 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -248,6 +248,13 @@ bool recording_screen(void)
bool led_state;
int led_delay;
+ const unsigned char *byte_units[] = {
+ ID2P(LANG_BYTE),
+ ID2P(LANG_KILOBYTE),
+ ID2P(LANG_MEGABYTE),
+ ID2P(LANG_GIGABYTE)
+ };
+
cursor = 0;
mpeg_init_recording();
@@ -587,10 +594,13 @@ bool recording_screen(void)
dhours, dminutes);
}
else
+ {
+ output_dyn_value(buf2, sizeof buf2,
+ mpeg_num_recorded_bytes(),
+ byte_units, true);
snprintf(buf, 32, "%s %s",
- str(LANG_RECORDING_SIZE),
- num2max5(mpeg_num_recorded_bytes(),
- buf2));
+ str(LANG_RECORDING_SIZE), buf2);
+ }
}
lcd_puts(0, 1, buf);