]>
Commit | Line | Data |
---|---|---|
bc1385a6 | 1 | ## |
50bd5d25 | 2 | ## This file is part of the libsigrokdecode project. |
bc1385a6 UH |
3 | ## |
4 | ## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> | |
5 | ## | |
6 | ## This program is free software; you can redistribute it and/or modify | |
7 | ## it under the terms of the GNU General Public License as published by | |
8 | ## the Free Software Foundation; either version 2 of the License, or | |
9 | ## (at your option) any later version. | |
10 | ## | |
11 | ## This program is distributed in the hope that it will be useful, | |
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ## GNU General Public License for more details. | |
15 | ## | |
16 | ## You should have received a copy of the GNU General Public License | |
4539e9ca | 17 | ## along with this program; if not, see <http://www.gnu.org/licenses/>. |
bc1385a6 UH |
18 | ## |
19 | ||
bc1385a6 UH |
20 | import sigrokdecode as srd |
21 | ||
22 | class Decoder(srd.Decoder): | |
b197383c | 23 | api_version = 3 |
bc1385a6 UH |
24 | id = 'mlx90614' |
25 | name = 'MLX90614' | |
26 | longname = 'Melexis MLX90614' | |
2787cf2a | 27 | desc = 'Melexis MLX90614 infrared thermometer protocol.' |
bc1385a6 UH |
28 | license = 'gplv2+' |
29 | inputs = ['i2c'] | |
6cbba91f | 30 | outputs = [] |
d6d8a8a4 | 31 | tags = ['IC', 'Sensor'] |
da9bcbd9 BV |
32 | annotations = ( |
33 | ('celsius', 'Temperature in degrees Celsius'), | |
34 | ('kelvin', 'Temperature in Kelvin'), | |
35 | ) | |
bc1385a6 | 36 | |
92b7b49f | 37 | def __init__(self): |
10aeb8ea GS |
38 | self.reset() |
39 | ||
40 | def reset(self): | |
bc1385a6 UH |
41 | self.state = 'IGNORE START REPEAT' |
42 | self.data = [] | |
43 | ||
8915b346 | 44 | def start(self): |
be465111 | 45 | self.out_ann = self.register(srd.OUTPUT_ANN) |
bc1385a6 | 46 | |
bc1385a6 UH |
47 | def putx(self, data): |
48 | self.put(self.ss, self.es, self.out_ann, data) | |
49 | ||
50 | # Quick hack implementation! This needs to be improved a lot! | |
51 | def decode(self, ss, es, data): | |
1b75abfd | 52 | cmd, databyte = data |
bc1385a6 UH |
53 | |
54 | # State machine. | |
55 | if self.state == 'IGNORE START REPEAT': | |
56 | if cmd != 'START REPEAT': | |
57 | return | |
58 | self.state = 'IGNORE ADDRESS WRITE' | |
59 | elif self.state == 'IGNORE ADDRESS WRITE': | |
60 | if cmd != 'ADDRESS WRITE': | |
61 | return | |
62 | self.state = 'GET TEMPERATURE' | |
63 | elif self.state == 'GET TEMPERATURE': | |
69ff19c8 UH |
64 | if cmd != 'DATA WRITE': |
65 | return | |
bc1385a6 | 66 | if len(self.data) == 0: |
7f7ea759 | 67 | self.data.append(databyte) |
bc1385a6 UH |
68 | self.ss = ss |
69 | elif len(self.data) == 1: | |
7f7ea759 | 70 | self.data.append(databyte) |
bc1385a6 UH |
71 | self.es = es |
72 | else: | |
73 | kelvin = (self.data[0] | (self.data[1] << 8)) * 0.02 | |
74 | celsius = kelvin - 273.15 | |
afff6b1a | 75 | self.putx([0, ['Temperature: %3.2f °C' % celsius]]) |
f2e114de | 76 | self.putx([1, ['Temperature: %3.2f K' % kelvin]]) |
bc1385a6 UH |
77 | self.state = 'IGNORE START REPEAT' |
78 | self.data = [] |