From c00fe34a81d87b46019ffd8a6dd3421c8195d4f5 Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Wed, 13 Oct 2010 21:05:50 +0000 Subject: [PATCH] Fix some incorrect colour-to-resistance results. The price is that sometimes the display is subobtimal (like "2000 Ohms" instead of "2 KOhms") Ideally, unit prefixes (K, M,...) should be calculated separately, but the largest resistance we can handle is 99 MOhm, which wouldn't fit in a 32 bit int (using our centiohm internal units) if we didn't cheat. (and technically we could go higher still. white-white-white would be 99 GOhm, but we don't do such high multipliers now) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28272 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/resistor.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/apps/plugins/resistor.c b/apps/plugins/resistor.c index 8bccbefcc8..c5d9cb5fdd 100644 --- a/apps/plugins/resistor.c +++ b/apps/plugins/resistor.c @@ -108,16 +108,16 @@ static struct band_data { { RES_BLACK, "Black", LCD_RGBPACK(0, 0, 0), 0, 100, "Ohms",-1 }, { RES_BROWN, "Brown", LCD_RGBPACK(118, 78, 0), 1, 1000, "Ohms", 1 }, - { RES_RED, "Red", LCD_RGBPACK(255, 0, 0), 2, 10000, "KOhms", 2 }, + { RES_RED, "Red", LCD_RGBPACK(255, 0, 0), 2, 10000, "Ohms", 2 }, { RES_ORANGE, "Orange", LCD_RGBPACK(255, 199, 76), 3, 100, "KOhms",-1 }, { RES_YELLOW, "Yellow", LCD_RGBPACK(255, 255, 0), 4, 1000, "KOhms",-1 }, - { RES_GREEN, "Green", LCD_RGBPACK(0, 128, 0), 5, 10000, "MOhms",-1 }, + { RES_GREEN, "Green", LCD_RGBPACK(0, 128, 0), 5, 10000, "KOhms",-1 }, { RES_BLUE, "Blue", LCD_RGBPACK(0, 0, 255), 6, 100, "MOhms",-1 }, { RES_VIOLET, "Violet", LCD_RGBPACK(153, 51, 255), 7, -1, 0, -1 }, { RES_GREY, "Grey", LCD_RGBPACK(192, 192, 192), 8, -1, 0, -1 }, { RES_WHITE, "White", LCD_RGBPACK(255, 255, 255), 9, -1, 0, -1 }, - { RES_GOLD, "Gold", LCD_RGBPACK(146, 146, 0), -1, 1, "Ohms", 5 }, - { RES_SILVER, "Silver", LCD_RGBPACK(213, 213, 213),-1, 10, "Ohms", 10 }, + { RES_GOLD, "Gold", LCD_RGBPACK(146, 146, 0), -1, 10, "Ohms", 5 }, + { RES_SILVER, "Silver", LCD_RGBPACK(213, 213, 213),-1, 1, "Ohms", 10 }, { RES_NONE, "[None]", -1 ,-1, -1, 0, 20 } }; @@ -291,10 +291,6 @@ static int calculate_resistance(enum color first_band, int multiplier = band_data[third_band].multiplier; int total_resistance_centiunits = (10 * tens + units ) * multiplier; - if(total_resistance_centiunits == 100000) { - total_resistance_centiunits /= 1000; } - /* Kludge, I know, but it fixes the '1000 KOhms' issue */ - unit_abbrev = band_data[third_band].unit; return total_resistance_centiunits; @@ -950,7 +946,7 @@ static void color_to_resistance(void) else { rb->snprintf(total_resistance_str, sizeof(total_resistance_str), - "Resistance: %d.%d %s", + "Resistance: %d.%2.2d %s", total_resistance_centiunits/100, total_resistance_centiunits%100, unit_abbrev);