add files for automake
[owTools.git] / src / owDeviceConfig.cpp
1 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //  * Redistributions of source code must retain the above copyright
9 //    notice, this list of conditions and the following disclaimer.
10 //  * Redistributions in binary form must reproduce the above copyright
11 //    notice, this list of conditions and the following disclaimer in the
12 //    documentation and/or other materials provided with the
13 //    distribution.
14 //  * All advertising materials mentioning features or use of this
15 //    software must display the following acknowledgement: This product
16 //    includes software developed by tm3d.de and its contributors.
17 //  * Neither the name of tm3d.de nor the names of its contributors may
18 //    be used to endorse or promote products derived from this software
19 //    without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33
34 #include "owDeviceConfig.h"
35 #include <math.h>
36
37 std::vector<std::string> owDeviceConfig::getFamilyInfo(uint8_t famcode) {
38         std::vector<std::string> l;
39         switch (famcode) {
40                         case 1:
41                                 l.push_back("DS2401,DS2411");
42                                 l.push_back("DS1990A");
43                                 l.push_back("silicon serial number");
44                                 break;
45                         case 2:
46                                 l.push_back("DS1425");
47                                 l.push_back("DS1991");
48                                 l.push_back("multikey 1153bit secure");
49                                 break;
50                         case 4:
51                                 l.push_back("DS2404");
52                                 l.push_back("DS1994");
53                                 l.push_back("econoram time chip");
54                                 break;
55                         case 5:
56                                 l.push_back("DS2405");
57                                 l.push_back("");
58                                 l.push_back("push_backresable Switch");
59                                 break;
60                         case 6:
61                                 l.push_back(""); l.push_back("DS1993");
62                                 l.push_back("4k memory ibutton");
63                                 break;
64                         case 8:
65                                 l.push_back(""); l.push_back("DS1992");
66                                 l.push_back("1k memory ibutton");
67                                 break;
68                         case 9:
69                                 l.push_back("DS2502"); l.push_back("DS1982");
70                                 l.push_back("1k add - only memory");
71                                 break;
72                         case 0x0A: l.push_back(""); l.push_back("DS1995");
73                                 l.push_back("16k memory ibutton"); break;
74                         case 0x0B: l.push_back("DS2505"); l.push_back("DS1985");
75                                 l.push_back("16k add - only memory"); break;
76                         case 0x0C: l.push_back(""); l.push_back("DS1996");
77                                 l.push_back("64k memory ibutton"); break;
78                         case 0x0F: l.push_back("DS2506"); l.push_back("1986");
79                                 l.push_back("64k add - only  memory"); break;
80                         case 0x10:l.push_back("DS18S20"); l.push_back("DS1920");
81                                 l.push_back("high precision digital thermometer"); break;
82                         case 0x12:l.push_back("DS2406,DS2407"); l.push_back("");
83                                 l.push_back("dual addressable switch plus 1k memory"); break;
84                         case 0x14:l.push_back("DS2430A"); l.push_back("1971");
85                                 l.push_back("256 eeprom"); break;
86                         case 0x1A:l.push_back(""); l.push_back("DS1963L");
87                                 l.push_back("4k Monetary"); break;
88                         case 0x1B:l.push_back("DS2436"); l.push_back("");
89                                 l.push_back("battery id / monitor chip"); break;
90                         case 0x1C:l.push_back("DS28E04-100"); l.push_back("");
91                                 l.push_back("4k EEPROM with PIO 1C"); break;
92                         case 0x1D:l.push_back("DS2423"); l.push_back("");
93                                 l.push_back("4k ram with counter"); break;
94                         case 0x1F:l.push_back("DS2409"); l.push_back("");
95                                 l.push_back("microlan coupler"); break;
96                         case 0x20 : l.push_back("DS2450"); l.push_back("");
97                                 l.push_back("quad a / d converter"); break;
98                         case 0x21: l.push_back(""); l.push_back("DS1921");
99                                 l.push_back("Thermachron"); break;
100                         case 0x22: l.push_back("DS1822"); l.push_back("");
101                                 l.push_back("Econo Digital Thermometer"); break;
102                         case 0x23: l.push_back("DS2433"); l.push_back("");
103                                 l.push_back("4k eeprom"); break;
104                         case 0x24: l.push_back("DS2415"); l.push_back("");
105                                 l.push_back("time chip"); break;
106                         case 0x26: l.push_back("DS2438"); l.push_back("");
107                                 l.push_back("smart battery monitor"); break;
108                         case 0x27:l.push_back("DS2417"); l.push_back("");
109                                 l.push_back("time chip with interrupt"); break;
110                         case 0x28:l.push_back("DS18B20"); l.push_back("");
111                                 l.push_back("programmable resolution digital thermometer"); break;
112                         case 0x29:l.push_back("DS2408"); l.push_back("");
113                                 l.push_back("8 - channel addressable switch"); break;
114                         case 0x2C:l.push_back("DS2890"); l.push_back("");
115                                 l.push_back("digital potentiometer"); break;
116                         case 0x2D:l.push_back("DS2431"); l.push_back("");
117                                 l.push_back("1k eeprom"); break;
118                         case 0x2E:l.push_back("DS2770"); l.push_back("");
119                                 l.push_back("battery monitor and charge controller"); break;
120                         case 0x30:l.push_back("DS2760/61/62"); l.push_back("");
121                                 l.push_back("high - precision li + battery monitor"); break;
122                         case 0x31:l.push_back("DS2720"); l.push_back("");
123                                 l.push_back("efficient addressable single - cell rechargable lithium protection ic"); break;
124                         case 0x33: l.push_back("DS2432"); l.push_back("DS1961S");
125                                 l.push_back("1k protected eeprom with SHA - 1"); break;
126                         case 0x36:l.push_back("DS2740"); l.push_back("");
127                                 l.push_back("high precision coulomb counter"); break;
128                         case 0x37: l.push_back(""); l.push_back("DS1977"); 
129                                 l.push_back("Password protected 32k eeprom"); break;
130                         case 0x3A:l.push_back("DS2413"); l.push_back("");
131                                 l.push_back("dual channel addressable switch"); break;
132                         case 0x41:l.push_back("DS2422"); l.push_back("DS1922L/DS1922T/DS1923");
133                                 l.push_back("Temperature Logger 8k mem"); break;
134                         case 0x51:l.push_back("DS2751"); l.push_back("");
135                                 l.push_back("multichemistry battery fuel gauge"); break;
136                         case 0x81: l.push_back(""); l.push_back("DS1420");
137                                 l.push_back("Serial ID Button"); break;
138                         case 0x84:l.push_back("DS2404S"); l.push_back("");
139                                 l.push_back("dual port plus time"); break;
140                         case 0x89:l.push_back("DS2502-E48"); l.push_back("DS1982U");
141                                 l.push_back("48 bit node address chip"); break;
142                         case 0x8B:l.push_back("DS2502/DS2505"); l.push_back("DS1985U");
143                                 l.push_back("16k add - only"); break;
144                         case 0x8F:l.push_back("DS2506"); l.push_back("DS1986U");
145                                 l.push_back("64k add - only uniqueware"); break;
146                         case 0xFF:l.push_back("LCD"); l.push_back("");
147                                 l.push_back("(Swart)"); break;
148                         case 0xA3:l.push_back("ATTINY84A"); l.push_back("");
149                                 l.push_back("1-Wire Flasher"); break;
150                         default:l.push_back("unknown"); l.push_back("unknown");
151                                 l.push_back("Device not int list"); 
152                                 break;
153                 }
154                         return l;
155         }
156
157 std::vector<std::string> owDeviceConfig::getQuantityFromNumber(uint8_t code) {
158         std::vector<std::string> l;
159         switch (code) {
160                 case 1:
161                         l.push_back("temperature");
162                         l.push_back("Temperatur");
163                         l.push_back("°C");
164                         break;
165                 case 2:
166                         l.push_back("pressure");
167                         l.push_back("Druck");
168                         l.push_back("hPa");
169                         break;
170                 case 3:
171                         l.push_back("illuminance");
172                         l.push_back("Beleuchtungsstärke");
173                         l.push_back("lux");
174                         break;
175                 case 4:
176                         l.push_back("humidity");
177                         l.push_back("Luftfeuchte");
178                         l.push_back("%");
179                         break;
180                 case 5:
181                         l.push_back("constant");
182                         l.push_back("Konstante");
183                         l.push_back("");
184                         break;
185                 case 6:
186                         l.push_back("voltage");
187                         l.push_back("Spannung");
188                         l.push_back("V");
189                         break;
190                 case 7:
191                         l.push_back("current");
192                         l.push_back("Strom");
193                         l.push_back("mA");
194                         break;
195                 case 8:
196                         l.push_back("VOC");
197                         l.push_back("VOC");
198                         l.push_back("ppm");
199                 case 9:
200                         l.push_back("Counter");
201                         l.push_back("Zähler");
202                         l.push_back("");
203                         break;
204                 case 10:
205                         l.push_back("CO2");
206                         l.push_back("CO2");
207                         l.push_back("ppm");
208                         break;  
209                 case 11:
210                         l.push_back("resistance");
211                         l.push_back("Widerstand");
212                         l.push_back("kOhm");
213                         break;  
214                 default:
215                         l.push_back("");
216                         l.push_back("");
217                         l.push_back("");
218         
219         }
220         //Optimization necessary
221         if (language==OWDC_LANGUAGE_ENGLISH) l.erase(l.begin()+1);
222         if (language==OWDC_LANGUAGE_GERMAN) l.erase(l.begin()); 
223         
224         return l;
225 }
226
227 double owDeviceConfig::calculateValueFromNumber(int code, int vn, std::vector<int> V) {
228         switch (code) {
229                         case 01: return V[vn] / 16.0; break;
230                         case 2:return V[vn]/1.6; break;
231                         case 3:return V[vn]*0.2 + 700; break;
232                         case 4:return exp(V[vn] / 160.0); break;
233                         case 5:return V[vn]*62.5 + 55000; break;
234                         case 6:return V[vn] / 256.0; break;
235                         case 7:return (((double)V[2] / (double)V[1] - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); break;
236                         case 8:return V[vn] / 100.0; break;
237                         case 9:return V[vn] / 65535.0*5.1; break;
238                         case 10:return V[vn] / 65535.0*2.55; break;
239                         case 11:return V[vn] / 65535.0*1.1; break;
240                         case 12:return V[vn] / 10.0; break;
241                         case 13:return V[vn];  break;
242                         case 14:return (V[vn] - 32767.0) / 100.0;  break;
243                         case 15:return exp((V[vn]-32767.0)/1000.0);  break;
244                         case 16:return V[vn]/32.0;  break;
245                         case 17:return 5120.0/V[vn]; break; //Current of DS2438 with 0.025 Ohm;
246                         default:return 0;
247                 }
248 }
249
250 std::string owDeviceConfig::getSensorChip(uint8_t ch) {
251         if (ch>4) return "";
252         std::string s;
253         switch(config.sens[ch]) {
254                 case 1: s="DS18B20";break;
255                 case 2: s="DS2438";break;       //Temperatur Sensor
256                 case 3: s="DS2438";break;       //Spannung
257                 case 4: s="DS2438";break;       //      Spannung / Strom
258                 case 5: s="DS2450";break;       //      Spannung
259                 case 6: s="Thermoelement";break;        //      Hochtemperatur Sensor
260                 case 7: s="SHT21";break;        //      Feuchte/Temperatur Sensor
261                 case 8: s="SHT25";break;        //      Feuchte/Temperatur Präzisionssensor
262                 case 9: s="DHT22";break;        //      Feuchte/Temperatur Sensor
263                 case 10: s="HIH9021";break;     //      Feuchte/Temperatur Präzisionssensor
264                 case 11: s="HDC1080";break;     //      Feuchte/Temperatur Sensor
265                 case 12: s="HIH4030";break;     //      Feuchte/Temperatur Sensor analog
266                 case 13: s="HIH5030";break;     //      Feuchte/Temperatur Sensor analog
267                 case 14: s="BMP280";break;      //      Luftdrucksensor
268                 case 15: s="MAX44009";break;    //      Umgebungslicht-Sensor
269                 case 16: s="CDM7160";break;     //      CO2-Sensor
270                 case 17: s="MAX1164/TGS8100";break;     //      VOC-Sensor
271                 case 18: s="TGS8100 direkt";break;      //      VOC-Sensor
272                 case 19: s="DS2423";break;      //      Counter
273                 default: return "";
274         }
275         return s;
276 }