remove compiler warnings of new compilerversion /
[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("lx");
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 case 12:
215 l.push_back("wind speed");
216 l.push_back("Windgeschwindigkeit");
217 l.push_back("m/s");
218 break;
219 case 13:
220 l.push_back("wind speed max");
221 l.push_back("Maximale Windgeschwindigkeit");
222 l.push_back("m/s");
223 break;
224 case 14:
225 l.push_back("wind direction");
226 l.push_back("Windrichtung");
227 l.push_back("°");
228 break;
229 case 15:
230 l.push_back("wind direction variance");
231 l.push_back("Varianz der Windrichtung");
232 l.push_back("°");
233 break;
234 case 16:
235 l.push_back("illuminance red");
236 l.push_back("Beleuchtungsstärke Rot");
237 l.push_back("lx");
238 case 17:
239 l.push_back("illuminance green");
240 l.push_back("Beleuchtungsstärke Grün");
241 l.push_back("lx");
242 case 18:
243 l.push_back("illuminance blue");
244 l.push_back("Beleuchtungsstärke Blau");
245 l.push_back("lx");
246 default:
247 l.push_back("");
248 l.push_back("");
249 l.push_back("");
250
251 }
252 //Optimization necessary
253 if (language==OWDC_LANGUAGE_ENGLISH) l.erase(l.begin()+1);
254 if (language==OWDC_LANGUAGE_GERMAN) l.erase(l.begin());
255
256 return l;
257 }
258
259 double owDeviceConfig::calculateValueFromNumber(int code, int vn, std::vector<int> V) {
260 switch (code) {
261 case 01: return V[vn] / 16.0; break;
262 case 2:return V[vn]/1.6; break;
263 case 3:return V[vn]*0.2 + 700; break;
264 case 4:return exp(V[vn] / 160.0); break;
265 case 5:return V[vn]*62.5 + 55000; break;
266 case 6:return V[vn] / 256.0; break;
267 case 7:return (((double)V[2] / (double)V[1] - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); break;
268 case 8:return V[vn] / 100.0; break;
269 case 9:return V[vn] / 65535.0*5.1; break;
270 case 10:return V[vn] / 65535.0*2.55; break;
271 case 11:return V[vn] / 65535.0*1.1; break;
272 case 12:return V[vn] / 10.0; break;
273 case 13:return V[vn]; break;
274 case 14:return (V[vn] - 32767.0) / 100.0; break;
275 case 15:return exp((V[vn]-32767.0)/1000.0); break;
276 case 16:return V[vn]/32.0; break;
277 case 17:return V[vn]*0.2441/1000.0; break; //Vsens DS2438
278 case 18:return V[vn]/8.0;break;
279 case 19:return V[vn]/500.0*14.0;break; //Test
280 case 20:return V[vn]*0.5+700;break;
281 case 21:return V[vn]+1280; break;
282 case 22:return V[vn]*10;break;
283 case 23:return V[vn]*0.025+700.0;break;
284 case 24:return V[vn]*1.1/1024.0;break;
285 case 25:return V[vn]*3.0/1024.0;break;
286 case 26:return V[vn]*5.0/1024.0;break;
287 case 27:return ((double)V[2]+(double)V[1]/1000.0)/8.0;break;
288 case 28:return exp(V[vn]/2560.0);break;
289 default:return V[vn];
290 }
291 }
292
293 std::string owDeviceConfig::getSensorChip(uint8_t ch) {
294 if (ch>4) return "";
295 std::string s;
296 switch(config.sens[ch]) {
297 case 1: s="DS18B20";break;
298 case 2: s="DS2438";break; //Temperatur Sensor
299 case 3: s="DS2438";break; //Spannung
300 case 4: s="DS2438";break; // Spannung / Strom
301 case 5: s="DS2450";break; // Spannung
302 case 6: s="Thermoelement";break; // Hochtemperatur Sensor
303 case 7: s="SHT21";break; // Feuchte/Temperatur Sensor
304 case 8: s="SHT25";break; // Feuchte/Temperatur Präzisionssensor
305 case 9: s="DHT22";break; // Feuchte/Temperatur Sensor
306 case 10: s="HIH9021";break; // Feuchte/Temperatur Präzisionssensor
307 case 11: s="HDC1080";break; // Feuchte/Temperatur Sensor
308 case 12: s="HIH4030";break; // Feuchte/Temperatur Sensor analog
309 case 13: s="HIH5030";break; // Feuchte/Temperatur Sensor analog
310 case 14: s="BMP280";break; // Luftdrucksensor
311 case 15: s="MAX44009";break; // Umgebungslicht-Sensor
312 case 16: s="CDM7160";break; // CO2-Sensor
313 case 17: s="MAX1164/TGS8100";break; // VOC-Sensor
314 case 18: s="TGS8100 direkt";break; // VOC-Sensor
315 case 19: s="DS2423";break; // Counter
316 case 20: s="Intern ADC";break;
317 case 21: s="SHT35";break; // Feuchte/Temperatur Bester
318 case 22: s="SHT31";break; // Feuchte/Temperautr
319 case 23: s="APDS-9960";break; // Feuchte/Temperautr
320 case 24: s="BMP680";break;
321 case 25: s="SGP30";break;
322 case 26: s="SGPC3";break;
323 case 27: s="iAQ-core C";break;
324 case 28: s="HDC2010";break;
325 default: return "";
326 }
327 return s;
328 }