summaryrefslogtreecommitdiff
path: root/apps/plugins/periodic_table.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/periodic_table.c')
-rw-r--r--apps/plugins/periodic_table.c724
1 files changed, 724 insertions, 0 deletions
diff --git a/apps/plugins/periodic_table.c b/apps/plugins/periodic_table.c
new file mode 100644
index 0000000000..19452fd5de
--- /dev/null
+++ b/apps/plugins/periodic_table.c
@@ -0,0 +1,724 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Jonathan Bettencourt (jonrelay)
11 * (C) 2009 Port to Rockbox by: Yifu Huang
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software Foundation,
28 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 *
30 ****************************************************************************/
31
32#include "plugin.h"
33#include "lib/pluginlib_actions.h"
34
35/* - - - PERIODIC TABLE DATA - - - */
36
37struct periodic_element_t {
38 int group;
39 int period;
40 int number;
41 char *symbol;
42 char *name;
43 char *mass;
44 char *density;
45 char *fpoint; /* freezing point */
46 char *bpoint; /* boiling point */
47 char block; /* s, p, d, f */
48 int color; /* in periodic_color_palette below */
49 uint8_t up; /* index of element "up" from this */
50 uint8_t down; /* index of element "down" from this */
51};
52
53static const struct periodic_element_t periodic_elements[] = {
54 { 1, 1, 1, "H", "Hydrogen", "1.00794", "0.0899", "-259.14", "-252.87", 's', 0 , 86, 2},
55 { 18, 1, 2, "He", "Helium", "4.002602", "0.1785", "-272.2", "-268.934", 's', 9 , 117, 9},
56 { 1, 2, 3, "Li", "Lithium", "6.941", "0.534", "180.54", "1347", 's', 1 , 0, 10},
57 { 2, 2, 4, "Be", "Beryllium", "9.012182", "1.848", "1287", "2472", 's', 2 , 87, 11},
58 { 13, 2, 5, "B", "Boron", "10.811", "2.34", "2077", "3870", 'p', 5 , 112, 12},
59 { 14, 2, 6, "C", "Carbon", "12.0107", "2.250", "3727", "3827", 'p', 6 , 113, 13},
60 { 15, 2, 7, "N", "Nitrogen", "14.0067", "1.2506", "-209.86", "-195.8", 'p', 6 , 114, 14},
61 { 16, 2, 8, "O", "Oxygen", "15.9994", "1.4291", "-218.4", "-182.96", 'p', 6 , 115, 15},
62 { 17, 2, 9, "F", "Fluorine", "18.9984032", "1.696", "-219.62", "-188.14", 'p', 7 , 116, 16},
63 { 18, 2, 10, "Ne", "Neon", "20.1797", "0.899990", "-248.67", "-246.048", 'p', 9 , 1, 17},
64 { 1, 3, 11, "Na", "Sodium", "22.98976928", "0.971", "97.81", "883", 's', 1 , 2, 18},
65 { 2, 3, 12, "Mg", "Magnesium", "24.3050", "1.738", "650", "1095", 's', 2 , 3, 19},
66 { 13, 3, 13, "Al", "Aluminum", "26.9815386", "2.6989", "660.323", "2520", 'p', 4 , 4, 30},
67 { 14, 3, 14, "Si", "Silicon", "28.0855", "2.329", "1412", "3266", 'p', 5 , 5, 31},
68 { 15, 3, 15, "P", "Phosphorus", "30.973762", "1.82", "44.1", "280.5", 'p', 6 , 6, 32},
69 { 16, 3, 16, "S", "Sulfur", "32.065", "2.07", "112.8", "444.674", 'p', 6 , 7, 33},
70 { 17, 3, 17, "Cl", "Chlorine", "35.453", "3.214", "-100.98", "-34.05", 'p', 7 , 8, 34},
71 { 18, 3, 18, "Ar", "Argon", "39.948", "1.7837", "-189.2", "-185.86", 'p', 9 , 9, 35},
72 { 1, 4, 19, "K", "Potassium", "39.0983", "0.862", "63.65", "765", 's', 1 , 10, 36},
73 { 2, 4, 20, "Ca", "Calcium", "40.078", "1.55", "842", "1503", 's', 2 , 11, 37},
74 { 3, 4, 21, "Sc", "Scandium", "44.955912", "2.989", "1539", "2831", 'd', 3 , 38, 38},
75 { 4, 4, 22, "Ti", "Titanium", "47.867", "4.54", "1666", "3289", 'd', 3 , 103, 39},
76 { 5, 4, 23, "V", "Vanadium", "50.9415", "6.11", "1917", "3420", 'd', 3 , 104, 40},
77 { 6, 4, 24, "Cr", "Chromium", "51.9961", "7.20", "1857", "2682", 'd', 3 , 105, 41},
78 { 7, 4, 25, "Mn", "Manganese", "54.938045", "7.44", "1246", "2062", 'd', 3 , 106, 42},
79 { 8, 4, 26, "Fe", "Iron", "55.845", "7.874", "1536", "2863", 'd', 3 , 107, 43},
80 { 9, 4, 27, "Co", "Cobalt", "58.933195", "8.9", "1495", "2930", 'd', 3 , 108, 44},
81 { 10, 4, 28, "Ni", "Nickel", "58.6934", "8.902", "1455", "2890", 'd', 3 , 109, 45},
82 { 11, 4, 29, "Cu", "Copper", "63.546", "8.96", "1084.62", "2571", 'd', 3 , 110, 46},
83 { 12, 4, 30, "Zn", "Zinc", "65.38", "7.13", "419.527", "907", 'd', 3 , 111, 47},
84 { 13, 4, 31, "Ga", "Gallium", "69.723", "5.904", "29.7646", "2208", 'p', 4 , 12, 48},
85 { 14, 4, 32, "Ge", "Germanium", "72.64", "5.323", "937.4", "2834", 'p', 5 , 13, 49},
86 { 15, 4, 33, "As", "Arsenic", "74.92160", "5.73", "817", "603", 'p', 5 , 14, 50},
87 { 16, 4, 34, "Se", "Selenium", "78.96", "4.79", "220.2", "684.9", 'p', 6 , 15, 51},
88 { 17, 4, 35, "Br", "Bromine", "79.904", "3.12", "-7.2", "58.78", 'p', 7 , 16, 52},
89 { 18, 4, 36, "Kr", "Krypton", "83.798", "3.733", "-156.6", "-153.35", 'p', 9 , 17, 53},
90 { 1, 5, 37, "Rb", "Rubidium", "85.4678", "1.532", "38.89", "688", 's', 1 , 18, 54},
91 { 2, 5, 38, "Sr", "Strontium", "87.62", "2.54", "777", "1414", 's', 2 , 19, 55},
92 { 3, 5, 39, "Y", "Yttrium", "88.90585", "4.469", "1520", "3388", 'd', 3 , 20, 20},
93 { 4, 5, 40, "Zr", "Zirconium", "91.224", "6.506", "1852", "4361", 'd', 3 , 21, 71},
94 { 5, 5, 41, "Nb", "Niobium", "92.90638", "8.57", "2477", "4744", 'd', 3 , 22, 72},
95 { 6, 5, 42, "Mo", "Molybdenum", "95.96", "10.22", "2623", "4682", 'd', 3 , 23, 73},
96 { 7, 5, 43, "Tc", "Technetium", "[98]", "11.500", "2157", "4265", 'd', 3 , 24, 74},
97 { 8, 5, 44, "Ru", "Ruthenium", "101.07", "12.41", "2250", "4155", 'd', 3 , 25, 75},
98 { 9, 5, 45, "Rh", "Rhodium", "102.90550", "12.41", "1960", "3697", 'd', 3 , 26, 76},
99 { 10, 5, 46, "Pd", "Palladium", "106.42", "12.02", "1552", "2964", 'd', 3 , 27, 77},
100 { 11, 5, 47, "Ag", "Silver", "107.8682", "10.50", "961.78", "2162", 'd', 3 , 28, 78},
101 { 12, 5, 48, "Cd", "Cadmium", "112.411", "8.65", "321.03", "767", 'd', 3 , 29, 79},
102 { 13, 5, 49, "In", "Indium", "114.818", "7.31", "156.5985", "2072", 'p', 4 , 30, 80},
103 { 14, 5, 50, "Sn", "Tin", "118.710", "7.31", "231.968", "2603", 'p', 4 , 31, 81},
104 { 15, 5, 51, "Sb", "Antimony", "121.760", "6.691", "630.74", "1587", 'p', 5 , 32, 82},
105 { 16, 5, 52, "Te", "Tellurium", "127.60", "6.24", "449.8", "991", 'p', 5 , 33, 83},
106 { 17, 5, 53, "I", "Iodine", "126.90447", "4.93", "113.6", "184.35", 'p', 7 , 34, 84},
107 { 18, 5, 54, "Xe", "Xenon", "131.293", "5.887", "-111.9", "-108.1", 'p', 9 , 35, 85},
108 { 1, 6, 55, "Cs", "Caesium", "132.9054519", "1.873", "28.4", "658", 's', 1 , 36, 86},
109 { 2, 6, 56, "Ba", "Barium", "137.327", "3.51", "729", "1898", 's', 2 , 37, 87},
110 { 2, 9, 57, "La", "Lanthanum", "138.90547", "6.145", "920", "3461", 'd', 3 , 88, 88},
111 { 3, 9, 58, "Ce", "Cerium", "140.116", "6.757", "799", "3426", 'f', 10 , 89, 89},
112 { 4, 9, 59, "Pr", "Praseodymium", "140.90765", "6.773", "931", "3520", 'f', 10 , 90, 90},
113 { 5, 9, 60, "Nd", "Neodymium", "144.242", "7.007", "1021", "3074", 'f', 10 , 91, 91},
114 { 6, 9, 61, "Pm", "Promethium", "[145]", "7.220", "1100", "3000", 'f', 10 , 92, 92},
115 { 7, 9, 62, "Sm", "Samarium", "150.36", "7.520", "1072", "1791", 'f', 10 , 93, 93},
116 { 8, 9, 63, "Eu", "Europium", "151.964", "5.243", "822", "1529", 'f', 10 , 94, 94},
117 { 9, 9, 64, "Gd", "Gadolinium", "157.25", "7.9004", "1312", "3266", 'f', 10 , 95, 95},
118 { 10, 9, 65, "Tb", "Terbium", "158.92535", "8.229", "1356", "3230", 'f', 10 , 96, 96},
119 { 11, 9, 66, "Dy", "Dysprosium", "162.500", "8.550", "1412", "2567", 'f', 10 , 97, 97},
120 { 12, 9, 67, "Ho", "Holmium", "164.93032", "8.795", "1474", "2700", 'f', 10 , 98, 98},
121 { 13, 9, 68, "Er", "Erbium", "167.259", "9.066", "1529", "2868", 'f', 10 , 99, 99},
122 { 14, 9, 69, "Tm", "Thulium", "168.93421", "9.321", "1545", "1950", 'f', 10 , 100, 100},
123 { 15, 9, 70, "Yb", "Ytterbium", "173.054", "6.965", "819", "1196", 'f', 10 , 101, 101},
124 { 16, 9, 71, "Lu", "Lutetium", "174.9668", "9.840", "1663", "3402", 'f', 10 , 102, 102},
125 { 4, 6, 72, "Hf", "Hafnium", "178.49", "13.31", "2233", "4603", 'd', 3 , 39, 103},
126 { 5, 6, 73, "Ta", "Tantalum", "180.94788", "16.654", "2985", "5510", 'd', 3 , 40, 104},
127 { 6, 6, 74, "W", "Tungsten", "183.84", "19.3", "3407", "5555", 'd', 3 , 41, 105},
128 { 7, 6, 75, "Re", "Rhenium", "186.207", "21.02", "3180", "5596", 'd', 3 , 42, 106},
129 { 8, 6, 76, "Os", "Osmium", "190.23", "22.57", "3045", "5012", 'd', 3 , 43, 107},
130 { 9, 6, 77, "Ir", "Iridium", "192.217", "22.42", "2443", "4437", 'd', 3 , 44, 108},
131 { 10, 6, 78, "Pt", "Platinum", "195.084", "21.45", "1769", "3827", 'd', 3 , 45, 109},
132 { 11, 6, 79, "Au", "Gold", "196.966569", "19.32", "1064.18", "2857", 'd', 3 , 46, 110},
133 { 12, 6, 80, "Hg", "Mercury", "200.59", "13.546", "-38.842", "356.58", 'd', 3 , 47, 111},
134 { 13, 6, 81, "Tl", "Thallium", "204.3833", "11.85", "303.5", "1473", 'p', 4 , 48, 112},
135 { 14, 6, 82, "Pb", "Lead", "207.2", "11.35", "327.5", "1750", 'p', 4 , 49, 113},
136 { 15, 6, 83, "Bi", "Bismuth", "208.98040", "9.747", "271.4", "1561", 'p', 4 , 50, 114},
137 { 16, 6, 84, "Po", "Polonium", "[209]", "9.32", "254", "962", 'p', 4 , 51, 115},
138 { 17, 6, 85, "At", "Astatine", "[210]", "-", "302", "337", 'p', 8 , 52, 116},
139 { 18, 6, 86, "Rn", "Radon", "[222]", "9.73", "-71", "-61.8", 'p', 9 , 53, 117},
140 { 1, 7, 87, "Fr", "Francium", "[223]", "2.410", "27", "657", 's', 1 , 54, 0},
141 { 2, 7, 88, "Ra", "Radium", "[226]", "5.00", "700", "1140", 's', 2 , 55, 3},
142 { 2, 10, 89, "Ac", "Actinium", "[227]", "10.07", "1051", "3200", 'd', 4 , 56, 56},
143 { 3, 10, 90, "Th", "Thorium", "232.03806", "11.720", "1750", "4789", 'f', 11 , 57, 57},
144 { 4, 10, 91, "Pa", "Protactinium", "231.03588", "15.370", "1567", "4227", 'f', 11 , 58, 58},
145 { 5, 10, 92, "U", "Uranium", "238.02891", "18.95", "1132.3", "4172", 'f', 11 , 59, 59},
146 { 6, 10, 93, "Np", "Neptunium", "[237]", "20.45", "637", "4000", 'f', 11 , 60, 60},
147 { 7, 10, 94, "Pu", "Plutonium", "[244]", "19.84", "639.5", "3231", 'f', 11 , 61, 61},
148 { 8, 10, 95, "Am", "Americiam", "[243]", "13.67", "1176", "2607", 'f', 11 , 62, 62},
149 { 9, 10, 96, "Cm", "Curium", "[247]", "13.51", "1340", "3110", 'f', 11 , 63, 63},
150 { 10, 10, 97, "Bk", "Berkelium", "[247]", "14.78", "986", "-", 'f', 11 , 64, 64},
151 { 11, 10, 98, "Cf", "Californium", "[251]", "15.1", "900", "-", 'f', 11 , 65, 65},
152 { 12, 10, 99, "Es", "Einsteinium", "[252]", "-", "860", "-", 'f', 11 , 66, 66},
153 { 13, 10, 100, "Fm", "Fermium", "[257]", "-", "1527", "-", 'f', 11 , 67, 67},
154 { 14, 10, 101, "Md", "Mendelevium", "[258]", "-", "827", "-", 'f', 11 , 68, 68},
155 { 15, 10, 102, "No", "Nobelium", "[259]", "-", "827", "-", 'f', 11 , 69, 69},
156 { 16, 10, 103, "Lr", "Lawrencium", "[262]", "-", "1627", "-", 'f', 11 , 70, 70},
157 { 4, 7, 104, "Rf", "Rutherfordium", "[267]", "-", "-", "-", 'd', 3 , 71, 21},
158 { 5, 7, 105, "Db", "Dubnium", "[268]", "-", "-", "-", 'd', 3 , 72, 22},
159 { 6, 7, 106, "Sg", "Seaborgium", "[271]", "-", "-", "-", 'd', 3 , 73, 23},
160 { 7, 7, 107, "Bh", "Bhorium", "[272]", "-", "-", "-", 'd', 3 , 74, 24},
161 { 8, 7, 108, "Hs", "Hassium", "[270]", "-", "-", "-", 'd', 3 , 75, 25},
162 { 9, 7, 109, "Mt", "Meitnerium", "[276]", "-", "-", "-", 'd', 3 , 76, 26},
163 { 10, 7, 110, "Ds", "Darmstadtium", "[281]", "-", "-", "-", 'd', 3 , 77, 27},
164 { 11, 7, 111, "Rg", "Roentgenium", "[280]", "-", "-", "-", 'd', 3 , 78, 28},
165 { 12, 7, 112, "Uub", "Ununbium", "[285]", "-", "-", "-", 'd', 3 , 79, 29},
166 { 13, 7, 113, "Uut", "Ununtrium", "[284]", "-", "-", "-", 'p', 4 , 80, 4},
167 { 14, 7, 114, "Uuq", "Ununquadium", "[289]", "-", "-", "-", 'p', 4 , 81, 5},
168 { 15, 7, 115, "Uup", "Ununpentium", "[288]", "-", "-", "-", 'p', 4 , 82, 6},
169 { 16, 7, 116, "Uuh", "Ununhexium", "[293]", "-", "-", "-", 'p', 4 , 83, 7},
170 { 17, 7, 117, "Uus", "Ununseptium", "[294]", "-", "-", "-", 'p', 4 , 84, 8},
171 { 18, 7, 118, "Uuo", "Ununoctium", "[294]", "-", "-", "-", 'p', 9 , 85, 1}
172};
173
174#define ELEMENTS_COUNT sizeof(periodic_elements)/sizeof(struct periodic_element_t)
175
176/* - - - PERIODIC TABLE VARIABLES - - - */
177#if LCD_DEPTH > 1
178static unsigned periodic_color_palette[12];
179static unsigned int theme_fg, theme_bg;
180#endif
181static unsigned int periodic_sel = 0;
182static int font_height = 0;
183
184/* - - - TINYFONT - - - */
185
186static const long int periodic_tinyfont_bitmaps[] = {
187 0x00000000, 0x00220200, 0x00550000, 0x00575750, 0x00236200, 0x00514500, 0x00236300, 0x00220000,
188 0x00244200, 0x00211200, 0x00272720, 0x00027200, 0x00000240, 0x00007000, 0x00000200, 0x00122400,
189 0x00255200, 0x00262700, 0x00612700, 0x00631600, 0x00571100, 0x00761600, 0x00365200, 0x00712200,
190 0x00725200, 0x00353100, 0x00020200, 0x00020240, 0x00024200, 0x00070700, 0x00021200, 0x00610200,
191
192 0x00254300, 0x00257500, 0x00675600, 0x00344300, 0x00655600, 0x00764700, 0x00746400, 0x00345300,
193 0x00577500, 0x00722700, 0x00722400, 0x00566500, 0x00444700, 0x00775500, 0x00575500, 0x00255200,
194 0x00656400, 0x00255300, 0x00656500, 0x00363600, 0x00722200, 0x00555200, 0x00552200, 0x00557700,
195 0x00522500, 0x00522200, 0x00714700, 0x00322300, 0x00422100, 0x00622600, 0x00250000, 0x00000700,
196
197 0x00420000, 0x00063300, 0x00465600, 0x00034300, 0x00135300, 0x00026300, 0x00127200, 0x00035360,
198 0x00465500, 0x00202200, 0x00202240, 0x00456500, 0x00222200, 0x00067500, 0x00065500, 0x00025200,
199 0x00065640, 0x00035310, 0x00056400, 0x00032600, 0x00272100, 0x00055300, 0x00057200, 0x00057700,
200 0x00052500, 0x00055360, 0x00072700, 0x00162100, 0x00222220, 0x00432400, 0x00630000, 0x00525250
201};
202
203static void periodic_tinyfont_draw_char(int x, int y, char ch)
204{
205 int i,j;
206 int r;
207 long int bmp = periodic_tinyfont_bitmaps[ch-' '];
208 for (i=7; i>=0; i--) {
209 r = bmp & 15;
210 bmp /= 16;
211 for (j=3; j>=0; j--) {
212 if (r & 1) {
213 rb->lcd_drawpixel(x+j, y+i);
214 }
215 r /= 2;
216 }
217 }
218}
219
220static void periodic_tinyfont_draw_string(int x, int y, char * s)
221{
222 char * t = s;
223 int xx = x;
224 int yy = y;
225 while (*t) {
226 if ((*t) == 10) {
227 xx = x;
228 yy += 8;
229 } else {
230 periodic_tinyfont_draw_char(xx, yy, *t);
231 xx += 4;
232 }
233 t++;
234 }
235}
236
237/*
238 void periodic_tinyfont_draw_chart(int x, int y, ttk_color col)
239 {
240 unsigned char ch;
241 int xx = x;
242 int yy = y;
243 for (ch = 32; ch < 128; ch++) {
244 periodic_tinyfont_draw_char(xx, yy, ch, col);
245 if ((ch % 16) == 15) {
246 xx = x;
247 yy += 8;
248 } else {
249 xx += 4;
250 }
251 }
252 }
253*/
254
255/* - - - KEYMAP - - - */
256
257static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
258
259#define PERIODIC_KEY_SELECT PLA_SELECT
260#define PERIODIC_KEY_MENU PLA_CANCEL
261#define PERIODIC_KEY_BACK PLA_LEFT
262#define PERIODIC_KEY_FORWARD PLA_RIGHT
263#define PERIODIC_KEY_UP PLA_UP
264#define PERIODIC_KEY_DOWN PLA_DOWN
265#define PERIODIC_KEY_BACK_RPT PLA_LEFT_REPEAT
266#define PERIODIC_KEY_FORWARD_RPT PLA_RIGHT_REPEAT
267#define PERIODIC_KEY_UP_RPT PLA_UP_REPEAT
268#define PERIODIC_KEY_DOWN_RPT PLA_DOWN_REPEAT
269
270
271/* - - - SOME CONSTANTS - - - */
272#ifdef HAVE_LCD_COLOR
273#define PERIODIC_COLOR_BLACK LCD_RGBPACK(0,0,0)
274#elif LCD_DEPTH > 1
275#define PERIODIC_COLOR_BLACK LCD_BLACK
276#endif
277
278#ifdef HAVE_LCD_COLOR
279#define PERIODIC_COLOR_WHITE LCD_RGBPACK(255,255,255)
280#elif LCD_DEPTH > 1
281#define PERIODIC_COLOR_WHITE LCD_WHITE
282#endif
283
284#define CELLSIZE ((LCD_WIDTH-1)/18)
285#define NUM_LINE ((LCD_HEIGHT - CELLSIZE * 10 + (CELLSIZE >> 1))/font_height)
286
287#define CELSIUS "\xc2\xb0\x43"
288#define CUBIC_CENTIMETER "\x63\x6d\xc2\xb3"
289
290/* - - - PERIODIC TABLE HELPER FUNCTIONS - - - */
291
292static void periodic_makecols(void)
293{
294#ifdef HAVE_LCD_COLOR
295 int i = 0;
296
297 periodic_color_palette[i++] = LCD_RGBPACK(255,255,255); /* 0 hydrogen */
298 periodic_color_palette[i++] = LCD_RGBPACK(221,221,221); /* 1 alkali metals */
299 periodic_color_palette[i++] = LCD_RGBPACK(187,187,187); /* 2 earth metals */
300 periodic_color_palette[i++] = LCD_RGBPACK(255,204,255); /* 3 transition metals */
301 periodic_color_palette[i++] = LCD_RGBPACK(255,204,204); /* 4 other metals */
302 periodic_color_palette[i++] = LCD_RGBPACK(255,204,153); /* 5 metalloids */
303 periodic_color_palette[i++] = LCD_RGBPACK(255,255,204); /* 6 nonmetals */
304 periodic_color_palette[i++] = LCD_RGBPACK(204,255,204); /* 7 halogens */
305 periodic_color_palette[i++] = LCD_RGBPACK(204,204,153); /* 8 astatine */
306 periodic_color_palette[i++] = LCD_RGBPACK(204,255,255); /* 9 noble gases */
307 periodic_color_palette[i++] = LCD_RGBPACK(153,204,255); /* 10 lanthanides */
308 periodic_color_palette[i++] = LCD_RGBPACK(204,153,255); /* 11 actinides */
309#elif LCD_DEPTH > 1
310 int i = 0;
311
312 periodic_color_palette[i++] = LCD_WHITE; /* 0 hydrogen */
313 periodic_color_palette[i++] = LCD_DARKGRAY; /* 1 alkali metals */
314 periodic_color_palette[i++] = LCD_DARKGRAY; /* 2 earth metals */
315 periodic_color_palette[i++] = LCD_WHITE; /* 3 transition metals */
316 periodic_color_palette[i++] = LCD_WHITE; /* 4 other metals */
317 periodic_color_palette[i++] = LCD_DARKGRAY; /* 5 metalloids */
318 periodic_color_palette[i++] = LCD_WHITE; /* 6 nonmetals */
319 periodic_color_palette[i++] = LCD_WHITE; /* 7 halogens */
320 periodic_color_palette[i++] = LCD_DARKGRAY; /* 8 astatine */
321 periodic_color_palette[i++] = LCD_WHITE; /* 9 noble gases */
322 periodic_color_palette[i++] = LCD_DARKGRAY; /* 10 lanthanides */
323 periodic_color_palette[i++] = LCD_DARKGRAY; /* 11 actinides */
324#endif
325}
326
327static int periodic_fix_period(int p)
328{
329 /* lanthanides/actinides are periods 9/10 in the internal chart, but make them look like 6/7 in the displayed table */
330 return (p>8)?(p-3):p;
331}
332
333static int periodic_fix_group(int g, int p)
334{
335 return (p>8)?0:g;
336}
337
338static char * periodic_group_name(int i)
339{
340 if (i==1) {
341 return "Noble Gases";
342 }
343 else if (periodic_elements[i].period > 8)
344 {
345 switch (periodic_elements[i].period)
346 {
347 case 9:
348 return "Lanthanides";
349 break;
350 case 10:
351 return "Actinides";
352 break;
353 }
354 return "";
355 }
356 else if (i>1)
357 {
358 switch (periodic_elements[i].group) {
359 case 1:
360 return "Alkali Metals";
361 break;
362 case 2:
363 return "Alkaline Earth Metals";
364 break;
365 case 15:
366 return "Pnictogens";
367 break;
368 case 16:
369 return "Chalcogens";
370 break;
371 case 17:
372 return "Halogens";
373 break;
374 case 18:
375 return "Noble Gases";
376 break;
377 }
378 }
379 return "";
380}
381
382static void periodic_draw_element(unsigned int i, int bx, int by)
383{
384 int ex = (bx+((periodic_elements[i].group-1) * CELLSIZE));
385 int ey = (by+((periodic_elements[i].period-1) * CELLSIZE));
386#if LCD_DEPTH > 1
387 int tx, ty;
388 char tt[4];
389#endif
390
391 if (periodic_elements[i].period > 8)
392 ey -= (CELLSIZE >> 1);
393
394 if (i == periodic_sel)
395 {
396#if LCD_DEPTH > 1
397 rb->lcd_set_foreground(PERIODIC_COLOR_BLACK);
398#endif
399#if LCD_DEPTH > 1
400 rb->lcd_fillrect(ex, ey, CELLSIZE+1, CELLSIZE+1);
401#else
402 rb->lcd_set_drawmode(DRMODE_FG);
403 rb->lcd_fillrect(ex, ey, CELLSIZE+1, CELLSIZE+1);
404 rb->lcd_set_drawmode(DRMODE_SOLID);
405#endif
406 }
407 else
408 {
409#if LCD_DEPTH > 1
410 rb->lcd_set_foreground(periodic_color_palette[periodic_elements[i].color]);
411 rb->lcd_fillrect(ex, ey, CELLSIZE+1, CELLSIZE+1);
412 rb->lcd_set_foreground(PERIODIC_COLOR_BLACK);
413#else
414 rb->lcd_set_drawmode(DRMODE_BG+DRMODE_INVERSEVID);
415 rb->lcd_fillrect(ex, ey, CELLSIZE+1, CELLSIZE+1);
416 rb->lcd_set_drawmode(DRMODE_SOLID);
417#endif
418 rb->lcd_drawrect(ex, ey, CELLSIZE+1, CELLSIZE+1);
419 }
420#if LCD_DEPTH > 1
421 if (CELLSIZE >= 8) {
422 rb->strcpy(tt, periodic_elements[i].symbol);
423 if (rb->strlen(tt) > 2) {
424 tt[1] = tt[rb->strlen(tt)-1];
425 tt[2] = 0;
426 tx = ex + (CELLSIZE >> 1) - 4;
427 } else if (tt[1] != 0) {
428 tx = ex + (CELLSIZE >> 1) - 4;
429 } else {
430 tx = ex + (CELLSIZE >> 1) - 2;
431 }
432 ty = ey + (CELLSIZE >> 1) - 4;
433
434 if (i == periodic_sel)
435 {
436 rb->lcd_set_foreground(PERIODIC_COLOR_WHITE);
437 }
438 else
439 {
440 rb->lcd_set_foreground(PERIODIC_COLOR_BLACK);
441 }
442 periodic_tinyfont_draw_string(tx, ty, tt);
443 }
444#endif
445}
446
447static void periodic_draw_table(void)
448{
449 int bx = (LCD_WIDTH - CELLSIZE * 18) >> 1;
450 int by = 1;
451 unsigned int i;
452 for (i = 0; i < ELEMENTS_COUNT; i++) {
453 periodic_draw_element(i, bx, by);
454 }
455}
456
457static void periodic_draw(void)
458{
459 char buf[40];
460
461 periodic_draw_table();
462
463 /* show the info for the current element */
464
465 /* X coordinate of name/group */
466 int nx = (LCD_WIDTH >> 1) - CELLSIZE * 7 + 5;
467
468 /* X coordinate of first column */
469 int fx = 0;
470#if LCD_WIDTH >= 220
471 int sx = (LCD_WIDTH > 220)? 120 : 90;
472#endif
473
474 /* Y coordinate of first/second top column */
475 int ty = LCD_HEIGHT - font_height * NUM_LINE;
476
477 struct periodic_element_t e;
478 e = periodic_elements[periodic_sel];
479
480#ifdef HAVE_LCD_COLOR
481 rb->lcd_set_foreground(theme_fg);
482#endif
483
484 /* display name and group up top */
485#if LCD_WIDTH > 160
486 rb->snprintf(buf, 40, "Name: %s", e.name);
487 rb->lcd_putsxy(nx, 0, buf);
488
489 /* don't show period number for lanthanides/actinides */
490 if(e.period<9)
491 {
492 rb->snprintf(buf, 40, "Group: %d %s", periodic_fix_group(e.group, e.period),
493 periodic_group_name(periodic_sel));
494 }
495 else
496 {
497 rb->snprintf(buf, 40, "Group: %s", periodic_group_name(periodic_sel));
498 }
499 rb->lcd_putsxy(nx, font_height, buf);
500
501#else
502 if (NUM_LINE > 0)
503 {
504 rb->snprintf(buf, 40, "%s", e.name);
505 rb->lcd_putsxy(nx, 0, buf);
506 rb->snprintf(buf, 40, "%d %s", periodic_fix_group(e.group, e.period),
507 periodic_group_name(periodic_sel));
508 rb->lcd_putsxy(nx, font_height, buf);
509 }
510 else
511 {
512 rb->snprintf(buf, 40, "%d %s %s", e.number, e.symbol, e.name);
513 rb->lcd_putsxy(nx, 0, buf);
514 rb->snprintf(buf, 40, "%s amu", e.mass);
515 rb->lcd_putsxy(nx, font_height, buf);
516 }
517#endif
518
519 /* first col of info */
520 if (NUM_LINE >= 8)
521 {
522 rb->snprintf(buf, 40, "Number: %d", e.number);
523 rb->lcd_putsxy(fx, ty, buf);
524 rb->snprintf(buf, 40, "Symbol: %s", e.symbol);
525 rb->lcd_putsxy(fx, ty + font_height, buf);
526 rb->snprintf(buf, 40, "Period: %d", periodic_fix_period(e.period));
527 rb->lcd_putsxy(fx, ty + font_height*2, buf);
528 rb->snprintf(buf, 40, "Block: %c", e.block);
529 rb->lcd_putsxy(fx, ty + font_height*3, buf);
530
531 rb->snprintf(buf, 40, "Mass: %s amu", e.mass);
532 rb->lcd_putsxy(fx, ty + font_height*4, buf);
533 rb->snprintf(buf, 40, "Density: %s g/%s", e.density, CUBIC_CENTIMETER);
534 rb->lcd_putsxy(fx, ty + font_height*5, buf);
535 rb->snprintf(buf, 40, "F Point: %s %s", e.fpoint, CELSIUS);
536 rb->lcd_putsxy(fx, ty + font_height*6, buf);
537 rb->snprintf(buf, 40, "B Point: %s %s", e.bpoint, CELSIUS);
538 rb->lcd_putsxy(fx, ty + font_height*7, buf);
539 }
540 else
541 {
542#if LCD_WIDTH >= 220 /* shuld be NUM_LINE >= 4 */
543 rb->snprintf(buf, 40, "Number: %d", e.number);
544 rb->lcd_putsxy(fx, ty, buf);
545 rb->snprintf(buf, 40, "Symbol: %s", e.symbol);
546 rb->lcd_putsxy(fx, ty + font_height, buf);
547 rb->snprintf(buf, 40, "Period: %d", periodic_fix_period(e.period));
548 rb->lcd_putsxy(fx, ty + font_height*2, buf);
549 rb->snprintf(buf, 40, "Block: %c", e.block);
550 rb->lcd_putsxy(fx, ty + font_height*3, buf);
551#else
552 if (NUM_LINE >= 4)
553 {
554 rb->snprintf(buf, 40, "%d %s P: %d B: %c", e.number, e.symbol,
555 periodic_fix_period(e.period), e.block);
556 rb->lcd_putsxy(fx, ty, buf);
557 rb->snprintf(buf, 40, "M: %s amu", e.mass);
558 rb->lcd_putsxy(fx, ty + font_height, buf);
559 rb->snprintf(buf, 40, "D: %s g/%s", e.density, CUBIC_CENTIMETER);
560 rb->lcd_putsxy(fx, ty + font_height*2, buf);
561 rb->snprintf(buf, 40, "F/B: %s %s / %s %s", e.fpoint, CELSIUS, e.bpoint, CELSIUS);
562 rb->lcd_putsxy(fx, ty + font_height*3, buf);
563 }
564 else
565 {
566 if (NUM_LINE >= 1)
567 {
568 rb->snprintf(buf, 40, "%d %s %s amu", e.number, e.symbol, e.mass);
569 rb->lcd_putsxy(fx, ty, buf);
570 }
571 if (NUM_LINE >= 2)
572 {
573 rb->snprintf(buf, 40, "D: %s g/%s", e.density, CUBIC_CENTIMETER);
574 rb->lcd_putsxy(fx, ty + font_height, buf);
575 }
576 if (NUM_LINE >= 3)
577 {
578 rb->snprintf(buf, 40, "F/B: %s %s / %s %s", e.fpoint, CELSIUS, e.bpoint, CELSIUS);
579 rb->lcd_putsxy(fx, ty + font_height*2, buf);
580 }
581 }
582#endif
583 }
584
585 /* second col of info */
586#if LCD_WIDTH >= 220
587 if (NUM_LINE < 8)
588 {
589 rb->snprintf(buf, 40, "Mass: %s amu", e.mass);
590 rb->lcd_putsxy(sx, ty, buf);
591 rb->snprintf(buf, 40, "Density: %s g/%s", e.density, CUBIC_CENTIMETER);
592 rb->lcd_putsxy(sx, ty + font_height, buf);
593 rb->snprintf(buf, 40, "F Point: %s %s", e.fpoint, CELSIUS);
594 rb->lcd_putsxy(sx, ty + font_height*2, buf);
595 rb->snprintf(buf, 40, "B Point: %s %s", e.bpoint, CELSIUS);
596 rb->lcd_putsxy(sx, ty + font_height*3, buf);
597 }
598#endif
599}
600
601enum plugin_status plugin_start(const void* parameter)
602{
603 (void)parameter;
604
605 periodic_sel = 0;
606 periodic_makecols();
607
608 theme_fg=rb->lcd_get_foreground();
609 theme_bg=rb->lcd_get_background();
610
611 struct font *pf = rb->font_get(FONT_UI);
612 font_height = pf->height;
613
614 while (1) {
615 rb->lcd_set_background(theme_bg);
616 rb->lcd_clear_display();
617 periodic_draw();
618 rb->lcd_update();
619 int button = pluginlib_getaction(-1, plugin_contexts, ARRAYLEN(plugin_contexts));
620 switch (button)
621 {
622 case PERIODIC_KEY_SELECT:
623 break;
624 case PERIODIC_KEY_MENU:
625 return PLUGIN_OK;
626 break;
627 case PERIODIC_KEY_BACK:
628 case PERIODIC_KEY_BACK_RPT:
629 if(periodic_sel==103)
630 {
631 periodic_sel=87;
632 }
633 else if(periodic_sel==88)
634 {
635 periodic_sel=38;
636 break;
637 }
638 else if(periodic_sel==56)
639 {
640 periodic_sel=20;
641 break;
642 }
643 else if(periodic_sel==71)
644 {
645 periodic_sel=55;
646 break;
647 }
648 else if(periodic_sel==39)
649 {
650 periodic_sel=102;
651 break;
652 }
653 else if(periodic_sel==21)
654 {
655 periodic_sel=70;
656 break;
657 }
658 else if (periodic_sel > 0)
659 {
660 periodic_sel--;
661 }
662 else
663 {
664 periodic_sel = ELEMENTS_COUNT - 1;
665 }
666 break;
667 case PERIODIC_KEY_FORWARD:
668 case PERIODIC_KEY_FORWARD_RPT:
669 if(periodic_sel==102)
670 {
671 periodic_sel=39;
672 break;
673 }
674 else if(periodic_sel==87)
675 {
676 periodic_sel=103;
677 break;
678 }
679 else if(periodic_sel==70)
680 {
681 periodic_sel=21;
682 break;
683 }
684 else if(periodic_sel==55)
685 {
686 periodic_sel=71;
687 break;
688 }
689 else if(periodic_sel==38)
690 {
691 periodic_sel=88;
692 break;
693 }
694 else if(periodic_sel==20)
695 {
696 periodic_sel=56;
697 break;
698 }
699 else if (periodic_sel < ELEMENTS_COUNT - 1)
700 {
701 periodic_sel++;
702 }
703 else
704 {
705 periodic_sel = 0;
706 }
707 break;
708 case PERIODIC_KEY_UP:
709 case PERIODIC_KEY_UP_RPT:
710 periodic_sel=periodic_elements[periodic_sel].up;
711 break;
712 case PERIODIC_KEY_DOWN:
713 case PERIODIC_KEY_DOWN_RPT:
714 periodic_sel=periodic_elements[periodic_sel].down;
715 break;
716 default:
717 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
718 return PLUGIN_USB_CONNECTED;
719 }
720 break;
721 }
722 }
723 return PLUGIN_OK;
724}