summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2010-10-13 20:13:39 +0000
committerFrank Gevaerts <frank@gevaerts.be>2010-10-13 20:13:39 +0000
commit29503eea8631348530a22c2e6ef452758821d81e (patch)
tree06a23ebeeb66778bd68251542dff2e898e548ab3 /apps
parentc85ff1c0c95f9bf22e1d1fb4c202e1dcdabbb3db (diff)
downloadrockbox-29503eea8631348530a22c2e6ef452758821d81e.tar.gz
rockbox-29503eea8631348530a22c2e6ef452758821d81e.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/resistor.c80
1 files changed, 19 insertions, 61 deletions
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)
603 603
604 int resistance = 0; 604 int resistance = 0;
605 int rounded_resistance = 0; 605 int rounded_resistance = 0;
606 int temp;
606 int power_rating_in = 0; 607 int power_rating_in = 0;
607 int rounded_power_rating = 0; 608 int rounded_power_rating = 0;
608 int out_int = 0; 609 int out_int = 0;
@@ -737,40 +738,15 @@ void led_resistance_calc(void)
737 738
738 get_power_rating_str(rounded_power_rating); 739 get_power_rating_str(rounded_power_rating);
739 740
740 power_ten = get_power_ten(rounded_resistance); 741 power_ten=0;
741 if(rounded_resistance / powi(10, power_ten) == 1) { 742 temp=rounded_resistance;
742 while(rounded_resistance /powi(10, power_ten) == 1) { 743 while(temp>=100)
743 power_ten--; 744 {
744 } 745 temp/=10;
745 }
746
747 if(rounded_resistance/powi(10, power_ten) != (int)rounded_resistance) {
748 power_ten--; }
749 rounded_resistance /= powi(10, power_ten);
750
751 if(rounded_resistance < 10) {
752 first_band_int = rounded_resistance; }
753 else { first_band_int = rounded_resistance /10; }
754 second_band_int += rounded_resistance % 10;
755
756 if(first_band_int == 10) {
757 first_band_int /= 10;
758 second_band_int = 0;
759 power_ten++; 746 power_ten++;
760 } 747 }
761 748 first_band_int=temp/10;
762 if(first_band_int > 10) { 749 second_band_int=temp%10;
763 int temp;
764 temp = first_band_int /10;
765 second_band_int = first_band_int % 10;
766 first_band_int = temp;
767 }
768 rounded_resistance *= 10;
769
770 if(rounded_resistance >= 1000) {
771 rounded_resistance /= 10; }
772 /*kludge, maybe. But it fixes the problem (100 ohms graphically,
773 1000 ohms in text displayed */
774 750
775 first_band = get_band_rtoc(first_band_int); 751 first_band = get_band_rtoc(first_band_int);
776 second_band = get_band_rtoc(second_band_int); 752 second_band = get_band_rtoc(second_band_int);
@@ -830,6 +806,7 @@ void resistance_to_color(void)
830 bool quit = false; 806 bool quit = false;
831 char kbd_buffer [10]; 807 char kbd_buffer [10];
832 int kbd_input_int; 808 int kbd_input_int;
809 int temp;
833 int in_resistance_int; 810 int in_resistance_int;
834 811
835 int power_ten; 812 int power_ten;
@@ -900,36 +877,17 @@ void resistance_to_color(void)
900 kbd_input_int *= 1000000; 877 kbd_input_int *= 1000000;
901 break; 878 break;
902 } 879 }
903 880
904 power_ten = get_power_ten(kbd_input_int); 881 power_ten=0;
905 if(kbd_input_int / powi(10, power_ten) == 1) { 882 temp=kbd_input_int;
906 while(kbd_input_int /powi(10, power_ten) == 1) { 883 while(temp>=100)
907 power_ten--; 884 {
908 } 885 temp/=10;
909 }
910
911 if(kbd_input_int / powi(10, power_ten) != (int)kbd_input_int) {
912 power_ten--; }
913 kbd_input_int /= powi(10, power_ten);
914
915 if(kbd_input_int < 10) {
916 first_band_int = kbd_input_int; }
917 else { first_band_int = kbd_input_int /10; }
918 second_band_int += kbd_input_int % 10;
919
920 if(first_band_int == 10) {
921 first_band_int /= 10;
922 second_band_int = 0;
923 power_ten++; 886 power_ten++;
924 } 887 }
888 first_band_int=temp/10;
889 second_band_int=temp%10;
925 890
926 if(first_band_int > 10) {
927 int temp;
928 temp = first_band_int /10;
929 second_band_int = first_band_int % 10;
930 first_band_int = temp;
931 }
932
933 first_band = get_band_rtoc(first_band_int); 891 first_band = get_band_rtoc(first_band_int);
934 second_band = get_band_rtoc(second_band_int); 892 second_band = get_band_rtoc(second_band_int);
935 multiplier = get_band_rtoc(power_ten); 893 multiplier = get_band_rtoc(power_ten);