From 29503eea8631348530a22c2e6ef452758821d81e Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Wed, 13 Oct 2010 20:13:39 +0000 Subject: Simplify resistance to colour calculations, removing some bugs in the process. Fixes the bugs that triggered FS#11667 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28269 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/resistor.c | 80 ++++++++++++------------------------------------- 1 file changed, 19 insertions(+), 61 deletions(-) (limited to 'apps/plugins/resistor.c') diff --git a/apps/plugins/resistor.c b/apps/plugins/resistor.c index 006a2c94d1..2cd4a2cb70 100644 --- a/apps/plugins/resistor.c +++ b/apps/plugins/resistor.c @@ -603,6 +603,7 @@ void led_resistance_calc(void) int resistance = 0; int rounded_resistance = 0; + int temp; int power_rating_in = 0; int rounded_power_rating = 0; int out_int = 0; @@ -737,40 +738,15 @@ void led_resistance_calc(void) get_power_rating_str(rounded_power_rating); - power_ten = get_power_ten(rounded_resistance); - if(rounded_resistance / powi(10, power_ten) == 1) { - while(rounded_resistance /powi(10, power_ten) == 1) { - power_ten--; - } - } - - if(rounded_resistance/powi(10, power_ten) != (int)rounded_resistance) { - power_ten--; } - rounded_resistance /= powi(10, power_ten); - - if(rounded_resistance < 10) { - first_band_int = rounded_resistance; } - else { first_band_int = rounded_resistance /10; } - second_band_int += rounded_resistance % 10; - - if(first_band_int == 10) { - first_band_int /= 10; - second_band_int = 0; + power_ten=0; + temp=rounded_resistance; + while(temp>=100) + { + temp/=10; power_ten++; - } - - if(first_band_int > 10) { - int temp; - temp = first_band_int /10; - second_band_int = first_band_int % 10; - first_band_int = temp; - } - rounded_resistance *= 10; - - if(rounded_resistance >= 1000) { - rounded_resistance /= 10; } - /*kludge, maybe. But it fixes the problem (100 ohms graphically, - 1000 ohms in text displayed */ + } + first_band_int=temp/10; + second_band_int=temp%10; first_band = get_band_rtoc(first_band_int); second_band = get_band_rtoc(second_band_int); @@ -830,6 +806,7 @@ void resistance_to_color(void) bool quit = false; char kbd_buffer [10]; int kbd_input_int; + int temp; int in_resistance_int; int power_ten; @@ -900,36 +877,17 @@ void resistance_to_color(void) kbd_input_int *= 1000000; break; } - - power_ten = get_power_ten(kbd_input_int); - if(kbd_input_int / powi(10, power_ten) == 1) { - while(kbd_input_int /powi(10, power_ten) == 1) { - power_ten--; - } - } - - if(kbd_input_int / powi(10, power_ten) != (int)kbd_input_int) { - power_ten--; } - kbd_input_int /= powi(10, power_ten); - - if(kbd_input_int < 10) { - first_band_int = kbd_input_int; } - else { first_band_int = kbd_input_int /10; } - second_band_int += kbd_input_int % 10; - - if(first_band_int == 10) { - first_band_int /= 10; - second_band_int = 0; + + power_ten=0; + temp=kbd_input_int; + while(temp>=100) + { + temp/=10; power_ten++; - } + } + first_band_int=temp/10; + second_band_int=temp%10; - if(first_band_int > 10) { - int temp; - temp = first_band_int /10; - second_band_int = first_band_int % 10; - first_band_int = temp; - } - first_band = get_band_rtoc(first_band_int); second_band = get_band_rtoc(second_band_int); multiplier = get_band_rtoc(power_ten); -- cgit v1.2.3