summaryrefslogtreecommitdiff
path: root/apps/plugins/calculator.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/calculator.c')
-rw-r--r--apps/plugins/calculator.c91
1 files changed, 46 insertions, 45 deletions
diff --git a/apps/plugins/calculator.c b/apps/plugins/calculator.c
index 607f563b5a..994b066e7b 100644
--- a/apps/plugins/calculator.c
+++ b/apps/plugins/calculator.c
@@ -546,7 +546,7 @@ enum {cal_normal, /* 0, normal status, display result */
546} calStatus; 546} calStatus;
547 547
548/* constant table for CORDIC algorithm */ 548/* constant table for CORDIC algorithm */
549double cordicTable[51][2]= { 549static const double cordicTable[51][2]= {
550 /* pow(2,0) - pow(2,-50) atan(pow(2,0) - atan(pow(2,-50) */ 550 /* pow(2,0) - pow(2,-50) atan(pow(2,0) - atan(pow(2,-50) */
551 {1e+00, 7.853981633974483e-01}, 551 {1e+00, 7.853981633974483e-01},
552 {5e-01, 4.636476090008061e-01}, 552 {5e-01, 4.636476090008061e-01},
@@ -601,21 +601,21 @@ double cordicTable[51][2]= {
601 {8.8817841970012523233890533447265625e-16, 8.881784197001252e-16} 601 {8.8817841970012523233890533447265625e-16, 8.881784197001252e-16}
602}; 602};
603 603
604void doMultiple(double* operandOne, int* powerOne, 604static void doMultiple(double* operandOne, int* powerOne,
605 double operandTwo, int powerTwo); 605 double operandTwo, int powerTwo);
606void doAdd (double* operandOne, int* powerOne, 606static void doAdd (double* operandOne, int* powerOne,
607 double operandTwo, int powerTwo); 607 double operandTwo, int powerTwo);
608void printResult(void); 608static void printResult(void);
609void formatResult(void); 609static void formatResult(void);
610void oneOperand(void); 610static void oneOperand(void);
611 611
612void drawLines(void); 612static void drawLines(void);
613void drawButtons(int group); 613static void drawButtons(int group);
614 614
615/* ----------------------------------------------------------------------- 615/* -----------------------------------------------------------------------
616Handy funtions 616Handy functions
617----------------------------------------------------------------------- */ 617----------------------------------------------------------------------- */
618void cleartypingbuf(void) 618static void cleartypingbuf(void)
619{ 619{
620 int k; 620 int k;
621 for( k=1; k<=(DIGITLEN+1); k++) 621 for( k=1; k<=(DIGITLEN+1); k++)
@@ -623,21 +623,21 @@ void cleartypingbuf(void)
623 typingbuf[0] = ' '; 623 typingbuf[0] = ' ';
624 typingbufPointer = typingbuf+1; 624 typingbufPointer = typingbuf+1;
625} 625}
626void clearbuf(void) 626static void clearbuf(void)
627{ 627{
628 int k; 628 int k;
629 for(k=0;k<18;k++) 629 for(k=0;k<18;k++)
630 buf[k]=' '; 630 buf[k]=' ';
631 buf[18] = 0; 631 buf[18] = 0;
632} 632}
633void clearResult(void) 633static void clearResult(void)
634{ 634{
635 result = 0; 635 result = 0;
636 power = 0; 636 power = 0;
637 modifier = 0.1; 637 modifier = 0.1;
638} 638}
639 639
640void clearInput(void) 640static void clearInput(void)
641{ 641{
642 calStatus = cal_normal; 642 calStatus = cal_normal;
643 clearResult(); 643 clearResult();
@@ -647,25 +647,25 @@ void clearInput(void)
647 drawLines(); 647 drawLines();
648} 648}
649 649
650void clearOperand(void) 650static void clearOperand(void)
651{ 651{
652 operand = 0; 652 operand = 0;
653 operandPower = 0; 653 operandPower = 0;
654} 654}
655 655
656void clearMemTemp(void) 656static void clearMemTemp(void)
657{ 657{
658 memTemp = 0; 658 memTemp = 0;
659 memTempPower = 0; 659 memTempPower = 0;
660} 660}
661 661
662void clearOper(void) 662static void clearOper(void)
663{ 663{
664 oper = ' '; 664 oper = ' ';
665 operInputted = false; 665 operInputted = false;
666} 666}
667 667
668void clearMem(void) 668static void clearMem(void)
669{ 669{
670 clearInput(); 670 clearInput();
671 clearMemTemp(); 671 clearMemTemp();
@@ -674,7 +674,7 @@ void clearMem(void)
674 btn = BUTTON_NONE; 674 btn = BUTTON_NONE;
675} 675}
676 676
677void switchOperands(void) 677static void switchOperands(void)
678{ 678{
679 double tempr = operand; 679 double tempr = operand;
680 int tempp = operandPower; 680 int tempp = operandPower;
@@ -684,7 +684,7 @@ void switchOperands(void)
684 power = tempp; 684 power = tempp;
685} 685}
686 686
687void drawLines(void) 687static void drawLines(void)
688{ 688{
689 int i; 689 int i;
690 rb->lcd_hline(0, LCD_WIDTH, Y_1_POS-1); 690 rb->lcd_hline(0, LCD_WIDTH, Y_1_POS-1);
@@ -694,7 +694,7 @@ void drawLines(void)
694 rb->lcd_vline(X_1_POS+i*REC_WIDTH, Y_1_POS, LCD_HEIGHT); 694 rb->lcd_vline(X_1_POS+i*REC_WIDTH, Y_1_POS, LCD_HEIGHT);
695} 695}
696 696
697void drawButtons(int group) 697static void drawButtons(int group)
698{ 698{
699 int i, j, w, h; 699 int i, j, w, h;
700 for (i = 0; i <= 4; i++){ 700 for (i = 0; i <= 4; i++){
@@ -722,7 +722,7 @@ void drawButtons(int group)
722/* ----------------------------------------------------------------------- 722/* -----------------------------------------------------------------------
723Initiate calculator 723Initiate calculator
724----------------------------------------------------------------------- */ 724----------------------------------------------------------------------- */
725void cal_initial (void) 725static void cal_initial (void)
726{ 726{
727 int w,h; 727 int w,h;
728 728
@@ -761,7 +761,7 @@ void cal_initial (void)
761 in it's private case for sqrt. 761 in it's private case for sqrt.
762 Thanks BlueChip for his intro text and Dave Straayer for the actual name. 762 Thanks BlueChip for his intro text and Dave Straayer for the actual name.
763 ----------------------------------------------------------------------- */ 763 ----------------------------------------------------------------------- */
764double mySqrt(double square) 764static double mySqrt(double square)
765{ 765{
766 int k = 0; 766 int k = 0;
767 double temp = 0; 767 double temp = 0;
@@ -781,7 +781,7 @@ double mySqrt(double square)
781 transcendFunc can do sin,cos,log,exp 781 transcendFunc can do sin,cos,log,exp
782 input parameter is angle 782 input parameter is angle
783----------------------------------------------------------------------- */ 783----------------------------------------------------------------------- */
784void transcendFunc(char* func, double* tt, int* ttPower) 784static void transcendFunc(char* func, double* tt, int* ttPower)
785{ 785{
786 double t = (*tt)*M_PI/180; int tPower = *ttPower; 786 double t = (*tt)*M_PI/180; int tPower = *ttPower;
787 int sign = 1; 787 int sign = 1;
@@ -861,8 +861,8 @@ void transcendFunc(char* func, double* tt, int* ttPower)
861/* ----------------------------------------------------------------------- 861/* -----------------------------------------------------------------------
862 add in scientific number format 862 add in scientific number format
863----------------------------------------------------------------------- */ 863----------------------------------------------------------------------- */
864void doAdd (double* operandOne, int* powerOne, 864static void doAdd (double* operandOne, int* powerOne,
865 double operandTwo, int powerTwo) 865 double operandTwo, int powerTwo)
866{ 866{
867 if ( *powerOne >= powerTwo ){ 867 if ( *powerOne >= powerTwo ){
868 if (*powerOne - powerTwo <= DIGITLEN+1){ 868 if (*powerOne - powerTwo <= DIGITLEN+1){
@@ -891,8 +891,8 @@ void doAdd (double* operandOne, int* powerOne,
891/* ----------------------------------------------------------------------- 891/* -----------------------------------------------------------------------
892multiple in scientific number format 892multiple in scientific number format
893----------------------------------------------------------------------- */ 893----------------------------------------------------------------------- */
894void doMultiple(double* operandOne, int* powerOne, 894static void doMultiple(double* operandOne, int* powerOne,
895 double operandTwo, int powerTwo) 895 double operandTwo, int powerTwo)
896{ 896{
897 (*operandOne) *= operandTwo; 897 (*operandOne) *= operandTwo;
898 (*powerOne) += powerTwo; 898 (*powerOne) += powerTwo;
@@ -901,7 +901,7 @@ void doMultiple(double* operandOne, int* powerOne,
901/* ----------------------------------------------------------------------- 901/* -----------------------------------------------------------------------
902Handles all one operand calculations 902Handles all one operand calculations
903----------------------------------------------------------------------- */ 903----------------------------------------------------------------------- */
904void oneOperand(void) 904static void oneOperand(void)
905{ 905{
906 int k = 0; 906 int k = 0;
907 if (buttonGroup == basicButtons){ 907 if (buttonGroup == basicButtons){
@@ -988,7 +988,7 @@ void oneOperand(void)
988/* ----------------------------------------------------------------------- 988/* -----------------------------------------------------------------------
989Handles all two operands calculations 989Handles all two operands calculations
990----------------------------------------------------------------------- */ 990----------------------------------------------------------------------- */
991void twoOperands(void) 991static void twoOperands(void)
992{ 992{
993 switch(oper){ 993 switch(oper){
994 case '-': 994 case '-':
@@ -1048,7 +1048,7 @@ static void move_with_wrap_and_shift(
1048Print buttons when switching 1st and 2nd 1048Print buttons when switching 1st and 2nd
1049int group = {basicButtons, sciButtons} 1049int group = {basicButtons, sciButtons}
1050----------------------------------------------------------------------- */ 1050----------------------------------------------------------------------- */
1051void printButtonGroups(int group) 1051static void printButtonGroups(int group)
1052{ 1052{
1053 drawButtons(group); 1053 drawButtons(group);
1054 drawLines(); 1054 drawLines();
@@ -1057,7 +1057,7 @@ void printButtonGroups(int group)
1057/* ----------------------------------------------------------------------- 1057/* -----------------------------------------------------------------------
1058flash the currently marked button 1058flash the currently marked button
1059----------------------------------------------------------------------- */ 1059----------------------------------------------------------------------- */
1060void flashButton(void) 1060static void flashButton(void)
1061{ 1061{
1062 int k, w, h; 1062 int k, w, h;
1063 for (k=2;k>0;k--) 1063 for (k=2;k>0;k--)
@@ -1083,7 +1083,8 @@ void flashButton(void)
1083/* ----------------------------------------------------------------------- 1083/* -----------------------------------------------------------------------
1084pos is the position that needs animation. pos = [1~18] 1084pos is the position that needs animation. pos = [1~18]
1085----------------------------------------------------------------------- */ 1085----------------------------------------------------------------------- */
1086void deleteAnimation(int pos) 1086#if defined(CALCULATOR_CLEAR) || defined(CALCULATOR_OPERATORS)
1087static void deleteAnimation(int pos)
1087{ 1088{
1088 int k, w, h, x; 1089 int k, w, h, x;
1089 if (pos<1 || pos >18) 1090 if (pos<1 || pos >18)
@@ -1102,6 +1103,7 @@ void deleteAnimation(int pos)
1102 rb->sleep(HZ/32); 1103 rb->sleep(HZ/32);
1103 } 1104 }
1104} 1105}
1106#endif
1105 1107
1106/* ----------------------------------------------------------------------- 1108/* -----------------------------------------------------------------------
1107result may be one of these formats: 1109result may be one of these formats:
@@ -1114,7 +1116,7 @@ formatResult() change result to standard format: 0.xxxx
1114if result is close to 0, let it be 0; 1116if result is close to 0, let it be 0;
1115if result is close to 1, let it be 0.1 and power++; 1117if result is close to 1, let it be 0.1 and power++;
1116----------------------------------------------------------------------- */ 1118----------------------------------------------------------------------- */
1117void formatResult(void) 1119static void formatResult(void)
1118{ 1120{
1119 int resultsign = SIGN(result); 1121 int resultsign = SIGN(result);
1120 result = ABS(result); 1122 result = ABS(result);
@@ -1160,7 +1162,7 @@ case SCIENTIFIC_FORMAT, let temppower = 1;
1160case temppower > 0: print '.' in the middle 1162case temppower > 0: print '.' in the middle
1161case temppower <= 0: print '.' in the begining 1163case temppower <= 0: print '.' in the begining
1162----------------------------------------------------------------------- */ 1164----------------------------------------------------------------------- */
1163void result2typingbuf(void) 1165static void result2typingbuf(void)
1164{ 1166{
1165 bool haveDot = false; 1167 bool haveDot = false;
1166 char tempchar = 0; 1168 char tempchar = 0;
@@ -1244,7 +1246,7 @@ void result2typingbuf(void)
1244/* ----------------------------------------------------------------------- 1246/* -----------------------------------------------------------------------
1245printResult() generates LCD display. 1247printResult() generates LCD display.
1246----------------------------------------------------------------------- */ 1248----------------------------------------------------------------------- */
1247void printResult(void) 1249static void printResult(void)
1248{ 1250{
1249 int k, w, h; 1251 int k, w, h;
1250 1252
@@ -1321,7 +1323,7 @@ void printResult(void)
1321Process typing buttons: 1-9, '.', sign 1323Process typing buttons: 1-9, '.', sign
1322main operand "result" and typingbuf are processed seperately here. 1324main operand "result" and typingbuf are processed seperately here.
1323----------------------------------------------------------------------- */ 1325----------------------------------------------------------------------- */
1324void typingProcess(void){ 1326static void typingProcess(void){
1325 switch( CAL_BUTTON ){ 1327 switch( CAL_BUTTON ){
1326 case btn_sign: 1328 case btn_sign:
1327 if (calStatus == cal_typing || 1329 if (calStatus == cal_typing ||
@@ -1395,7 +1397,8 @@ void typingProcess(void){
1395Handle delete operation 1397Handle delete operation
1396main operand "result" and typingbuf are processed seperately here. 1398main operand "result" and typingbuf are processed seperately here.
1397----------------------------------------------------------------------- */ 1399----------------------------------------------------------------------- */
1398void doDelete(void){ 1400#ifdef CALCULATOR_CLEAR
1401static void doDelete(void){
1399 deleteAnimation(18); 1402 deleteAnimation(18);
1400 switch(calStatus){ 1403 switch(calStatus){
1401 case cal_dotted: 1404 case cal_dotted:
@@ -1434,10 +1437,11 @@ void doDelete(void){
1434 break; 1437 break;
1435 } 1438 }
1436} 1439}
1440#endif
1437/* ----------------------------------------------------------------------- 1441/* -----------------------------------------------------------------------
1438Handle buttons on basic screen 1442Handle buttons on basic screen
1439----------------------------------------------------------------------- */ 1443----------------------------------------------------------------------- */
1440void basicButtonsProcess(void){ 1444static void basicButtonsProcess(void){
1441 switch (btn) { 1445 switch (btn) {
1442 case CALCULATOR_INPUT: 1446 case CALCULATOR_INPUT:
1443 if (calStatus == cal_error && (CAL_BUTTON != btn_C) ) break; 1447 if (calStatus == cal_error && (CAL_BUTTON != btn_C) ) break;
@@ -1538,7 +1542,7 @@ void basicButtonsProcess(void){
1538/* ----------------------------------------------------------------------- 1542/* -----------------------------------------------------------------------
1539Handle buttons on scientific screen 1543Handle buttons on scientific screen
1540----------------------------------------------------------------------- */ 1544----------------------------------------------------------------------- */
1541void sciButtonsProcess(void){ 1545static void sciButtonsProcess(void){
1542 switch (btn) { 1546 switch (btn) {
1543 case CALCULATOR_INPUT: 1547 case CALCULATOR_INPUT:
1544 if (calStatus == cal_error && (CAL_BUTTON != sci_sci) ) break; 1548 if (calStatus == cal_error && (CAL_BUTTON != sci_sci) ) break;
@@ -1613,7 +1617,7 @@ void sciButtonsProcess(void){
1613move button index 1617move button index
1614Invert display new button, invert back previous button 1618Invert display new button, invert back previous button
1615----------------------------------------------------------------------- */ 1619----------------------------------------------------------------------- */
1616int handleButton(int button){ 1620static int handleButton(int button){
1617 switch(button) 1621 switch(button)
1618 { 1622 {
1619 case CALCULATOR_INPUT: 1623 case CALCULATOR_INPUT:
@@ -1721,9 +1725,6 @@ int handleButton(int button){
1721 } 1725 }
1722 1726
1723 return 0; 1727 return 0;
1724
1725 prev_btn_row = btn_row;
1726 prev_btn_col = btn_col;
1727} 1728}
1728 1729
1729/* ----------------------------------------------------------------------- 1730/* -----------------------------------------------------------------------