diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-07-15 19:40:55 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-07-24 21:20:13 +0000 |
commit | 092c340a2062fa98b7387fc5fd63578ddae7d0b6 (patch) | |
tree | 98ec96946eeb2ae709cb0528cc6998e21bb9b290 /apps/plugins/euroconverter.c | |
parent | 17f7cc92c258bc456a27c3e7c5a19c9409851879 (diff) | |
download | rockbox-092c340a2062fa98b7387fc5fd63578ddae7d0b6.tar.gz rockbox-092c340a2062fa98b7387fc5fd63578ddae7d0b6.zip |
[1/4] Remove SH support and all archos targets
This removes all code specific to SH targets
Change-Id: I7980523785d2596e65c06430f4638eec74a06061
Diffstat (limited to 'apps/plugins/euroconverter.c')
-rw-r--r-- | apps/plugins/euroconverter.c | 599 |
1 files changed, 0 insertions, 599 deletions
diff --git a/apps/plugins/euroconverter.c b/apps/plugins/euroconverter.c deleted file mode 100644 index d7aa61f806..0000000000 --- a/apps/plugins/euroconverter.c +++ /dev/null | |||
@@ -1,599 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2003 Pierre Delore | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "plugin.h" | ||
22 | #include "lib/configfile.h" | ||
23 | #include "lib/pluginlib_exit.h" | ||
24 | |||
25 | /* Euro converter for the player */ | ||
26 | /* | ||
27 | Use: | ||
28 | + : Digit +1 | ||
29 | - : Digit -1 | ||
30 | PLAY : Next digit | ||
31 | STOP : Prev digit | ||
32 | ON : RESET | ||
33 | ON+PLAY : Swap Euro<>Home | ||
34 | MENU : Display the Menu | ||
35 | Currency -> Allows to choose the currency | ||
36 | Exit-> Exit the plugin | ||
37 | |||
38 | Notes: | ||
39 | I don't use float. | ||
40 | I use signed long long (64 bits). | ||
41 | A value have 5 digits after the . (123.45 = 12345000) | ||
42 | |||
43 | To do: | ||
44 | - The Irish currency needs 6 digits after the . to have sufficient precision on big number | ||
45 | */ | ||
46 | |||
47 | |||
48 | |||
49 | /* Name and path of the config file*/ | ||
50 | static const char cfg_filename[] = "euroconverter.cfg"; | ||
51 | #define CFGFILE_VERSION 0 /* Current config file version */ | ||
52 | #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */ | ||
53 | |||
54 | /* typedef for simplifying usage of long long type */ | ||
55 | typedef long long int longlong_t; | ||
56 | |||
57 | /*Pattern for the converter*/ | ||
58 | static unsigned char pattern_euro[]={0x07, 0x08, 0x1E, 0x10, 0x1E, 0x08, 0x07}; /* € */ | ||
59 | static unsigned char pattern_home[]={0x04, 0x0A, 0x11, 0x1F, 0x11, 0x11, 0x1F}; /* Home icon*/ | ||
60 | |||
61 | /* 1 euro = ... (remenber 5 digits after the .)*/ | ||
62 | static int currency[12]={ | ||
63 | 655957, /*FRF France*/ | ||
64 | 195583, /*DEM Germany*/ | ||
65 | 1376030, /*ATS Austria*/ | ||
66 | 4033990, /*BEF Belgium*/ | ||
67 | 16638600, /*ESP Spain*/ | ||
68 | 594573, /*FIM Finland*/ | ||
69 | 78756, /*IEP Ireland*/ | ||
70 | 193627000, /*ITL Italy*/ | ||
71 | 4033990, /*LUF Luxemburg*/ | ||
72 | 220371, /*NLG Netherlands*/ | ||
73 | 20048200, /*PTE Portugal*/ | ||
74 | 34075100, /*GRD Greece*/ | ||
75 | }; | ||
76 | |||
77 | /* Number of digit of the currency (for the display) */ | ||
78 | static int nb_digit[12]={ | ||
79 | 2, /*FRF France*/ | ||
80 | 2, /*DEM Germany*/ | ||
81 | 2, /*ATS Austria*/ | ||
82 | 2, /*BEF Belgium*/ | ||
83 | 0, /*ESP Spain*/ | ||
84 | 2, /*FIM Finland*/ | ||
85 | 2, /*IEP Ireland*/ | ||
86 | 0, /*ITL Italy*/ | ||
87 | 2, /*LUF Luxemburg*/ | ||
88 | 2, /*NLG Netherlands*/ | ||
89 | 0, /*PTE Portugal*/ | ||
90 | 0 /*GRD Greece*/ | ||
91 | }; | ||
92 | |||
93 | /* max euro to have home currency */ | ||
94 | static longlong_t max_euro[12]={ | ||
95 | 99999999000LL, /*FRF France 999 999.99 */ | ||
96 | 99999999000LL, /*DEM Germany 999 999.99 */ | ||
97 | 99999999000LL, /*ATS Austria 999 999.99 */ | ||
98 | 99999999000LL, /*BEF Belgium 999 999.99 */ | ||
99 | 99999999000LL, /*ESP Spain 99 999 999 */ | ||
100 | 99999999000LL, /*FIM Finland 999 999.99 */ | ||
101 | 99999999000LL, /*IEP Ireland 999 999.99 */ | ||
102 | 51645690000LL, /*ITL Italy 999 999 999 */ | ||
103 | 99999999000LL, /*LUF Luxemburg 999 999.99 */ | ||
104 | 99999999000LL, /*NLG Netherlands 999 999.99 */ | ||
105 | 99999999000LL, /*PTE Portugal 99 999 999 */ | ||
106 | 29347028000LL /*GRD Greece 99 999 999 */ | ||
107 | }; | ||
108 | |||
109 | /* max home to have euro currency */ | ||
110 | /* 92233720300000 Limitation due to the max capacity of long long (2^63)*/ | ||
111 | static longlong_t max_curr[12]={ | ||
112 | 99999999000LL, /*FRF France 152449.02 */ | ||
113 | 99999999000LL, /*DEM Germany 511291.88 */ | ||
114 | 99999999000LL, /*ATS Austria 72672.83 */ | ||
115 | 99999999000LL, /*BEF Belgium 24789.35 */ | ||
116 | 92233720300000LL,/*ESP Spain 5543358.23 */ | ||
117 | 99999999000LL, /*FIM Finland 168187.92 */ | ||
118 | 9999999900LL, /*IEP Ireland 1269744.51 exact value=1269738.07 */ | ||
119 | 92233720300000LL,/*ITL Italy 476347.41 */ | ||
120 | 99999999000LL, /*LUF Luxemburg 24789.35 */ | ||
121 | 99999999000LL, /*NLG Netherlands 453780.21 */ | ||
122 | 92233720300000LL,/*PTE Portugal 4600598.57 */ | ||
123 | 92233720300000LL /*GRD Greece 2706777.69 */ | ||
124 | }; | ||
125 | |||
126 | static unsigned char *abbrev_str[12] = { | ||
127 | "...FRF...", /*France*/ | ||
128 | "...DEM...", /*Germany*/ | ||
129 | "...ATS...", /*Austria*/ | ||
130 | "...BEF...", /*Belgium*/ | ||
131 | "...ESP...", /*Spain*/ | ||
132 | "...FIM...", /*Finland*/ | ||
133 | "...IEP...", /*Ireland*/ | ||
134 | "...ITL...", /*Italy*/ | ||
135 | "...LUF...", /*Luxemburg*/ | ||
136 | "...NLG...", /*Netherlands*/ | ||
137 | "...PTE...", /*Portugal*/ | ||
138 | "...GRD..." /*Greece*/ | ||
139 | }; | ||
140 | |||
141 | |||
142 | static unsigned long heuro,hhome; /*Handles for the new patterns*/ | ||
143 | |||
144 | static char *currency_str[12] = { | ||
145 | "France", | ||
146 | "Germany", | ||
147 | "Austria", | ||
148 | "Belgium", | ||
149 | "Spain", | ||
150 | "Finland", | ||
151 | "Ireland", | ||
152 | "Italy", | ||
153 | "Luxemburg", | ||
154 | "Netherlands", | ||
155 | "Portugal", | ||
156 | "Greece" | ||
157 | }; | ||
158 | |||
159 | |||
160 | static int country; /*Country selected*/ | ||
161 | static int cur_pos; /*Cursor position*/ | ||
162 | static longlong_t inc; | ||
163 | |||
164 | /* Persistent settings */ | ||
165 | static struct configdata config[] = { | ||
166 | { TYPE_ENUM, 0, 12, { .int_p = &country }, "country", currency_str } | ||
167 | }; | ||
168 | |||
169 | |||
170 | /* 64bits*64 bits with 5 digits after the . */ | ||
171 | static longlong_t mymul(longlong_t a, longlong_t b) | ||
172 | { | ||
173 | return((a*b)/100000LL); | ||
174 | } | ||
175 | |||
176 | |||
177 | /* 64bits/64 bits with 5 digits after the . */ | ||
178 | static longlong_t mydiv(longlong_t a, longlong_t b) | ||
179 | { | ||
180 | return((a*100000LL)/b); | ||
181 | } | ||
182 | |||
183 | |||
184 | /* 123.45=12345000 split => i=123 f=45000*/ | ||
185 | static void split(longlong_t v, longlong_t* i, longlong_t* f) | ||
186 | { | ||
187 | longlong_t t; | ||
188 | |||
189 | t=v/100000LL; | ||
190 | (*i)=t; | ||
191 | (*f)=(v-(t*100000LL)); | ||
192 | } | ||
193 | |||
194 | |||
195 | /* result=10^n */ | ||
196 | static longlong_t pow10(int n) | ||
197 | { | ||
198 | int i; | ||
199 | longlong_t r; | ||
200 | |||
201 | r=1; | ||
202 | for (i=0;i<n;i++) | ||
203 | r=r*10LL; | ||
204 | return(r); | ||
205 | } | ||
206 | |||
207 | |||
208 | /* round the i.f at n digit after the . */ | ||
209 | static void round(longlong_t* i, longlong_t* f, int n) | ||
210 | { | ||
211 | |||
212 | longlong_t m; | ||
213 | int add=0; | ||
214 | |||
215 | m=(int)pow10(5-n-1); | ||
216 | if (((*f)/m)%10>=5) | ||
217 | add=1; | ||
218 | if (n>0) | ||
219 | { | ||
220 | (*f)=((*f)/(int)pow10(5-n))+add; | ||
221 | if ((*f)==100LL) | ||
222 | { | ||
223 | (*i)+=1; | ||
224 | (*f)=0; | ||
225 | } | ||
226 | } | ||
227 | else | ||
228 | { | ||
229 | (*i)+=add; | ||
230 | (*f)=0; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | |||
235 | /* Display the imput and the result | ||
236 | pos: false : first line | ||
237 | : true : second line | ||
238 | */ | ||
239 | static void display(longlong_t euro, longlong_t home, bool pos) | ||
240 | { | ||
241 | longlong_t i,f; | ||
242 | unsigned char str[20]; | ||
243 | unsigned char s1[20]; | ||
244 | unsigned char s2[20]; | ||
245 | |||
246 | if (pos) | ||
247 | { /*Edit the second line*/ | ||
248 | rb->strcpy(s1," %6d.%02d"); | ||
249 | if (nb_digit[country]==2) | ||
250 | rb->strcpy(s2,"\xee\x84\x90%06d.%02d"); | ||
251 | else | ||
252 | rb->strcpy(s2,"\xee\x84\x90%09d"); | ||
253 | } | ||
254 | else | ||
255 | { | ||
256 | rb->strcpy(s1,"\xee\x84\x90%06d.%02d"); | ||
257 | if (nb_digit[country]==2) | ||
258 | rb->strcpy(s2," %6d.%02d"); | ||
259 | else | ||
260 | rb->strcpy(s2," %9d"); | ||
261 | } | ||
262 | |||
263 | rb->lcd_remove_cursor(); | ||
264 | /*First line*/ | ||
265 | rb->lcd_putc(0,0,heuro); | ||
266 | split(euro,&i,&f); | ||
267 | if (pos) | ||
268 | round(&i,&f,2); | ||
269 | rb->snprintf(str,sizeof(str),s1,(int)i,(int)f); | ||
270 | |||
271 | if (!pos) | ||
272 | { | ||
273 | rb->lcd_puts(1,0,str); | ||
274 | rb->lcd_put_cursor(10-cur_pos,0,0x5F); | ||
275 | } | ||
276 | else | ||
277 | rb->lcd_puts_scroll(1,0,str); | ||
278 | |||
279 | /*Second line*/ | ||
280 | rb->lcd_putc(0,1,hhome); | ||
281 | split(home,&i,&f); | ||
282 | if (!pos) | ||
283 | round(&i,&f,nb_digit[country]); | ||
284 | rb->snprintf(str,sizeof(str),s2,(int)i,(int)f); | ||
285 | if (pos) | ||
286 | { | ||
287 | rb->lcd_puts(1,1,str); | ||
288 | rb->lcd_put_cursor(10-cur_pos,1,0x5F); | ||
289 | } | ||
290 | else | ||
291 | rb->lcd_puts_scroll(1,1,str); | ||
292 | |||
293 | rb->lcd_update(); | ||
294 | } | ||
295 | |||
296 | |||
297 | /* Show country Abbreviation */ | ||
298 | static void show_abbrev(void) | ||
299 | { | ||
300 | rb->splash(HZ*3/4,abbrev_str[country]); | ||
301 | } | ||
302 | |||
303 | |||
304 | /* Save the config to disk */ | ||
305 | static void save_config(void) | ||
306 | { | ||
307 | configfile_save(cfg_filename, config, 1, CFGFILE_VERSION); | ||
308 | } | ||
309 | |||
310 | |||
311 | /* Load the config from disk */ | ||
312 | static void load_config(void) | ||
313 | { | ||
314 | configfile_load(cfg_filename, config, 1, CFGFILE_MINVERSION); | ||
315 | } | ||
316 | |||
317 | |||
318 | /*Currency choice*/ | ||
319 | static void currency_menu(void) | ||
320 | { | ||
321 | int c=country; | ||
322 | |||
323 | rb->lcd_clear_display(); | ||
324 | while (true) | ||
325 | { | ||
326 | rb->lcd_puts(0,0,"Currency:"); | ||
327 | rb->lcd_puts(0,1,currency_str[c]); | ||
328 | rb->lcd_update(); | ||
329 | switch (rb->button_get(true)) | ||
330 | { | ||
331 | case BUTTON_RIGHT|BUTTON_REL: | ||
332 | c++; | ||
333 | if (c>11) | ||
334 | c=0; | ||
335 | break; | ||
336 | case BUTTON_LEFT|BUTTON_REL: | ||
337 | c--; | ||
338 | if (c<0) | ||
339 | c=11; | ||
340 | break; | ||
341 | case BUTTON_PLAY|BUTTON_REL: | ||
342 | country=c; | ||
343 | save_config(); | ||
344 | return; | ||
345 | break; | ||
346 | case BUTTON_STOP|BUTTON_REL: | ||
347 | return; | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | |||
352 | |||
353 | /* Display the choice menu. */ | ||
354 | static int euro_menu(void) | ||
355 | { | ||
356 | int c=0; | ||
357 | |||
358 | |||
359 | while (true) | ||
360 | { | ||
361 | rb->lcd_clear_display(); | ||
362 | rb->lcd_puts(0,0," Currency"); | ||
363 | rb->lcd_puts(0,1," Exit"); | ||
364 | rb->lcd_putc(0,c,0xe110); | ||
365 | rb->lcd_update(); | ||
366 | |||
367 | switch (rb->button_get(true)) | ||
368 | { | ||
369 | case BUTTON_RIGHT|BUTTON_REL: | ||
370 | c=1; | ||
371 | break; | ||
372 | case BUTTON_LEFT|BUTTON_REL: | ||
373 | c=0; | ||
374 | break; | ||
375 | case BUTTON_PLAY|BUTTON_REL: | ||
376 | if (c==0) | ||
377 | currency_menu(); | ||
378 | else | ||
379 | return 1; | ||
380 | break; | ||
381 | case BUTTON_STOP|BUTTON_REL: | ||
382 | return 0; | ||
383 | } | ||
384 | } | ||
385 | } | ||
386 | |||
387 | |||
388 | /* Call when the program end */ | ||
389 | static void euro_exit(void) | ||
390 | { | ||
391 | //Restore the old pattern (i don't find another way to do this. An idea?) | ||
392 | rb->lcd_unlock_pattern(heuro); | ||
393 | rb->lcd_unlock_pattern(hhome); | ||
394 | |||
395 | //Clear the screen | ||
396 | rb->lcd_clear_display(); | ||
397 | rb->lcd_update(); | ||
398 | } | ||
399 | |||
400 | |||
401 | /* this is the plugin entry point */ | ||
402 | enum plugin_status plugin_start(const void* parameter) | ||
403 | { | ||
404 | bool end, pos; | ||
405 | longlong_t e,h,old_e,old_h; | ||
406 | int button; | ||
407 | |||
408 | /* if you don't use the parameter, you can do like | ||
409 | this to avoid the compiler warning about it */ | ||
410 | (void)parameter; | ||
411 | atexit(euro_exit); | ||
412 | |||
413 | /*Get the pattern handle*/ | ||
414 | heuro=rb->lcd_get_locked_pattern(); | ||
415 | hhome=rb->lcd_get_locked_pattern(); | ||
416 | rb->lcd_define_pattern(heuro, pattern_euro); | ||
417 | rb->lcd_define_pattern(hhome, pattern_home); | ||
418 | |||
419 | h=0; | ||
420 | e=0; | ||
421 | end=false; | ||
422 | pos=false; | ||
423 | country=0; | ||
424 | cur_pos=3; | ||
425 | inc=100000; | ||
426 | |||
427 | load_config(); | ||
428 | |||
429 | /*Empty the event queue*/ | ||
430 | rb->button_clear_queue(); | ||
431 | |||
432 | display(e,h,false); | ||
433 | show_abbrev(); | ||
434 | display(e,h,false); | ||
435 | |||
436 | /*Main loop*/ | ||
437 | while(end!=true) | ||
438 | { | ||
439 | button = rb->button_get(true); | ||
440 | switch (button) | ||
441 | { | ||
442 | case BUTTON_MENU|BUTTON_REL: | ||
443 | switch (euro_menu()) | ||
444 | { | ||
445 | case 1: | ||
446 | end=true; | ||
447 | break; | ||
448 | } | ||
449 | if (!pos) | ||
450 | { | ||
451 | if (e>max_euro[country]) | ||
452 | e=0; | ||
453 | cur_pos=3; | ||
454 | } | ||
455 | else | ||
456 | { | ||
457 | if (h>max_curr[country]) | ||
458 | h=0; | ||
459 | if (nb_digit[country]==2) | ||
460 | cur_pos=3; | ||
461 | else | ||
462 | cur_pos=0; | ||
463 | } | ||
464 | |||
465 | display(e,h,pos); | ||
466 | break; | ||
467 | |||
468 | case BUTTON_ON | BUTTON_PLAY: | ||
469 | pos=!pos; | ||
470 | |||
471 | case BUTTON_ON | BUTTON_REL: | ||
472 | e=0; | ||
473 | h=0; | ||
474 | if (!pos) | ||
475 | { | ||
476 | cur_pos=3; | ||
477 | inc=100000; | ||
478 | } | ||
479 | else | ||
480 | { | ||
481 | inc=100000; | ||
482 | if (nb_digit[country]==2) | ||
483 | cur_pos=3; | ||
484 | else | ||
485 | cur_pos=0; | ||
486 | } | ||
487 | show_abbrev(); | ||
488 | break; | ||
489 | |||
490 | case BUTTON_STOP|BUTTON_REL: | ||
491 | cur_pos--; | ||
492 | if (!pos) | ||
493 | { | ||
494 | if (cur_pos<0) | ||
495 | cur_pos=0; | ||
496 | if (cur_pos==2) | ||
497 | cur_pos=1; | ||
498 | if (cur_pos>2) | ||
499 | inc=pow10(3+cur_pos-1); | ||
500 | else | ||
501 | inc=pow10(3+cur_pos); | ||
502 | } | ||
503 | else | ||
504 | { | ||
505 | if (cur_pos<0) | ||
506 | cur_pos=0; | ||
507 | if (nb_digit[country]==2) | ||
508 | { | ||
509 | if (cur_pos==2) | ||
510 | cur_pos=1; | ||
511 | if (cur_pos>2) | ||
512 | inc=pow10(3+cur_pos-1); | ||
513 | else | ||
514 | inc=pow10(3+cur_pos); | ||
515 | } | ||
516 | else | ||
517 | inc=pow10(5+cur_pos); | ||
518 | |||
519 | } | ||
520 | break; | ||
521 | |||
522 | case BUTTON_PLAY|BUTTON_REL: | ||
523 | cur_pos++; | ||
524 | if (!pos) | ||
525 | { | ||
526 | if (cur_pos>8) | ||
527 | cur_pos=8; | ||
528 | if (cur_pos==2) | ||
529 | cur_pos=3; | ||
530 | if (cur_pos>2) | ||
531 | inc=pow10(3+cur_pos-1); | ||
532 | else | ||
533 | inc=pow10(3+cur_pos); | ||
534 | } | ||
535 | else | ||
536 | { | ||
537 | if (cur_pos>8) | ||
538 | cur_pos=8; | ||
539 | if (nb_digit[country]==2) | ||
540 | { | ||
541 | if (cur_pos==2) | ||
542 | cur_pos=3; | ||
543 | if (cur_pos>2) | ||
544 | inc=pow10(3+cur_pos-1); | ||
545 | else | ||
546 | inc=pow10(3+cur_pos); | ||
547 | } | ||
548 | else | ||
549 | inc=pow10(5+cur_pos); | ||
550 | } | ||
551 | break; | ||
552 | |||
553 | case BUTTON_LEFT|BUTTON_REL: | ||
554 | case BUTTON_LEFT|BUTTON_REPEAT: | ||
555 | if (!pos) | ||
556 | { | ||
557 | e-=inc; | ||
558 | if (e<0) | ||
559 | e=0; | ||
560 | } | ||
561 | else | ||
562 | { | ||
563 | h-=inc; | ||
564 | if (h<0) | ||
565 | h=0; | ||
566 | } | ||
567 | break; | ||
568 | |||
569 | case BUTTON_RIGHT|BUTTON_REL: | ||
570 | case BUTTON_RIGHT|BUTTON_REPEAT: | ||
571 | old_e=e; | ||
572 | old_h=h; | ||
573 | if (!pos) | ||
574 | { | ||
575 | e+=inc; | ||
576 | if (e>max_euro[country]) | ||
577 | e=old_e; | ||
578 | } | ||
579 | else | ||
580 | { | ||
581 | h+=inc; | ||
582 | if (h>max_curr[country]) | ||
583 | h=old_h; | ||
584 | } | ||
585 | break; | ||
586 | |||
587 | default: | ||
588 | exit_on_usb(button); | ||
589 | break; | ||
590 | } | ||
591 | /*Display*/ | ||
592 | if (!pos) /*Euro>home*/ | ||
593 | h=mymul(e,currency[country]); | ||
594 | else /*Home>euro*/ | ||
595 | e=mydiv(h,currency[country]); | ||
596 | display(e,h,pos); | ||
597 | } | ||
598 | return PLUGIN_OK; | ||
599 | } | ||