A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 663 lines 33 kB view raw
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 , 102, 38}, 75 { 4, 4, 22, "Ti", "Titanium", "47.867", "4.54", "1666", "3289", 'd', 3 , 88, 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, 70}, 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", 'd', 10 , 38, 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, 20}, 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, "Cn", "Copernicium", "[285]", "-", "-", "-", 'd', 3 , 79, 29}, 166 { 13, 7, 113, "Nh", "Nihonium", "[284]", "-", "-", "-", 'p', 4 , 80, 4}, 167 { 14, 7, 114, "Fl", "Flerovium", "[289]", "-", "-", "-", 'p', 4 , 81, 5}, 168 { 15, 7, 115, "Mc", "Moscovium", "[288]", "-", "-", "-", 'p', 4 , 82, 6}, 169 { 16, 7, 116, "Lv", "Livermorium", "[293]", "-", "-", "-", 'p', 4 , 83, 7}, 170 { 17, 7, 117, "Ts", "Tennessine", "[294]", "-", "-", "-", 'p', 4 , 84, 8}, 171 { 18, 7, 118, "Og", "Oganesson", "[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 186#if LCD_DEPTH > 1 187static const long int periodic_tinyfont_bitmaps[] = { 188 0x00000000, 0x00220200, 0x00550000, 0x00575750, 0x00236200, 0x00514500, 0x00236300, 0x00220000, 189 0x00244200, 0x00211200, 0x00272720, 0x00027200, 0x00000240, 0x00007000, 0x00000200, 0x00122400, 190 0x00255200, 0x00262700, 0x00612700, 0x00631600, 0x00571100, 0x00761600, 0x00365200, 0x00712200, 191 0x00725200, 0x00353100, 0x00020200, 0x00020240, 0x00024200, 0x00070700, 0x00021200, 0x00610200, 192 193 0x00254300, 0x00257500, 0x00675600, 0x00344300, 0x00655600, 0x00764700, 0x00746400, 0x00345300, 194 0x00577500, 0x00722700, 0x00722400, 0x00566500, 0x00444700, 0x00775500, 0x00575500, 0x00255200, 195 0x00656400, 0x00255300, 0x00656500, 0x00363600, 0x00722200, 0x00555200, 0x00552200, 0x00557700, 196 0x00522500, 0x00522200, 0x00714700, 0x00322300, 0x00422100, 0x00622600, 0x00250000, 0x00000700, 197 198 0x00420000, 0x00063300, 0x00465600, 0x00034300, 0x00135300, 0x00026300, 0x00127200, 0x00035360, 199 0x00465500, 0x00202200, 0x00202240, 0x00456500, 0x00222200, 0x00067500, 0x00065500, 0x00025200, 200 0x00065640, 0x00035310, 0x00056400, 0x00032600, 0x00272100, 0x00055300, 0x00057200, 0x00057700, 201 0x00052500, 0x00055360, 0x00072700, 0x00162100, 0x00222220, 0x00432400, 0x00630000, 0x00525250 202}; 203 204static void periodic_tinyfont_draw_char(int x, int y, char ch) 205{ 206 int i,j; 207 int r; 208 long int bmp = periodic_tinyfont_bitmaps[ch-' ']; 209 for (i=7; i>=0; i--) { 210 r = bmp & 15; 211 bmp /= 16; 212 for (j=3; j>=0; j--) { 213 if (r & 1) { 214 rb->lcd_drawpixel(x+j, y+i); 215 } 216 r /= 2; 217 } 218 } 219} 220 221static void periodic_tinyfont_draw_string(int x, int y, char * s) 222{ 223 char * t = s; 224 int xx = x; 225 int yy = y; 226 while (*t) { 227 if ((*t) == 10) { 228 xx = x; 229 yy += 8; 230 } else { 231 periodic_tinyfont_draw_char(xx, yy, *t); 232 xx += 4; 233 } 234 t++; 235 } 236} 237#endif /* LCD_DEPTH > 1 */ 238 239/* 240 void periodic_tinyfont_draw_chart(int x, int y, ttk_color col) 241 { 242 unsigned char ch; 243 int xx = x; 244 int yy = y; 245 for (ch = 32; ch < 128; ch++) { 246 periodic_tinyfont_draw_char(xx, yy, ch, col); 247 if ((ch % 16) == 15) { 248 xx = x; 249 yy += 8; 250 } else { 251 xx += 4; 252 } 253 } 254 } 255*/ 256 257/* - - - KEYMAP - - - */ 258 259static const struct button_mapping *plugin_contexts[] = { pla_main_ctx }; 260 261#define PERIODIC_KEY_SELECT PLA_SELECT 262#define PERIODIC_KEY_MENU PLA_CANCEL 263#define PERIODIC_KEY_BACK PLA_LEFT 264#define PERIODIC_KEY_FORWARD PLA_RIGHT 265#define PERIODIC_KEY_UP PLA_UP 266#define PERIODIC_KEY_DOWN PLA_DOWN 267#define PERIODIC_KEY_BACK_RPT PLA_LEFT_REPEAT 268#define PERIODIC_KEY_FORWARD_RPT PLA_RIGHT_REPEAT 269#define PERIODIC_KEY_UP_RPT PLA_UP_REPEAT 270#define PERIODIC_KEY_DOWN_RPT PLA_DOWN_REPEAT 271 272 273/* - - - SOME CONSTANTS - - - */ 274#ifdef HAVE_LCD_COLOR 275#define PERIODIC_COLOR_BLACK LCD_RGBPACK(0,0,0) 276#else 277#define PERIODIC_COLOR_BLACK LCD_BLACK 278#endif 279 280#ifdef HAVE_LCD_COLOR 281#define PERIODIC_COLOR_WHITE LCD_RGBPACK(255,255,255) 282#else 283#define PERIODIC_COLOR_WHITE LCD_WHITE 284#endif 285 286#define CELLSIZE ((LCD_WIDTH-1)/18) 287#define NUM_LINE ((LCD_HEIGHT - CELLSIZE * 10 + (CELLSIZE >> 1))/font_height) 288 289#define CELSIUS "\xc2\xb0\x43" 290#define CUBIC_CENTIMETER "\x63\x6d\xc2\xb3" 291 292/* - - - PERIODIC TABLE HELPER FUNCTIONS - - - */ 293 294static void periodic_makecols(void) 295{ 296#ifdef HAVE_LCD_COLOR 297 int i = 0; 298 299 periodic_color_palette[i++] = LCD_RGBPACK(255,255,255); /* 0 hydrogen */ 300 periodic_color_palette[i++] = LCD_RGBPACK(221,221,221); /* 1 alkali metals */ 301 periodic_color_palette[i++] = LCD_RGBPACK(187,187,187); /* 2 earth metals */ 302 periodic_color_palette[i++] = LCD_RGBPACK(255,204,255); /* 3 transition metals */ 303 periodic_color_palette[i++] = LCD_RGBPACK(255,204,204); /* 4 other metals */ 304 periodic_color_palette[i++] = LCD_RGBPACK(255,204,153); /* 5 metalloids */ 305 periodic_color_palette[i++] = LCD_RGBPACK(255,255,204); /* 6 nonmetals */ 306 periodic_color_palette[i++] = LCD_RGBPACK(204,255,204); /* 7 halogens */ 307 periodic_color_palette[i++] = LCD_RGBPACK(204,204,153); /* 8 astatine */ 308 periodic_color_palette[i++] = LCD_RGBPACK(204,255,255); /* 9 noble gases */ 309 periodic_color_palette[i++] = LCD_RGBPACK(153,204,255); /* 10 lanthanides */ 310 periodic_color_palette[i++] = LCD_RGBPACK(204,153,255); /* 11 actinides */ 311#elif LCD_DEPTH > 1 312 int i = 0; 313 314 periodic_color_palette[i++] = LCD_WHITE; /* 0 hydrogen */ 315 periodic_color_palette[i++] = LCD_DARKGRAY; /* 1 alkali metals */ 316 periodic_color_palette[i++] = LCD_DARKGRAY; /* 2 earth metals */ 317 periodic_color_palette[i++] = LCD_WHITE; /* 3 transition metals */ 318 periodic_color_palette[i++] = LCD_WHITE; /* 4 other metals */ 319 periodic_color_palette[i++] = LCD_DARKGRAY; /* 5 metalloids */ 320 periodic_color_palette[i++] = LCD_WHITE; /* 6 nonmetals */ 321 periodic_color_palette[i++] = LCD_WHITE; /* 7 halogens */ 322 periodic_color_palette[i++] = LCD_DARKGRAY; /* 8 astatine */ 323 periodic_color_palette[i++] = LCD_WHITE; /* 9 noble gases */ 324 periodic_color_palette[i++] = LCD_DARKGRAY; /* 10 lanthanides */ 325 periodic_color_palette[i++] = LCD_DARKGRAY; /* 11 actinides */ 326#endif 327} 328 329static int periodic_fix_period(int p) 330{ 331 /* lanthanides/actinides are periods 9/10 internally, but make them look like 6/7 in the displayed table */ 332 return (p>8)?(p-3):p; 333} 334 335static int periodic_fix_group(int g, int p) 336{ 337 /* there is no agreed-upon group number for the lanthanides/actinides, but 3 is used sometimes */ 338 return (p>8)?3:g; 339} 340 341static char * periodic_group_name(int i) 342{ 343 if (i==1) { 344 return "Noble Gases"; 345 } 346 else if (periodic_elements[i].period > 8) 347 { 348 switch (periodic_elements[i].period) 349 { 350 case 9: 351 return "Lanthanides"; 352 break; 353 case 10: 354 return "Actinides"; 355 break; 356 } 357 return ""; 358 } 359 else if (i>1) 360 { 361 switch (periodic_elements[i].group) { 362 case 1: 363 return "Alkali Metals"; 364 break; 365 case 2: 366 return "Alkaline Earth Metals"; 367 break; 368 case 15: 369 return "Pnictogens"; 370 break; 371 case 16: 372 return "Chalcogens"; 373 break; 374 case 17: 375 return "Halogens"; 376 break; 377 case 18: 378 return "Noble Gases"; 379 break; 380 } 381 } 382 return ""; 383} 384 385static void periodic_draw_element(unsigned int i, int bx, int by) 386{ 387 int ex = (bx+((periodic_elements[i].group-1) * CELLSIZE)); 388 int ey = (by+((periodic_elements[i].period-1) * CELLSIZE)); 389#if LCD_DEPTH > 1 390 int tx, ty; 391 char tt[4]; 392#endif 393 394 if (periodic_elements[i].period > 8) 395 ey -= (CELLSIZE >> 1); 396 397 if (i == periodic_sel) 398 { 399#if LCD_DEPTH > 1 400 rb->lcd_set_foreground(PERIODIC_COLOR_BLACK); 401#endif 402#if LCD_DEPTH > 1 403 rb->lcd_fillrect(ex, ey, CELLSIZE+1, CELLSIZE+1); 404#else 405 rb->lcd_set_drawmode(DRMODE_FG); 406 rb->lcd_fillrect(ex, ey, CELLSIZE+1, CELLSIZE+1); 407 rb->lcd_set_drawmode(DRMODE_SOLID); 408#endif 409 } 410 else 411 { 412#if LCD_DEPTH > 1 413 rb->lcd_set_foreground(periodic_color_palette[periodic_elements[i].color]); 414 rb->lcd_fillrect(ex, ey, CELLSIZE+1, CELLSIZE+1); 415 rb->lcd_set_foreground(PERIODIC_COLOR_BLACK); 416#else 417 rb->lcd_set_drawmode(DRMODE_BG+DRMODE_INVERSEVID); 418 rb->lcd_fillrect(ex, ey, CELLSIZE+1, CELLSIZE+1); 419 rb->lcd_set_drawmode(DRMODE_SOLID); 420#endif 421 rb->lcd_drawrect(ex, ey, CELLSIZE+1, CELLSIZE+1); 422 } 423#if LCD_DEPTH > 1 424 if (CELLSIZE >= 8) { 425 rb->strcpy(tt, periodic_elements[i].symbol); 426 if (rb->strlen(tt) > 2) { 427 tt[1] = tt[rb->strlen(tt)-1]; 428 tt[2] = 0; 429 tx = ex + (CELLSIZE >> 1) - 4; 430 } else if (tt[1] != 0) { 431 tx = ex + (CELLSIZE >> 1) - 4; 432 } else { 433 tx = ex + (CELLSIZE >> 1) - 2; 434 } 435 ty = ey + (CELLSIZE >> 1) - 4; 436 437 if (i == periodic_sel) 438 { 439 rb->lcd_set_foreground(PERIODIC_COLOR_WHITE); 440 } 441 else 442 { 443 rb->lcd_set_foreground(PERIODIC_COLOR_BLACK); 444 } 445 periodic_tinyfont_draw_string(tx, ty, tt); 446 } 447#endif 448} 449 450static void periodic_draw_table(void) 451{ 452 int bx = (LCD_WIDTH - CELLSIZE * 18) >> 1; 453 int by = 1; 454 unsigned int i; 455 for (i = 0; i < ELEMENTS_COUNT; i++) { 456 periodic_draw_element(i, bx, by); 457 } 458} 459 460static void periodic_draw(void) 461{ 462 char buf[40]; 463 464 periodic_draw_table(); 465 466 /* show the info for the current element */ 467 468 /* X coordinate of name/group */ 469 int nx = (LCD_WIDTH >> 1) - CELLSIZE * 7 + 5; 470 471 /* X coordinate of first column */ 472 int fx = 0; 473#if LCD_WIDTH >= 220 474 int sx = (LCD_WIDTH > 220)? 120 : 90; 475#endif 476 477 /* Y coordinate of first/second top column */ 478 int ty = LCD_HEIGHT - font_height * NUM_LINE; 479 480 struct periodic_element_t e; 481 e = periodic_elements[periodic_sel]; 482 483#if LCD_DEPTH > 1 484 rb->lcd_set_foreground(theme_fg); 485#endif 486 487 /* display name and group up top */ 488#if LCD_WIDTH > 160 489 rb->snprintf(buf, 40, "Name: %s", e.name); 490 rb->lcd_putsxy(nx, 0, buf); 491 492 rb->snprintf(buf, 40, "Group: %d %s", periodic_fix_group(e.group, e.period), 493 periodic_group_name(periodic_sel)); 494 rb->lcd_putsxy(nx, font_height, buf); 495 496#else 497 if (NUM_LINE > 0) 498 { 499 rb->snprintf(buf, 40, "%s", e.name); 500 rb->lcd_putsxy(nx, 0, buf); 501 rb->snprintf(buf, 40, "%d %s", periodic_fix_group(e.group, e.period), 502 periodic_group_name(periodic_sel)); 503 rb->lcd_putsxy(nx, font_height, buf); 504 } 505 else 506 { 507 rb->snprintf(buf, 40, "%d %s %s", e.number, e.symbol, e.name); 508 rb->lcd_putsxy(nx, 0, buf); 509 rb->snprintf(buf, 40, "%s amu", e.mass); 510 rb->lcd_putsxy(nx, font_height, buf); 511 } 512#endif 513 514 /* first col of info */ 515 if (NUM_LINE >= 8) 516 { 517 rb->snprintf(buf, 40, "Number: %d", e.number); 518 rb->lcd_putsxy(fx, ty, buf); 519 rb->snprintf(buf, 40, "Symbol: %s", e.symbol); 520 rb->lcd_putsxy(fx, ty + font_height, buf); 521 rb->snprintf(buf, 40, "Period: %d", periodic_fix_period(e.period)); 522 rb->lcd_putsxy(fx, ty + font_height*2, buf); 523 rb->snprintf(buf, 40, "Block: %c", e.block); 524 rb->lcd_putsxy(fx, ty + font_height*3, buf); 525 526 rb->snprintf(buf, 40, "Mass: %s amu", e.mass); 527 rb->lcd_putsxy(fx, ty + font_height*4, buf); 528 rb->snprintf(buf, 40, "Density: %s g/%s", e.density, CUBIC_CENTIMETER); 529 rb->lcd_putsxy(fx, ty + font_height*5, buf); 530 rb->snprintf(buf, 40, "F Point: %s %s", e.fpoint, CELSIUS); 531 rb->lcd_putsxy(fx, ty + font_height*6, buf); 532 rb->snprintf(buf, 40, "B Point: %s %s", e.bpoint, CELSIUS); 533 rb->lcd_putsxy(fx, ty + font_height*7, buf); 534 } 535 else 536 { 537#if LCD_WIDTH >= 220 /* shuld be NUM_LINE >= 4 */ 538 rb->snprintf(buf, 40, "Number: %d", e.number); 539 rb->lcd_putsxy(fx, ty, buf); 540 rb->snprintf(buf, 40, "Symbol: %s", e.symbol); 541 rb->lcd_putsxy(fx, ty + font_height, buf); 542 rb->snprintf(buf, 40, "Period: %d", periodic_fix_period(e.period)); 543 rb->lcd_putsxy(fx, ty + font_height*2, buf); 544 rb->snprintf(buf, 40, "Block: %c", e.block); 545 rb->lcd_putsxy(fx, ty + font_height*3, buf); 546#else 547 if (NUM_LINE >= 4) 548 { 549 rb->snprintf(buf, 40, "%d %s P: %d B: %c", e.number, e.symbol, 550 periodic_fix_period(e.period), e.block); 551 rb->lcd_putsxy(fx, ty, buf); 552 rb->snprintf(buf, 40, "M: %s amu", e.mass); 553 rb->lcd_putsxy(fx, ty + font_height, buf); 554 rb->snprintf(buf, 40, "D: %s g/%s", e.density, CUBIC_CENTIMETER); 555 rb->lcd_putsxy(fx, ty + font_height*2, buf); 556 rb->snprintf(buf, 40, "F/B: %s %s / %s %s", e.fpoint, CELSIUS, e.bpoint, CELSIUS); 557 rb->lcd_putsxy(fx, ty + font_height*3, buf); 558 } 559 else 560 { 561 if (NUM_LINE >= 1) 562 { 563 rb->snprintf(buf, 40, "%d %s %s amu", e.number, e.symbol, e.mass); 564 rb->lcd_putsxy(fx, ty, buf); 565 } 566 if (NUM_LINE >= 2) 567 { 568 rb->snprintf(buf, 40, "D: %s g/%s", e.density, CUBIC_CENTIMETER); 569 rb->lcd_putsxy(fx, ty + font_height, buf); 570 } 571 if (NUM_LINE >= 3) 572 { 573 rb->snprintf(buf, 40, "F/B: %s %s / %s %s", e.fpoint, CELSIUS, e.bpoint, CELSIUS); 574 rb->lcd_putsxy(fx, ty + font_height*2, buf); 575 } 576 } 577#endif 578 } 579 580 /* second col of info */ 581#if LCD_WIDTH >= 220 582 if (NUM_LINE < 8) 583 { 584 rb->snprintf(buf, 40, "Mass: %s amu", e.mass); 585 rb->lcd_putsxy(sx, ty, buf); 586 rb->snprintf(buf, 40, "Density: %s g/%s", e.density, CUBIC_CENTIMETER); 587 rb->lcd_putsxy(sx, ty + font_height, buf); 588 rb->snprintf(buf, 40, "F Point: %s %s", e.fpoint, CELSIUS); 589 rb->lcd_putsxy(sx, ty + font_height*2, buf); 590 rb->snprintf(buf, 40, "B Point: %s %s", e.bpoint, CELSIUS); 591 rb->lcd_putsxy(sx, ty + font_height*3, buf); 592 } 593#endif 594} 595 596enum plugin_status plugin_start(const void* parameter) 597{ 598 (void)parameter; 599 600 periodic_sel = 0; 601 periodic_makecols(); 602 603#if LCD_DEPTH > 1 604 theme_fg=rb->lcd_get_foreground(); 605 theme_bg=rb->lcd_get_background(); 606#endif 607 608 struct font *pf = rb->font_get(rb->screens[SCREEN_MAIN]->getuifont()); 609 font_height = pf->height; 610 611 while (1) { 612#if LCD_DEPTH > 1 613 rb->lcd_set_background(theme_bg); 614#endif 615 rb->lcd_clear_display(); 616 periodic_draw(); 617 rb->lcd_update(); 618 int button = pluginlib_getaction(-1, plugin_contexts, ARRAYLEN(plugin_contexts)); 619 switch (button) 620 { 621 case PERIODIC_KEY_SELECT: 622 case PERIODIC_KEY_MENU: 623 return PLUGIN_OK; 624 break; 625 case PERIODIC_KEY_BACK: 626 case PERIODIC_KEY_BACK_RPT: 627 if (periodic_sel > 0) 628 { 629 periodic_sel--; 630 } 631 else 632 { 633 periodic_sel = ELEMENTS_COUNT - 1; 634 } 635 break; 636 case PERIODIC_KEY_FORWARD: 637 case PERIODIC_KEY_FORWARD_RPT: 638 if (periodic_sel < ELEMENTS_COUNT - 1) 639 { 640 periodic_sel++; 641 } 642 else 643 { 644 periodic_sel = 0; 645 } 646 break; 647 case PERIODIC_KEY_UP: 648 case PERIODIC_KEY_UP_RPT: 649 periodic_sel=periodic_elements[periodic_sel].up; 650 break; 651 case PERIODIC_KEY_DOWN: 652 case PERIODIC_KEY_DOWN_RPT: 653 periodic_sel=periodic_elements[periodic_sel].down; 654 break; 655 default: 656 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { 657 return PLUGIN_USB_CONNECTED; 658 } 659 break; 660 } 661 } 662 return PLUGIN_OK; 663}