1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 Pengxuan Liu (Isaac)
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 00 01 21 22 23 43 44 45 65 66 67 87 88 89 109110111
24 00 |-----------|-----------|-----------|-----------|-----------|
26 |***********|***********|***********|***********|***********|
27 |***********|***********|***********|***********|***********|
29 12 |-----------|-----------|-----------|-----------|-----------|
30 13 |-----------|-----------|-----------|-----------|-----------| y1
34 23 |-----------|-----------|-----------|-----------|-----------| y2
38 33 |-----------|-----------|-----------|-----------|-----------| y3
42 43 |-----------|-----------|-----------|-----------|-----------| y4
46 53 |-----------|-----------|-----------|-----------|-----------| y5
50 63 |-----------|-----------|-----------|-----------|-----------| y6
54 /*---------------------------------------------------------------------------
56 - Scientific number format core code. Support range 10^-999 ~ 10^999
57 - Number of significant figures up to 10
60 - Right now, only accept "num, operator (+,-,*,/), num, =" input sequence.
61 Input "3, +, 5, -, 2, =", the calculator will only do 5-2 and result = 3
62 You have to input "3, +, 5, =, -, 2, =" to get 3+5-2 = 6
64 - "*,/" have no priority. Actually you can't input 3+5*2 yet.
67 use arrow button to move cursor, "play" button to select, "off" button to exit
68 F1: if typing numbers, it's equal to "Del"; otherwise, equal to "C"
69 F2: circle input "+, -, *, /"
72 "MR" : load temp memory
73 "M+" : add currently display to temp memory
74 "C" : reset calculator
75 ---------------------------------------------------------------------------*/
78 #ifdef HAVE_LCD_BITMAP
86 #define REC_HEIGHT (int)(LCD_HEIGHT / (BUTTON_ROWS + 1))
87 #define REC_WIDTH (int)(LCD_WIDTH / BUTTON_COLS)
89 #define Y_6_POS (LCD_HEIGHT) /* Leave room for the border */
90 #define Y_5_POS (Y_6_POS - REC_HEIGHT) /* y5 = 53 */
91 #define Y_4_POS (Y_5_POS - REC_HEIGHT) /* y4 = 43 */
92 #define Y_3_POS (Y_4_POS - REC_HEIGHT) /* y3 = 33 */
93 #define Y_2_POS (Y_3_POS - REC_HEIGHT) /* y2 = 23 */
94 #define Y_1_POS (Y_2_POS - REC_HEIGHT) /* y1 = 13 */
95 #define Y_0_POS 0 /* y0 = 0 */
97 #define X_0_POS 0 /* x0 = 0 */
98 #define X_1_POS (X_0_POS + REC_WIDTH) /* x1 = 22 */
99 #define X_2_POS (X_1_POS + REC_WIDTH) /* x2 = 44 */
100 #define X_3_POS (X_2_POS + REC_WIDTH) /* x3 = 66 */
101 #define X_4_POS (X_3_POS + REC_WIDTH) /* x4 = 88 */
102 #define X_5_POS (X_4_POS + REC_WIDTH) /* x5 = 110, column 111 left blank */
104 #define SIGN(x) ((x)<0?-1:1)
106 /* variable button definitions */
107 #if CONFIG_KEYPAD == RECORDER_PAD
108 #define CALCULATOR_LEFT BUTTON_LEFT
109 #define CALCULATOR_RIGHT BUTTON_RIGHT
110 #define CALCULATOR_UP BUTTON_UP
111 #define CALCULATOR_DOWN BUTTON_DOWN
112 #define CALCULATOR_QUIT BUTTON_OFF
113 #define CALCULATOR_INPUT BUTTON_PLAY
114 #define CALCULATOR_CALC BUTTON_F3
115 #define CALCULATOR_OPERATORS BUTTON_F2
116 #define CALCULATOR_CLEAR BUTTON_F1
118 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
119 #define CALCULATOR_LEFT BUTTON_LEFT
120 #define CALCULATOR_RIGHT BUTTON_RIGHT
121 #define CALCULATOR_UP BUTTON_UP
122 #define CALCULATOR_DOWN BUTTON_DOWN
123 #define CALCULATOR_QUIT BUTTON_OFF
124 #define CALCULATOR_INPUT BUTTON_SELECT
125 #define CALCULATOR_CALC BUTTON_F3
126 #define CALCULATOR_OPERATORS BUTTON_F2
127 #define CALCULATOR_CLEAR BUTTON_F1
129 #elif CONFIG_KEYPAD == ONDIO_PAD
130 #define CALCULATOR_LEFT BUTTON_LEFT
131 #define CALCULATOR_RIGHT BUTTON_RIGHT
132 #define CALCULATOR_UP BUTTON_UP
133 #define CALCULATOR_DOWN BUTTON_DOWN
134 #define CALCULATOR_QUIT BUTTON_OFF
135 #define CALCULATOR_INPUT_CALC_PRE BUTTON_MENU
136 #define CALCULATOR_INPUT (BUTTON_MENU | BUTTON_REL)
137 #define CALCULATOR_CALC (BUTTON_MENU | BUTTON_REPEAT)
139 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
140 (CONFIG_KEYPAD == IRIVER_H300_PAD)
141 #define CALCULATOR_LEFT BUTTON_LEFT
142 #define CALCULATOR_RIGHT BUTTON_RIGHT
143 #define CALCULATOR_UP BUTTON_UP
144 #define CALCULATOR_DOWN BUTTON_DOWN
145 #define CALCULATOR_QUIT BUTTON_OFF
146 #define CALCULATOR_INPUT BUTTON_SELECT
147 #define CALCULATOR_CALC BUTTON_ON
148 #define CALCULATOR_OPERATORS BUTTON_MODE
149 #define CALCULATOR_CLEAR BUTTON_REC
151 #define CALCULATOR_RC_QUIT BUTTON_RC_STOP
153 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
154 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
155 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
157 #define CALCULATOR_LEFT BUTTON_LEFT
158 #define CALCULATOR_RIGHT BUTTON_RIGHT
159 #define CALCULATOR_UP_W_SHIFT BUTTON_SCROLL_BACK
160 #define CALCULATOR_DOWN_W_SHIFT BUTTON_SCROLL_FWD
161 #define CALCULATOR_QUIT BUTTON_MENU
162 #define CALCULATOR_INPUT BUTTON_SELECT
163 #define CALCULATOR_CALC BUTTON_PLAY
165 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
167 #define CALCULATOR_LEFT BUTTON_LEFT
168 #define CALCULATOR_RIGHT BUTTON_RIGHT
169 #define CALCULATOR_UP BUTTON_UP
170 #define CALCULATOR_DOWN BUTTON_DOWN
171 #define CALCULATOR_QUIT BUTTON_POWER
172 #define CALCULATOR_INPUT BUTTON_SELECT
173 #define CALCULATOR_CALC BUTTON_PLAY
174 #define CALCULATOR_CLEAR BUTTON_REC
176 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
178 #define CALCULATOR_LEFT BUTTON_LEFT
179 #define CALCULATOR_RIGHT BUTTON_RIGHT
180 #define CALCULATOR_UP BUTTON_UP
181 #define CALCULATOR_DOWN BUTTON_DOWN
182 #define CALCULATOR_QUIT BUTTON_POWER
183 #define CALCULATOR_INPUT BUTTON_SELECT
184 #define CALCULATOR_CALC BUTTON_MENU
185 #define CALCULATOR_CLEAR BUTTON_A
187 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
188 #define CALCULATOR_LEFT BUTTON_LEFT
189 #define CALCULATOR_RIGHT BUTTON_RIGHT
190 #define CALCULATOR_UP BUTTON_UP
191 #define CALCULATOR_DOWN BUTTON_DOWN
192 #define CALCULATOR_UP_W_SHIFT BUTTON_SCROLL_BACK
193 #define CALCULATOR_DOWN_W_SHIFT BUTTON_SCROLL_FWD
194 #define CALCULATOR_QUIT BUTTON_POWER
195 #define CALCULATOR_INPUT_CALC_PRE BUTTON_SELECT
196 #define CALCULATOR_INPUT (BUTTON_SELECT|BUTTON_REL)
197 #define CALCULATOR_CALC (BUTTON_SELECT|BUTTON_REPEAT)
198 #define CALCULATOR_CLEAR BUTTON_REC
200 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
201 #define CALCULATOR_LEFT BUTTON_LEFT
202 #define CALCULATOR_RIGHT BUTTON_RIGHT
203 #define CALCULATOR_UP BUTTON_UP
204 #define CALCULATOR_DOWN BUTTON_DOWN
205 #define CALCULATOR_QUIT BUTTON_POWER
206 #define CALCULATOR_INPUT_CALC_PRE BUTTON_SELECT
207 #define CALCULATOR_INPUT (BUTTON_SELECT|BUTTON_REL)
208 #define CALCULATOR_CALC (BUTTON_SELECT|BUTTON_REPEAT)
210 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
211 #define CALCULATOR_LEFT BUTTON_LEFT
212 #define CALCULATOR_RIGHT BUTTON_RIGHT
213 #define CALCULATOR_UP BUTTON_UP
214 #define CALCULATOR_DOWN BUTTON_DOWN
215 #define CALCULATOR_UP_W_SHIFT BUTTON_SCROLL_BACK
216 #define CALCULATOR_DOWN_W_SHIFT BUTTON_SCROLL_FWD
217 #define CALCULATOR_QUIT (BUTTON_HOME|BUTTON_REPEAT)
218 #define CALCULATOR_INPUT_CALC_PRE BUTTON_SELECT
219 #define CALCULATOR_INPUT (BUTTON_SELECT|BUTTON_REL)
220 #define CALCULATOR_CALC (BUTTON_SELECT|BUTTON_REPEAT)
221 #define CALCULATOR_CLEAR BUTTON_HOME
224 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
225 #define CALCULATOR_LEFT BUTTON_LEFT
226 #define CALCULATOR_RIGHT BUTTON_RIGHT
227 #define CALCULATOR_UP BUTTON_UP
228 #define CALCULATOR_DOWN BUTTON_DOWN
229 #define CALCULATOR_QUIT BUTTON_POWER
230 #define CALCULATOR_INPUT_CALC_PRE BUTTON_SELECT
231 #define CALCULATOR_INPUT (BUTTON_SELECT|BUTTON_REL)
232 #define CALCULATOR_CALC (BUTTON_SELECT|BUTTON_REPEAT)
233 #define CALCULATOR_CLEAR BUTTON_HOME
235 #elif (CONFIG_KEYPAD == SANSA_M200_PAD)
236 #define CALCULATOR_LEFT BUTTON_LEFT
237 #define CALCULATOR_RIGHT BUTTON_RIGHT
238 #define CALCULATOR_UP BUTTON_UP
239 #define CALCULATOR_DOWN BUTTON_DOWN
240 #define CALCULATOR_QUIT BUTTON_POWER
241 #define CALCULATOR_INPUT_CALC_PRE BUTTON_SELECT
242 #define CALCULATOR_INPUT (BUTTON_SELECT|BUTTON_REL)
243 #define CALCULATOR_CALC (BUTTON_SELECT|BUTTON_REPEAT)
244 #define CALCULATOR_CLEAR (BUTTON_SELECT|BUTTON_UP)
246 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
248 #define CALCULATOR_LEFT BUTTON_LEFT
249 #define CALCULATOR_RIGHT BUTTON_RIGHT
250 #define CALCULATOR_UP BUTTON_SCROLL_UP
251 #define CALCULATOR_DOWN BUTTON_SCROLL_DOWN
252 #define CALCULATOR_QUIT BUTTON_POWER
253 #define CALCULATOR_INPUT_CALC_PRE BUTTON_PLAY
254 #define CALCULATOR_INPUT (BUTTON_PLAY | BUTTON_REL)
255 #define CALCULATOR_CALC (BUTTON_PLAY | BUTTON_REPEAT)
256 #define CALCULATOR_CLEAR BUTTON_REW
258 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
260 #define CALCULATOR_LEFT BUTTON_LEFT
261 #define CALCULATOR_RIGHT BUTTON_RIGHT
262 #define CALCULATOR_UP BUTTON_UP
263 #define CALCULATOR_DOWN BUTTON_DOWN
264 #define CALCULATOR_QUIT BUTTON_BACK
265 #define CALCULATOR_INPUT BUTTON_SELECT
266 #define CALCULATOR_CALC BUTTON_MENU
267 #define CALCULATOR_CLEAR BUTTON_PLAY
269 #elif (CONFIG_KEYPAD == MROBE100_PAD)
271 #define CALCULATOR_LEFT BUTTON_LEFT
272 #define CALCULATOR_RIGHT BUTTON_RIGHT
273 #define CALCULATOR_UP BUTTON_UP
274 #define CALCULATOR_DOWN BUTTON_DOWN
275 #define CALCULATOR_QUIT BUTTON_POWER
276 #define CALCULATOR_INPUT BUTTON_SELECT
277 #define CALCULATOR_CALC BUTTON_MENU
278 #define CALCULATOR_CLEAR BUTTON_DISPLAY
280 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
282 #define CALCULATOR_LEFT BUTTON_RC_REW
283 #define CALCULATOR_RIGHT BUTTON_RC_FF
284 #define CALCULATOR_UP BUTTON_RC_VOL_UP
285 #define CALCULATOR_DOWN BUTTON_RC_VOL_DOWN
286 #define CALCULATOR_QUIT BUTTON_RC_REC
287 #define CALCULATOR_INPUT BUTTON_RC_PLAY
288 #define CALCULATOR_CALC BUTTON_RC_MODE
289 #define CALCULATOR_CLEAR BUTTON_RC_MENU
291 #define CALCULATOR_RC_QUIT BUTTON_REC
293 #elif (CONFIG_KEYPAD == COWOND2_PAD)
295 #define CALCULATOR_QUIT BUTTON_POWER
296 #define CALCULATOR_CLEAR BUTTON_MENU
298 #elif CONFIG_KEYPAD == IAUDIO67_PAD
300 #define CALCULATOR_LEFT BUTTON_LEFT
301 #define CALCULATOR_RIGHT BUTTON_RIGHT
302 #define CALCULATOR_UP BUTTON_VOLUP
303 #define CALCULATOR_DOWN BUTTON_VOLDOWN
304 #define CALCULATOR_QUIT BUTTON_POWER
305 #define CALCULATOR_INPUT BUTTON_PLAY
306 #define CALCULATOR_CALC BUTTON_MENU
307 #define CALCULATOR_CLEAR BUTTON_STOP
309 #define CALCULATOR_RC_QUIT (BUTTON_MENU|BUTTON_PLAY)
311 #elif (CONFIG_KEYPAD == CREATIVEZVM_PAD)
313 #define CALCULATOR_LEFT BUTTON_LEFT
314 #define CALCULATOR_RIGHT BUTTON_RIGHT
315 #define CALCULATOR_UP BUTTON_UP
316 #define CALCULATOR_DOWN BUTTON_DOWN
317 #define CALCULATOR_QUIT BUTTON_BACK
318 #define CALCULATOR_INPUT BUTTON_SELECT
319 #define CALCULATOR_CALC BUTTON_MENU
320 #define CALCULATOR_CLEAR BUTTON_PLAY
322 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
324 #define CALCULATOR_LEFT BUTTON_LEFT
325 #define CALCULATOR_RIGHT BUTTON_RIGHT
326 #define CALCULATOR_UP BUTTON_UP
327 #define CALCULATOR_DOWN BUTTON_DOWN
328 #define CALCULATOR_QUIT BUTTON_POWER
329 #define CALCULATOR_INPUT BUTTON_SELECT
330 #define CALCULATOR_CALC BUTTON_MENU
331 #define CALCULATOR_CLEAR BUTTON_VIEW
333 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
335 #define CALCULATOR_QUIT BUTTON_POWER
336 #define CALCULATOR_CLEAR BUTTON_MENU
338 #elif (CONFIG_KEYPAD == ONDAVX777_PAD)
339 #define CALCULATOR_QUIT BUTTON_POWER
341 #elif CONFIG_KEYPAD == MROBE500_PAD
342 #define CALCULATOR_QUIT BUTTON_POWER
344 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
346 #define CALCULATOR_LEFT BUTTON_LEFT
347 #define CALCULATOR_RIGHT BUTTON_RIGHT
348 #define CALCULATOR_UP BUTTON_UP
349 #define CALCULATOR_DOWN BUTTON_DOWN
350 #define CALCULATOR_QUIT BUTTON_REC
351 #define CALCULATOR_INPUT BUTTON_PLAY
352 #define CALCULATOR_CALC BUTTON_FFWD
353 #define CALCULATOR_CLEAR BUTTON_REW
356 #error No keymap defined!
359 #ifdef HAVE_TOUCHSCREEN
360 #ifndef CALCULATOR_LEFT
361 #define CALCULATOR_LEFT BUTTON_MIDLEFT
363 #ifndef CALCULATOR_RIGHT
364 #define CALCULATOR_RIGHT BUTTON_MIDRIGHT
366 #ifndef CALCULATOR_UP
367 #define CALCULATOR_UP BUTTON_TOPMIDDLE
369 #ifndef CALCULATOR_DOWN
370 #define CALCULATOR_DOWN BUTTON_BOTTOMMIDDLE
372 #ifndef CALCULATOR_CALC
373 #define CALCULATOR_CALC BUTTON_BOTTOMRIGHT
375 #ifndef CALCULATOR_INPUT
376 #define CALCULATOR_INPUT BUTTON_CENTER
378 #ifndef CALCULATOR_CLEAR
379 #define CALCULATOR_CLEAR BUTTON_TOPRIGHT
382 #include "lib/pluginlib_touchscreen.h"
383 static struct ts_raster calc_raster
= { X_0_POS
, Y_1_POS
,
384 BUTTON_COLS
*REC_WIDTH
, BUTTON_ROWS
*REC_HEIGHT
, REC_WIDTH
, REC_HEIGHT
};
392 unsigned char* buttonChar
[2][5][5] = {
393 { { "MR" , "M+" , "2nd" , "CE" , "C" },
394 { "7" , "8" , "9" , "/" , "sqr" },
395 { "4" , "5" , "6" , "*" , "x^2" },
396 { "1" , "2" , "3" , "-" , "1/x" },
397 { "0" , "+/-", "." , "+" , "=" } },
399 { { "n!" , "PI" , "1st" , "sin" , "asi" },
400 { "7" , "8" , "9" , "cos" , "aco" },
401 { "4" , "5" , "6" , "tan" , "ata" },
402 { "1" , "2" , "3" , "ln" , "e^x" },
403 { "0" , "+/-", "." , "log" , "x^y" } }
406 enum { btn_MR
, btn_M
, btn_bas
, btn_CE
, btn_C
,
407 btn_7
, btn_8
, btn_9
, btn_div
, btn_sqr
,
408 btn_4
, btn_5
, btn_6
, btn_time
, btn_square
,
409 btn_1
, btn_2
, btn_3
, btn_minus
, btn_rec
,
410 btn_0
, btn_sign
, btn_dot
, btn_add
, btn_equal
413 enum { sci_fac
, sci_pi
, sci_sci
, sci_sin
, sci_asin
,
414 sci_7
, sci_8
, sci_9
, sci_cos
, sci_acos
,
415 sci_4
, sci_5
, sci_6
, sci_tan
, sci_atan
,
416 sci_1
, sci_2
, sci_3
, sci_ln
, sci_exp
,
417 sci_0
, sci_sign
, sci_dot
, sci_log
, sci_xy
420 #define MINIMUM 0.000000000001 /* e-12 */
422 /* 123456789abcdef */
424 #define DIGITLEN 10 /* must <= 10 */
425 #define SCIENTIFIC_FORMAT ( power < -(DIGITLEN-3) || power > (DIGITLEN))
426 /* 0.000 00000 0001 */
428 /* DIGITLEN 12345 6789a bcdef */
429 /* power 12 34567 89abc def */
430 /* 10^- 123 45678 9abcd ef */
432 unsigned char buf
[19];/* 18 bytes of output line,
434 buf[1] = 'M' if memTemp is not 0
438 buf[2]-buf[12] or buf[3]-buf[13] = result;
440 buf[13] or buf[14] -buf[17] = power;
444 buf[7]-buf[17] = result;
448 unsigned char typingbuf
[DIGITLEN
+2];/* byte 0 is sign or ' ',
449 byte 1~DIGITLEN are num and '.'
450 byte (DIGITLEN+1) is '\0' */
451 unsigned char* typingbufPointer
= typingbuf
;
453 double result
= 0; /* main operand, format 0.xxxxx */
454 int power
= 0; /* 10^power */
455 double modifier
= 0.1; /* position of next input */
456 double operand
= 0; /* second operand, format 0.xxxxx */
457 int operandPower
= 0; /* 10^power of second operand */
458 char oper
= ' '; /* operators: + - * / */
459 bool operInputted
= false; /* false: do calculation first and
461 true: just replace current oper */
463 double memTemp
= 0; /* temp memory */
464 int memTempPower
= 0; /* 10^^power of memTemp */
466 int btn_row
, btn_col
; /* current position index for button */
467 int prev_btn_row
, prev_btn_col
; /* previous cursor position */
468 #define CAL_BUTTON (btn_row*5+btn_col)
470 int btn
= BUTTON_NONE
;
471 int lastbtn
= BUTTON_NONE
;
473 /* Status of calculator */
474 enum {cal_normal
, /* 0, normal status, display result */
475 cal_typing
, /* 1, currently typing, dot hasn't been typed */
476 cal_dotted
, /* 2, currently typing, dot already has been typed. */
482 /* constant table for CORDIC algorithm */
483 double cordicTable
[51][2]= {
484 /* pow(2,0) - pow(2,-50) atan(pow(2,0) - atan(pow(2,-50) */
485 {1e+00, 7.853981633974483e-01},
486 {5e-01, 4.636476090008061e-01},
487 {2.5e-01, 2.449786631268641e-01},
488 {1.25e-01, 1.243549945467614e-01},
489 {6.25e-02, 6.241880999595735e-02},
490 {3.125e-02, 3.123983343026828e-02},
491 {1.5625e-02, 1.562372862047683e-02},
492 {7.8125e-03, 7.812341060101111e-03},
493 {3.90625e-03, 3.906230131966972e-03},
494 {1.953125e-03, 1.953122516478819e-03},
495 {9.765625e-04, 9.765621895593195e-04},
496 {4.8828125e-04, 4.882812111948983e-04},
497 {2.44140625e-04, 2.441406201493618e-04},
498 {1.220703125e-04, 1.220703118936702e-04},
499 {6.103515625e-05, 6.103515617420877e-05},
500 {3.0517578125e-05, 3.051757811552610e-05},
501 {1.52587890625e-05, 1.525878906131576e-05},
502 {7.62939453125e-06, 7.629394531101970e-06},
503 {3.814697265625e-06, 3.814697265606496e-06},
504 {1.9073486328125e-06, 1.907348632810187e-06},
505 {9.5367431640625e-07, 9.536743164059608e-07},
506 {4.76837158203125e-07, 4.768371582030888e-07},
507 {2.384185791015625e-07, 2.384185791015580e-07},
508 {1.1920928955078125e-07, 1.192092895507807e-07},
509 {5.9604644775390625e-08, 5.960464477539055e-08},
510 {2.98023223876953125e-08, 2.980232238769530e-08},
511 {1.490116119384765625e-08, 1.490116119384765e-08},
512 {7.450580596923828125e-09, 7.450580596923828e-09},
513 {3.7252902984619140625e-09, 3.725290298461914e-09},
514 {1.86264514923095703125e-09, 1.862645149230957e-09},
515 {9.31322574615478515625e-10, 9.313225746154785e-10},
516 {4.656612873077392578125e-10, 4.656612873077393e-10},
517 {2.3283064365386962890625e-10, 2.328306436538696e-10},
518 {1.16415321826934814453125e-10, 1.164153218269348e-10},
519 {5.82076609134674072265625e-11, 5.820766091346741e-11},
520 {2.910383045673370361328125e-11, 2.910383045673370e-11},
521 {1.4551915228366851806640625e-11, 1.455191522836685e-11},
522 {7.2759576141834259033203125e-12, 7.275957614183426e-12},
523 {3.63797880709171295166015625e-12, 3.637978807091713e-12},
524 {1.818989403545856475830078125e-12, 1.818989403545856e-12},
525 {9.094947017729282379150390625e-13, 9.094947017729282e-13},
526 {4.5474735088646411895751953125e-13, 4.547473508864641e-13},
527 {2.27373675443232059478759765625e-13, 2.273736754432321e-13},
528 {1.136868377216160297393798828125e-13, 1.136868377216160e-13},
529 {5.684341886080801486968994140625e-14, 5.684341886080801e-14},
530 {2.8421709430404007434844970703125e-14, 2.842170943040401e-14},
531 {1.42108547152020037174224853515625e-14, 1.421085471520200e-14},
532 {7.10542735760100185871124267578125e-15, 7.105427357601002e-15},
533 {3.552713678800500929355621337890625e-15, 3.552713678800501e-15},
534 {1.7763568394002504646778106689453125e-15, 1.776356839400250e-15},
535 {8.8817841970012523233890533447265625e-16, 8.881784197001252e-16}
538 void doMultiple(double* operandOne
, int* powerOne
,
539 double operandTwo
, int powerTwo
);
540 void doAdd (double* operandOne
, int* powerOne
,
541 double operandTwo
, int powerTwo
);
542 void printResult(void);
543 void formatResult(void);
544 void oneOperand(void);
546 void drawLines(void);
547 void drawButtons(int group
);
549 /* -----------------------------------------------------------------------
551 ----------------------------------------------------------------------- */
552 void cleartypingbuf(void)
555 for( k
=1; k
<=(DIGITLEN
+1); k
++)
558 typingbufPointer
= typingbuf
+1;
567 void clearResult(void)
574 void clearInput(void)
576 calStatus
= cal_normal
;
579 rb
->lcd_clear_display();
580 drawButtons(buttonGroup
);
584 void clearOperand(void)
590 void clearMemTemp(void)
599 operInputted
= false;
611 void switchOperands(void)
613 double tempr
= operand
;
614 int tempp
= operandPower
;
616 operandPower
= power
;
624 rb
->lcd_hline(0, LCD_WIDTH
, Y_1_POS
-1);
625 for (i
= 0; i
< 5 ; i
++)
626 rb
->lcd_hline(0, LCD_WIDTH
, Y_1_POS
+i
*REC_HEIGHT
);
627 for (i
= 0; i
< 4 ; i
++)
628 rb
->lcd_vline(X_1_POS
+i
*REC_WIDTH
, Y_1_POS
, LCD_HEIGHT
);
631 void drawButtons(int group
)
634 for (i
= 0; i
<= 4; i
++){
635 for (j
= 0; j
<= 4; j
++){
636 rb
->lcd_getstringsize( buttonChar
[group
][i
][j
],&w
,&h
);
637 if (i
== btn_row
&& j
== btn_col
) /* selected item */
638 rb
->lcd_set_drawmode(DRMODE_SOLID
);
640 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
641 rb
->lcd_fillrect( X_0_POS
+ j
*REC_WIDTH
,
642 Y_1_POS
+ i
*REC_HEIGHT
,
643 REC_WIDTH
, REC_HEIGHT
+1);
644 if (i
== btn_row
&& j
== btn_col
) /* selected item */
645 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
647 rb
->lcd_set_drawmode(DRMODE_SOLID
);
648 rb
->lcd_putsxy( X_0_POS
+ j
*REC_WIDTH
+ (REC_WIDTH
- w
)/2,
649 Y_1_POS
+ i
*REC_HEIGHT
+ (REC_HEIGHT
- h
)/2 + 1,
650 buttonChar
[group
][i
][j
] );
653 rb
->lcd_set_drawmode(DRMODE_SOLID
);
656 /* -----------------------------------------------------------------------
658 ----------------------------------------------------------------------- */
659 void cal_initial (void)
663 rb
->lcd_getstringsize("2nd",&w
,&h
);
664 if (w
> REC_WIDTH
|| h
> REC_HEIGHT
)
665 rb
->lcd_setfont(FONT_SYSFIXED
);
667 rb
->lcd_clear_display();
669 #ifdef CALCULATOR_OPERATORS
670 /* basic operators are available through separate button */
671 buttonGroup
= sciButtons
;
673 buttonGroup
= basicButtons
;
676 /* initially, invert button "5" */
679 prev_btn_row
= btn_row
;
680 prev_btn_col
= btn_col
;
681 drawButtons(buttonGroup
);
685 /* initial mem and output display*/
689 /* clear button queue */
690 rb
->button_clear_queue();
693 /* -----------------------------------------------------------------------
694 mySqrt uses Heron's algorithm, which is the Newtone-Raphson algorhitm
695 in it's private case for sqrt.
696 Thanks BlueChip for his intro text and Dave Straayer for the actual name.
697 ----------------------------------------------------------------------- */
698 double mySqrt(double square
)
702 double root
= ABS(square
+1)/2;
704 while( ABS(root
- temp
) > MINIMUM
){
706 root
= (square
/temp
+ temp
)/2;
708 if (k
>10000) return 0;
713 /* -----------------------------------------------------------------------
714 transcendFunc uses CORDIC (COordinate Rotation DIgital Computer) method
715 transcendFunc can do sin,cos,log,exp
716 input parameter is angle
717 ----------------------------------------------------------------------- */
718 void transcendFunc(char* func
, double* tt
, int* ttPower
)
720 double t
= (*tt
)*M_PI
/180; int tPower
= *ttPower
;
722 int n
= 50; /* n <=50, tables are all <= 50 */
724 double x
,y
,z
,xt
,yt
,zt
;
727 calStatus
= cal_normal
;
731 calStatus
= cal_error
;
735 calStatus
= cal_normal
;
737 if( func
[0] =='s' || func
[0] =='S'|| func
[0] =='t' || func
[0] =='T')
740 /* if( func[0] =='c' || func[0] =='C') */
754 while (t
> j
*M_TWOPI
) {j
++;}
756 if (M_PI_2
< t
&& t
< 3*M_PI_2
){
758 if (func
[0] =='c' || func
[0] =='C')
760 else if (func
[0] =='t' || func
[0] =='T')
763 else if ( 3*M_PI_2
<= t
&& t
<= M_TWOPI
)
766 x
= 0.60725293500888; y
= 0; z
= t
;
768 xt
= x
- SIGN(z
) * y
*cordicTable
[j
-1][0];
769 yt
= y
+ SIGN(z
) * x
*cordicTable
[j
-1][0];
770 zt
= z
- SIGN(z
) * cordicTable
[j
-1][1];
775 if( func
[0] =='s' || func
[0] =='S') {
779 else if( func
[0] =='c' || func
[0] =='C') {
783 else /*if( func[0] =='t' || func[0] =='T')*/ {
784 if(t
==M_PI_2
||t
==-M_PI_2
){
785 calStatus
= cal_error
;
795 /* -----------------------------------------------------------------------
796 add in scientific number format
797 ----------------------------------------------------------------------- */
798 void doAdd (double* operandOne
, int* powerOne
,
799 double operandTwo
, int powerTwo
)
801 if ( *powerOne
>= powerTwo
){
802 if (*powerOne
- powerTwo
<= DIGITLEN
+1){
803 while (powerTwo
< *powerOne
){
807 *operandOne
+= operandTwo
;
809 /*do nothing if operandTwo is too small*/
812 if (powerTwo
- *powerOne
<= DIGITLEN
+1){
813 while(powerTwo
> *powerOne
){
817 (*operandOne
) += operandTwo
;
819 else{/* simply copy operandTwo if operandOne is too small */
820 *operandOne
= operandTwo
;
821 *powerOne
= powerTwo
;
825 /* -----------------------------------------------------------------------
826 multiple in scientific number format
827 ----------------------------------------------------------------------- */
828 void doMultiple(double* operandOne
, int* powerOne
,
829 double operandTwo
, int powerTwo
)
831 (*operandOne
) *= operandTwo
;
832 (*powerOne
) += powerTwo
;
835 /* -----------------------------------------------------------------------
836 Handles all one operand calculations
837 ----------------------------------------------------------------------- */
838 void oneOperand(void)
841 if (buttonGroup
== basicButtons
){
845 calStatus
= cal_error
;
848 result
= (mySqrt(result
*10))/10;
849 power
= (power
+1) / 2;
852 result
= mySqrt(result
);
855 calStatus
= cal_normal
;
861 calStatus
= cal_normal
;
866 calStatus
= cal_error
;
870 calStatus
= cal_normal
;
874 calStatus
= cal_toDo
;
875 break; /* just for the safety */
878 else{ /* sciButtons */
881 transcendFunc("sin", &result
, &power
);
884 transcendFunc("cos", &result
, &power
);
887 transcendFunc("tan", &result
, &power
);
890 if (power
<0 || power
>8 || result
<0 )
891 calStatus
= cal_error
;
892 else if(result
== 0) {
901 if ( ( result
- (int)result
) > MINIMUM
)
902 calStatus
= cal_error
;
904 k
= result
; result
= 1;
906 doMultiple(&result
, &power
, k
, 0);
910 calStatus
= cal_normal
;
915 calStatus
= cal_toDo
;
916 break; /* just for the safety */
922 /* -----------------------------------------------------------------------
923 Handles all two operands calculations
924 ----------------------------------------------------------------------- */
925 void twoOperands(void)
929 doAdd(&operand
, &operandPower
, -result
, power
);
932 doAdd(&operand
, &operandPower
, result
, power
);
935 doMultiple(&operand
, &operandPower
, result
, power
);
938 if ( ABS(result
) > MINIMUM
){
939 doMultiple(&operand
, &operandPower
, 1/result
, -power
);
942 calStatus
= cal_error
;
945 switchOperands(); /* counter switchOperands() below */
952 /* First, increases *dimen1 by dimen1_delta modulo dimen1_modulo.
953 If dimen1 wraps, increases *dimen2 by dimen2_delta modulo dimen2_modulo.
955 static void move_with_wrap_and_shift(
956 int *dimen1
, int dimen1_delta
, int dimen1_modulo
,
957 int *dimen2
, int dimen2_delta
, int dimen2_modulo
)
959 bool wrapped
= false;
961 *dimen1
+= dimen1_delta
;
964 *dimen1
= dimen1_modulo
- 1;
967 else if (*dimen1
>= dimen1_modulo
)
975 /* Make the dividend always positive to be sure about the result.
976 Adding dimen2_modulo does not change it since we do it modulo. */
977 *dimen2
= (*dimen2
+ dimen2_modulo
+ dimen2_delta
) % dimen2_modulo
;
981 /* -----------------------------------------------------------------------
982 Print buttons when switching 1st and 2nd
983 int group = {basicButtons, sciButtons}
984 ----------------------------------------------------------------------- */
985 void printButtonGroups(int group
)
991 /* -----------------------------------------------------------------------
992 flash the currently marked button
993 ----------------------------------------------------------------------- */
994 void flashButton(void)
999 rb
->lcd_getstringsize( buttonChar
[buttonGroup
][btn_row
][btn_col
],&w
,&h
);
1000 rb
->lcd_set_drawmode(DRMODE_SOLID
|(k
==1) ? 0 : DRMODE_INVERSEVID
);
1001 rb
->lcd_fillrect( X_0_POS
+ btn_col
*REC_WIDTH
+ 1,
1002 Y_1_POS
+ btn_row
*REC_HEIGHT
+ 1,
1003 REC_WIDTH
- 1, REC_HEIGHT
- 1);
1004 rb
->lcd_putsxy( X_0_POS
+ btn_col
*REC_WIDTH
+ (REC_WIDTH
- w
)/2,
1005 Y_1_POS
+ btn_row
*REC_HEIGHT
+ (REC_HEIGHT
- h
)/2 +1,
1006 buttonChar
[buttonGroup
][btn_row
][btn_col
] );
1007 rb
->lcd_update_rect( X_0_POS
+ btn_col
*REC_WIDTH
+ 1,
1008 Y_1_POS
+ btn_row
*REC_HEIGHT
+ 1,
1009 REC_WIDTH
- 1, REC_HEIGHT
- 1);
1017 /* -----------------------------------------------------------------------
1018 pos is the position that needs animation. pos = [1~18]
1019 ----------------------------------------------------------------------- */
1020 void deleteAnimation(int pos
)
1023 if (pos
<1 || pos
>18)
1026 rb
->lcd_getstringsize("0", &w
, &h
);
1027 x
= (pos
==1? 4: LCD_WIDTH
- 4 - w
);
1030 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1031 rb
->lcd_fillrect(x
, Y_1_POS
- h
-1, w
, h
);
1032 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1033 rb
->lcd_fillrect(x
+ (w
*k
)/8, Y_1_POS
- h
-1 + (h
*k
)/8,
1034 (w
*(4-k
))/4, (h
*(4-k
))/4);
1035 rb
->lcd_update_rect(x
, Y_1_POS
- h
-1, w
, h
);
1040 /* -----------------------------------------------------------------------
1041 result may be one of these formats:
1047 formatResult() change result to standard format: 0.xxxx
1048 if result is close to 0, let it be 0;
1049 if result is close to 1, let it be 0.1 and power++;
1050 ----------------------------------------------------------------------- */
1051 void formatResult(void)
1053 int resultsign
= SIGN(result
);
1054 result
= ABS(result
);
1055 if(result
> MINIMUM
){ /* doesn't check power, might have problem
1057 + - * / of two formatted number wouldn't.
1058 only a calculation that makes a formatted
1059 number (0.xxxx) less than MINIMUM in only
1063 while( (int)(result
*10) == 0 ){
1069 else{ /* result >= 1 */
1070 while( (int)result
!= 0 ){
1077 if (result
> (1-MINIMUM
)){
1082 result
*= resultsign
;
1091 /* -----------------------------------------------------------------------
1092 result2typingbuf() outputs standard format result to typingbuf.
1093 case SCIENTIFIC_FORMAT, let temppower = 1;
1094 case temppower > 0: print '.' in the middle
1095 case temppower <= 0: print '.' in the begining
1096 ----------------------------------------------------------------------- */
1097 void result2typingbuf(void)
1099 bool haveDot
= false;
1102 double tempresult
= ABS(result
); /* positive num makes things simple */
1105 double tempmodifier
= 1;
1108 if(SCIENTIFIC_FORMAT
)
1109 temppower
= 1; /* output x.xxxx format */
1115 if(tempresult
< MINIMUM
){ /* if 0,faster display and avoid complication*/
1119 else{ /* tempresult > 0 */
1120 typingbuf
[0] = (SIGN(result
)<0)?'-':' ';
1122 typingbufPointer
= typingbuf
;
1124 for (k
= 0; k
<DIGITLEN
+1 ; k
++){
1126 if(temppower
|| *(typingbufPointer
-1) == '.'){
1128 tempmodifier
= tempmodifier
/10;
1129 while( (tempresult
-tempmodifier
*count
) >
1130 (tempmodifier
-MINIMUM
)){
1133 tempresult
-= tempmodifier
*count
;
1134 tempresult
= ABS(tempresult
);
1136 *typingbufPointer
= count
+ '0';
1138 else{ /* temppower == 0 */
1139 *typingbufPointer
= '.';
1146 typingbufPointer
++; *typingbufPointer
= '0';
1147 typingbufPointer
++; *typingbufPointer
= '.';
1148 for (k
= 2; k
<DIGITLEN
+1 ; k
++){
1151 if ( (-temppower
) < (k
-1)){
1152 tempmodifier
= tempmodifier
/10;
1153 while((tempresult
-tempmodifier
*count
)>(tempmodifier
-MINIMUM
)){
1157 tempresult
-= tempmodifier
*count
;
1158 tempresult
= ABS(tempresult
);
1161 *typingbufPointer
= count
+ '0';
1164 /* now, typingbufPointer = typingbuf + 16 */
1165 /* backward strip off 0 and '.' */
1167 while( (*typingbufPointer
== '0') || (*typingbufPointer
== '.')){
1168 tempchar
= *typingbufPointer
;
1169 *typingbufPointer
= 0;
1171 if (tempchar
== '.') break;
1174 typingbuf
[DIGITLEN
+1] = 0;
1175 } /* else tempresult > 0 */
1178 /* -----------------------------------------------------------------------
1179 printResult() generates LCD display.
1180 ----------------------------------------------------------------------- */
1181 void printResult(void)
1185 char operbuf
[3] = {0, 0, 0};
1190 rb
->lcd_clear_display();
1191 rb
->splash(HZ
/3, "Bye now!");
1195 rb
->snprintf(buf
, 19, "%18s","Error");
1199 rb
->snprintf(buf
, 19, "%18s","Coming soon ^_* ");
1205 if( power
> 1000 ){ /* power -1 > 999 */
1206 calStatus
= cal_error
;
1209 if (power
< -998 ) /* power -1 < -999 */
1210 clearResult(); /* too small, let it be 0 */
1216 operbuf
[1] = ( ABS(memTemp
) > MINIMUM
)?'M':' ';
1219 if(SCIENTIFIC_FORMAT
){
1220 /* output format: X.XXXX eXXX */
1221 if(power
> -98){ /* power-1 >= -99, eXXX or e-XX */
1222 rb
->snprintf(buf
, 12, "%11s",typingbuf
);
1223 for(k
=11;k
<=14;k
++) buf
[k
] = ' ';
1225 rb
->snprintf(typingbuf
, 5, "e%d",power
-1);
1226 rb
->snprintf(buf
+11, 5, "%4s",typingbuf
);
1228 else{ /* power-1 <= -100, e-XXX */
1229 rb
->snprintf(buf
, 12, "%11s",typingbuf
);
1230 rb
->snprintf(buf
+11, 6, "e%d",power
-1);
1234 rb
->snprintf(buf
, 12, "%11s",typingbuf
);
1235 } /* if SCIENTIFIC_FORMAT */
1241 operbuf
[1] = ( ABS(memTemp
) > MINIMUM
)?'M':' ';
1242 rb
->snprintf(buf
, 12, "%11s",typingbuf
);
1247 rb
->lcd_getstringsize(buf
, &w
, &h
);
1248 rb
->screen_clear_area(rb
->screens
[0], 0, 0, LCD_WIDTH
, Y_1_POS
- 1);
1249 rb
->lcd_putsxy(4, Y_1_POS
- h
-1, operbuf
);
1250 rb
->lcd_putsxy(LCD_WIDTH
- w
- 4, Y_1_POS
- h
-1, buf
);
1251 rb
->lcd_update_rect(0, 1, LCD_WIDTH
, Y_1_POS
);
1254 /* -----------------------------------------------------------------------
1255 Process typing buttons: 1-9, '.', sign
1256 main operand "result" and typingbuf are processed seperately here.
1257 ----------------------------------------------------------------------- */
1258 void typingProcess(void){
1259 switch( CAL_BUTTON
){
1261 if (calStatus
== cal_typing
||
1262 calStatus
== cal_dotted
)
1263 typingbuf
[0] = (typingbuf
[0]=='-')?' ':'-';
1267 operInputted
= false;
1271 *typingbufPointer
= '0';
1274 calStatus
= cal_dotted
;
1275 *typingbufPointer
= '.';
1276 if (typingbufPointer
!= typingbuf
+DIGITLEN
+1)
1279 default: /* cal_dotted */
1284 operInputted
= false;
1285 /* normal,0; normal,1-9; typing,0; typing,1-9 */
1288 if(CAL_BUTTON
== btn_0
)
1289 break; /* first input is 0, ignore */
1291 /*no operator means start a new calculation*/
1294 calStatus
= cal_typing
;
1295 /* go on typing, no break */
1300 *typingbufPointer
= '0';
1303 *typingbufPointer
=(7+btn_col
-3*(btn_row
-1))+ '0';
1306 if (typingbufPointer
!=typingbuf
+DIGITLEN
+1){
1309 {/* result processing */
1310 if (calStatus
== cal_typing
) power
++;
1311 if (CAL_BUTTON
!= btn_0
)
1314 (7+btn_col
-3*(btn_row
-1))*modifier
;
1318 else /* last byte always '\0' */
1319 *typingbufPointer
= 0;
1321 default: /* cal_error, cal_exit */
1324 break; /* default, 0-9 */
1325 } /* switch( CAL_BUTTON ) */
1328 /* -----------------------------------------------------------------------
1329 Handle delete operation
1330 main operand "result" and typingbuf are processed seperately here.
1331 ----------------------------------------------------------------------- */
1332 void doDelete(void){
1333 deleteAnimation(18);
1336 if (*(typingbufPointer
-1) == '.'){
1337 /* if dotted and deleting '.',
1338 change status and delete '.' below */
1339 calStatus
= cal_typing
;
1341 else{ /* if dotted and not deleting '.',
1343 power
++; /* counter "power--;" below */
1348 {/* result processing */ /* 0-9, '.' */
1349 /* if deleting '.', do nothing */
1350 if ( *typingbufPointer
!= '.'){
1353 result
= result
- SIGN(result
)*
1354 ((*typingbufPointer
)- '0')*modifier
;
1358 *typingbufPointer
= 0;
1360 /* if (only one digit left and it's 0)
1361 or no digit left, change status*/
1362 if ( typingbufPointer
== typingbuf
+1 ||
1363 ( typingbufPointer
== typingbuf
+2 &&
1364 *(typingbufPointer
-1) == '0' ))
1365 calStatus
= cal_normal
;
1367 default: /* normal, error, exit */
1371 /* -----------------------------------------------------------------------
1372 Handle buttons on basic screen
1373 ----------------------------------------------------------------------- */
1374 void basicButtonsProcess(void){
1376 case CALCULATOR_INPUT
:
1377 if (calStatus
== cal_error
&& (CAL_BUTTON
!= btn_C
) ) break;
1379 switch( CAL_BUTTON
){
1381 operInputted
= false;
1382 result
= memTemp
; power
= memTempPower
;
1383 calStatus
= cal_normal
;
1387 if (memTemp
> MINIMUM
)
1388 doAdd(&memTemp
, &memTempPower
, result
, power
);
1390 /* if result is too small and memTemp = 0,
1391 doAdd will not add */
1393 memTempPower
= power
;
1395 calStatus
= cal_normal
;
1398 case btn_C
: clearMem(); break;
1399 case btn_CE
: clearInput(); break;
1402 buttonGroup
= sciButtons
;
1403 printButtonGroups(buttonGroup
);
1406 /* one operand calculation, may be changed to
1407 like sin, cos, log, etc */
1411 formatResult(); /* not necessary, just for safty */
1415 case_btn_equal
: /* F3 shortkey entrance */
1418 calStatus
= cal_normal
;
1419 operInputted
= false;
1420 if (oper
!= ' ') twoOperands();
1427 if(!operInputted
) {twoOperands(); operInputted
= true;}
1428 oper
= buttonChar
[basicButtons
][btn_row
][btn_col
][0];
1429 #ifdef CALCULATOR_OPERATORS
1430 case_cycle_operators
: /* F2 shortkey entrance */
1432 calStatus
= cal_normal
;
1435 operandPower
= power
;
1444 } /* switch (CAL_BUTTON) */
1447 #ifdef CALCULATOR_OPERATORS
1448 case CALCULATOR_OPERATORS
:
1449 if (calStatus
== cal_error
) break;
1450 if (!operInputted
) {twoOperands(); operInputted
= true;}
1453 case '/': oper
= '+'; flashButton(); break;
1454 case '+': oper
= '-'; flashButton(); break;
1455 case '-': oper
= '*'; flashButton(); break;
1456 case '*': oper
= '/'; flashButton(); break;
1458 goto case_cycle_operators
;
1462 case CALCULATOR_CALC
:
1463 if (calStatus
== cal_error
) break;
1465 goto case_btn_equal
;
1472 /* -----------------------------------------------------------------------
1473 Handle buttons on scientific screen
1474 ----------------------------------------------------------------------- */
1475 void sciButtonsProcess(void){
1477 case CALCULATOR_INPUT
:
1478 if (calStatus
== cal_error
&& (CAL_BUTTON
!= sci_sci
) ) break;
1480 switch( CAL_BUTTON
){
1483 result
= M_PI
; power
= 0;
1484 calStatus
= cal_normal
;
1490 buttonGroup
= basicButtons
;
1491 printButtonGroups(basicButtons
);
1504 formatResult(); /* not necessary, just for safty */
1513 } /* switch (CAL_BUTTON) */
1516 #ifdef CALCULATOR_OPERATORS
1517 case CALCULATOR_OPERATORS
:
1518 if (calStatus
== cal_error
) break;
1519 if (!operInputted
) {twoOperands(); operInputted
= true;}
1521 case ' ': oper
= '+'; break;
1522 case '/': oper
= '+'; deleteAnimation(1); break;
1523 case '+': oper
= '-'; deleteAnimation(1); break;
1524 case '-': oper
= '*'; deleteAnimation(1); break;
1525 case '*': oper
= '/'; deleteAnimation(1); break;
1527 calStatus
= cal_normal
;
1530 operandPower
= power
;
1534 case CALCULATOR_CALC
:
1535 if (calStatus
== cal_error
) break;
1537 calStatus
= cal_normal
;
1538 operInputted
= false;
1539 if (oper
!= ' ') twoOperands();
1546 /* -----------------------------------------------------------------------
1548 Invert display new button, invert back previous button
1549 ----------------------------------------------------------------------- */
1550 int handleButton(int button
){
1553 case CALCULATOR_INPUT
:
1554 case CALCULATOR_CALC
:
1555 #ifdef CALCULATOR_INPUT_CALC_PRE
1556 if (lastbtn
!= CALCULATOR_INPUT_CALC_PRE
)
1558 /* no unconditional break; here! */
1560 #ifdef CALCULATOR_OPERATORS
1561 case CALCULATOR_OPERATORS
:
1563 switch(buttonGroup
){
1565 basicButtonsProcess();
1568 sciButtonsProcess();
1573 #ifdef CALCULATOR_CLEAR
1574 case CALCULATOR_CLEAR
:
1580 default: /* cal_normal, cal_error, cal_exit */
1587 case CALCULATOR_LEFT
:
1588 case CALCULATOR_LEFT
| BUTTON_REPEAT
:
1589 move_with_wrap_and_shift(
1590 &btn_col
, -1, BUTTON_COLS
,
1591 &btn_row
, 0, BUTTON_ROWS
);
1594 case CALCULATOR_RIGHT
:
1595 case CALCULATOR_RIGHT
| BUTTON_REPEAT
:
1596 move_with_wrap_and_shift(
1597 &btn_col
, 1, BUTTON_COLS
,
1598 &btn_row
, 0, BUTTON_ROWS
);
1601 #ifdef CALCULATOR_UP
1603 case CALCULATOR_UP
| BUTTON_REPEAT
:
1604 move_with_wrap_and_shift(
1605 &btn_row
, -1, BUTTON_ROWS
,
1606 &btn_col
, 0, BUTTON_COLS
);
1609 #ifdef CALCULATOR_DOWN
1610 case CALCULATOR_DOWN
:
1611 case CALCULATOR_DOWN
| BUTTON_REPEAT
:
1612 move_with_wrap_and_shift(
1613 &btn_row
, 1, BUTTON_ROWS
,
1614 &btn_col
, 0, BUTTON_COLS
);
1618 #ifdef CALCULATOR_UP_W_SHIFT
1619 case CALCULATOR_UP_W_SHIFT
:
1620 case CALCULATOR_UP_W_SHIFT
| BUTTON_REPEAT
:
1621 move_with_wrap_and_shift(
1622 &btn_row
, -1, BUTTON_ROWS
,
1623 &btn_col
, -1, BUTTON_COLS
);
1626 #ifdef CALCULATOR_DOWN_W_SHIFT
1627 case CALCULATOR_DOWN_W_SHIFT
:
1628 case CALCULATOR_DOWN_W_SHIFT
| BUTTON_REPEAT
:
1629 move_with_wrap_and_shift(
1630 &btn_row
, 1, BUTTON_ROWS
,
1631 &btn_col
, 1, BUTTON_COLS
);
1634 #ifdef CALCULATOR_LEFT_W_SHIFT
1635 case CALCULATOR_LEFT_W_SHIFT
:
1636 case CALCULATOR_LEFT_W_SHIFT
| BUTTON_REPEAT
:
1637 move_with_wrap_and_shift(
1638 &btn_col
, -1, BUTTON_COLS
,
1639 &btn_row
, -1, BUTTON_ROWS
);
1642 #ifdef CALCULATOR_RIGHT_W_SHIFT
1643 case CALCULATOR_RIGHT_W_SHIFT
:
1644 case CALCULATOR_RIGHT_W_SHIFT
| BUTTON_REPEAT
:
1645 move_with_wrap_and_shift(
1646 &btn_col
, 1, BUTTON_COLS
,
1647 &btn_row
, 1, BUTTON_ROWS
);
1650 #ifdef CALCULATOR_RC_QUIT
1651 case CALCULATOR_RC_QUIT
:
1653 case CALCULATOR_QUIT
:
1659 prev_btn_row
= btn_row
;
1660 prev_btn_col
= btn_col
;
1663 /* -----------------------------------------------------------------------
1665 ----------------------------------------------------------------------- */
1666 enum plugin_status
plugin_start(const void* parameter
)
1670 /* now go ahead and have fun! */
1672 #ifdef HAVE_TOUCHSCREEN
1673 rb
->touchscreen_set_mode(TOUCHSCREEN_POINT
);
1678 while (calStatus
!= cal_exit
) {
1679 btn
= rb
->button_get_w_tmo(HZ
/2);
1680 #ifdef HAVE_TOUCHSCREEN
1681 if(btn
& BUTTON_TOUCHSCREEN
)
1683 struct ts_raster_result res
;
1684 if(touchscreen_map_raster(&calc_raster
, rb
->button_get_data() >> 16,
1685 rb
->button_get_data() & 0xffff, &res
) == 1)
1689 drawButtons(buttonGroup
);
1694 prev_btn_row
= btn_row
;
1695 prev_btn_col
= btn_col
;
1696 if(btn
& BUTTON_REL
)
1698 btn
= CALCULATOR_INPUT
;
1699 switch(buttonGroup
){
1701 basicButtonsProcess();
1704 sciButtonsProcess();
1707 btn
= BUTTON_TOUCHSCREEN
;
1712 if (handleButton(btn
) == -1)
1714 calStatus
= cal_exit
;
1719 drawButtons(buttonGroup
);
1725 if(rb
->default_event_handler(btn
) == SYS_USB_CONNECTED
)
1726 return PLUGIN_USB_CONNECTED
;
1728 if (btn
!= BUTTON_NONE
)
1730 } /* while (calStatus != cal_exit ) */
1732 rb
->button_clear_queue();
1736 #endif /* #ifdef HAVE_LCD_BITMAP */