]>
Commit | Line | Data |
---|---|---|
1 | ## | |
2 | ## This file is part of the libsigrokdecode project. | |
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 | |
17 | ## along with this program; if not, write to the Free Software | |
18 | ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | ## | |
20 | ||
21 | import sigrokdecode as srd | |
22 | ||
23 | class Decoder(srd.Decoder): | |
24 | api_version = 2 | |
25 | id = 'mlx90614' | |
26 | name = 'MLX90614' | |
27 | longname = 'Melexis MLX90614' | |
28 | desc = 'Infrared Thermometer protocol.' | |
29 | license = 'gplv2+' | |
30 | inputs = ['i2c'] | |
31 | outputs = ['mlx90614'] | |
32 | annotations = ( | |
33 | ('celsius', 'Temperature in degrees Celsius'), | |
34 | ('kelvin', 'Temperature in Kelvin'), | |
35 | ) | |
36 | ||
37 | def __init__(self, **kwargs): | |
38 | self.state = 'IGNORE START REPEAT' | |
39 | self.data = [] | |
40 | ||
41 | def start(self): | |
42 | self.out_ann = self.register(srd.OUTPUT_ANN) | |
43 | ||
44 | def putx(self, data): | |
45 | self.put(self.ss, self.es, self.out_ann, data) | |
46 | ||
47 | # Quick hack implementation! This needs to be improved a lot! | |
48 | def decode(self, ss, es, data): | |
49 | cmd, databyte = data | |
50 | ||
51 | # State machine. | |
52 | if self.state == 'IGNORE START REPEAT': | |
53 | if cmd != 'START REPEAT': | |
54 | return | |
55 | self.state = 'IGNORE ADDRESS WRITE' | |
56 | elif self.state == 'IGNORE ADDRESS WRITE': | |
57 | if cmd != 'ADDRESS WRITE': | |
58 | return | |
59 | self.state = 'GET TEMPERATURE' | |
60 | elif self.state == 'GET TEMPERATURE': | |
61 | if cmd != 'DATA WRITE': | |
62 | return | |
63 | if len(self.data) == 0: | |
64 | self.data.append(databyte) | |
65 | self.ss = ss | |
66 | elif len(self.data) == 1: | |
67 | self.data.append(databyte) | |
68 | self.es = es | |
69 | else: | |
70 | kelvin = (self.data[0] | (self.data[1] << 8)) * 0.02 | |
71 | celsius = kelvin - 273.15 | |
72 | self.putx([0, ['Temperature: %3.2f °C' % celsius]]) | |
73 | self.putx([1, ['Temperature: %3.2f K' % kelvin]]) | |
74 | self.state = 'IGNORE START REPEAT' | |
75 | self.data = [] |