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
This commit is contained in:
Frank Gevaerts 2010-10-13 20:13:39 +00:00
parent c85ff1c0c9
commit 29503eea86

View file

@ -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;
@ -901,34 +878,15 @@ void resistance_to_color(void)
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++;
}
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_int=temp/10;
second_band_int=temp%10;
first_band = get_band_rtoc(first_band_int);
second_band = get_band_rtoc(second_band_int);