1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2003 Pierre Delore
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 ****************************************************************************/
22 #include "lib/configfile.h"
23 #include "lib/pluginlib_exit.h"
25 /* Euro converter for the player */
33 ON+PLAY : Swap Euro<>Home
34 MENU : Display the Menu
35 Currency -> Allows to choose the currency
36 Exit-> Exit the plugin
40 I use signed long long (64 bits).
41 A value have 5 digits after the . (123.45 = 12345000)
44 - The Irish currency needs 6 digits after the . to have sufficient precision on big number
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 */
54 /* typedef for simplifying usage of long long type */
55 typedef long long int longlong_t
;
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*/
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*/
77 /* Number of digit of the currency (for the display) */
78 static int nb_digit
[12]={
88 2, /*NLG Netherlands*/
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 */
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 */
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*/
142 static unsigned long heuro
,hhome
; /*Handles for the new patterns*/
144 static char *currency_str
[12] = {
160 static int country
; /*Country selected*/
161 static int cur_pos
; /*Cursor position*/
162 static longlong_t inc
;
164 /* Persistent settings */
165 static struct configdata config
[] = {
166 { TYPE_ENUM
, 0, 12, { .int_p
= &country
}, "country", currency_str
}
170 /* 64bits*64 bits with 5 digits after the . */
171 static longlong_t
mymul(longlong_t a
, longlong_t b
)
173 return((a
*b
)/100000LL);
177 /* 64bits/64 bits with 5 digits after the . */
178 static longlong_t
mydiv(longlong_t a
, longlong_t b
)
180 return((a
*100000LL)/b
);
184 /* 123.45=12345000 split => i=123 f=45000*/
185 static void split(longlong_t v
, longlong_t
* i
, longlong_t
* f
)
191 (*f
)=(v
-(t
*100000LL));
196 static longlong_t
pow10(int n
)
208 /* round the i.f at n digit after the . */
209 static void round(longlong_t
* i
, longlong_t
* f
, int n
)
220 (*f
)=((*f
)/(int)pow10(5-n
))+add
;
235 /* Display the imput and the result
236 pos: false : first line
239 static void display(longlong_t euro
, longlong_t home
, bool pos
)
242 unsigned char str
[20];
243 unsigned char s1
[20];
244 unsigned char s2
[20];
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");
252 rb
->strcpy(s2
,"\xee\x84\x90%09d");
256 rb
->strcpy(s1
,"\xee\x84\x90%06d.%02d");
257 if (nb_digit
[country
]==2)
258 rb
->strcpy(s2
," %6d.%02d");
260 rb
->strcpy(s2
," %9d");
263 rb
->lcd_remove_cursor();
265 rb
->lcd_putc(0,0,heuro
);
269 rb
->snprintf(str
,sizeof(str
),s1
,(int)i
,(int)f
);
273 rb
->lcd_puts(1,0,str
);
274 rb
->lcd_put_cursor(10-cur_pos
,0,0x5F);
277 rb
->lcd_puts_scroll(1,0,str
);
280 rb
->lcd_putc(0,1,hhome
);
283 round(&i
,&f
,nb_digit
[country
]);
284 rb
->snprintf(str
,sizeof(str
),s2
,(int)i
,(int)f
);
287 rb
->lcd_puts(1,1,str
);
288 rb
->lcd_put_cursor(10-cur_pos
,1,0x5F);
291 rb
->lcd_puts_scroll(1,1,str
);
297 /* Show country Abbreviation */
298 static void show_abbrev(void)
300 rb
->splash(HZ
*3/4,abbrev_str
[country
]);
304 /* Save the config to disk */
305 static void save_config(void)
307 configfile_save(cfg_filename
, config
, 1, CFGFILE_VERSION
);
311 /* Load the config from disk */
312 static void load_config(void)
314 configfile_load(cfg_filename
, config
, 1, CFGFILE_MINVERSION
);
319 static void currency_menu(void)
323 rb
->lcd_clear_display();
326 rb
->lcd_puts(0,0,"Currency:");
327 rb
->lcd_puts(0,1,currency_str
[c
]);
329 switch (rb
->button_get(true))
331 case BUTTON_RIGHT
|BUTTON_REL
:
336 case BUTTON_LEFT
|BUTTON_REL
:
341 case BUTTON_PLAY
|BUTTON_REL
:
346 case BUTTON_STOP
|BUTTON_REL
:
353 /* Display the choice menu. */
354 static int euro_menu(void)
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);
367 switch (rb
->button_get(true))
369 case BUTTON_RIGHT
|BUTTON_REL
:
372 case BUTTON_LEFT
|BUTTON_REL
:
375 case BUTTON_PLAY
|BUTTON_REL
:
381 case BUTTON_STOP
|BUTTON_REL
:
388 /* Call when the program end */
389 static void euro_exit(void)
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
);
396 rb
->lcd_clear_display();
401 /* this is the plugin entry point */
402 enum plugin_status
plugin_start(const void* parameter
)
405 longlong_t e
,h
,old_e
,old_h
;
408 /* if you don't use the parameter, you can do like
409 this to avoid the compiler warning about it */
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
);
429 /*Empty the event queue*/
430 rb
->button_clear_queue();
439 button
= rb
->button_get(true);
442 case BUTTON_MENU
|BUTTON_REL
:
451 if (e
>max_euro
[country
])
457 if (h
>max_curr
[country
])
459 if (nb_digit
[country
]==2)
468 case BUTTON_ON
| BUTTON_PLAY
:
471 case BUTTON_ON
| BUTTON_REL
:
482 if (nb_digit
[country
]==2)
490 case BUTTON_STOP
|BUTTON_REL
:
499 inc
=pow10(3+cur_pos
-1);
501 inc
=pow10(3+cur_pos
);
507 if (nb_digit
[country
]==2)
512 inc
=pow10(3+cur_pos
-1);
514 inc
=pow10(3+cur_pos
);
517 inc
=pow10(5+cur_pos
);
522 case BUTTON_PLAY
|BUTTON_REL
:
531 inc
=pow10(3+cur_pos
-1);
533 inc
=pow10(3+cur_pos
);
539 if (nb_digit
[country
]==2)
544 inc
=pow10(3+cur_pos
-1);
546 inc
=pow10(3+cur_pos
);
549 inc
=pow10(5+cur_pos
);
553 case BUTTON_LEFT
|BUTTON_REL
:
554 case BUTTON_LEFT
|BUTTON_REPEAT
:
569 case BUTTON_RIGHT
|BUTTON_REL
:
570 case BUTTON_RIGHT
|BUTTON_REPEAT
:
576 if (e
>max_euro
[country
])
582 if (h
>max_curr
[country
])
592 if (!pos
) /*Euro>home*/
593 h
=mymul(e
,currency
[country
]);
595 e
=mydiv(h
,currency
[country
]);