|
amiconn: apps misc.c, 1.21, 1.22 misc.h, 1.8, 1.9 debug_menu.c, 1.97, 1.98 : msg#00245systems.archos.rockbox.cvs
Update of /cvsroot/rockbox/apps In directory labb:/tmp/cvs-serv5400/apps Modified Files: misc.c misc.h debug_menu.c main_menu.c Log Message: 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). Index: misc.h =================================================================== RCS file: /cvsroot/rockbox/apps/misc.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- misc.h 12 Oct 2004 22:45:01 -0000 1.8 +++ misc.h 31 Jan 2005 00:39:20 -0000 1.9 @@ -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 Index: debug_menu.c =================================================================== RCS file: /cvsroot/rockbox/apps/debug_menu.c,v retrieving revision 1.97 retrieving revision 1.98 diff -u -d -r1.97 -r1.98 --- debug_menu.c 24 Jan 2005 01:39:24 -0000 1.97 +++ debug_menu.c 31 Jan 2005 00:39:20 -0000 1.98 @@ -1268,32 +1268,19 @@ } #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 @@ } 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); Index: main_menu.c =================================================================== RCS file: /cvsroot/rockbox/apps/main_menu.c,v retrieving revision 1.115 retrieving revision 1.116 diff -u -d -r1.115 -r1.116 --- main_menu.c 25 Jan 2005 23:55:42 -0000 1.115 +++ main_menu.c 31 Jan 2005 00:39:20 -0000 1.116 @@ -137,7 +137,7 @@ #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 @@ 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 @@ 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 @@ } 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(); Index: misc.c =================================================================== RCS file: /cvsroot/rockbox/apps/misc.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- misc.c 23 Oct 2004 23:12:48 -0000 1.21 +++ misc.c 31 Jan 2005 00:39:20 -0000 1.22 @@ -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. _______________________________________________ http://cool.haxx.se/mailman/listinfo/rockbox-cvs |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | amiconn: apps/lang english.lang,1.143,1.144 deutsch.lang,1.60,1.61: 00245, cvs |
|---|---|
| Next by Date: | amiconn: apps/recorder recording.c,1.69,1.70: 00245, cvs |
| Previous by Thread: | amiconn: apps/lang english.lang,1.143,1.144 deutsch.lang,1.60,1.61i: 00245, cvs |
| Next by Thread: | amiconn: apps/recorder recording.c,1.69,1.70: 00245, cvs |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |