]>
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 | |
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 | ||
bc1385a6 | 21 | # Melexis MLX90614 Infrared Thermometer protocol decoder |
bc1385a6 UH |
22 | |
23 | import sigrokdecode as srd | |
24 | ||
25 | class Decoder(srd.Decoder): | |
26 | api_version = 1 | |
27 | id = 'mlx90614' | |
28 | name = 'MLX90614' | |
29 | longname = 'Melexis MLX90614' | |
a465436e | 30 | desc = 'Infrared Thermometer protocol.' |
bc1385a6 UH |
31 | license = 'gplv2+' |
32 | inputs = ['i2c'] | |
33 | outputs = ['mlx90614'] | |
34 | probes = [] | |
b77614bc | 35 | optional_probes = [] |
bc1385a6 UH |
36 | options = {} |
37 | annotations = [ | |
38 | ['Celsius', 'Temperature in degrees Celsius'], | |
f2e114de | 39 | ['Kelvin', 'Temperature in Kelvin'], |
bc1385a6 UH |
40 | ] |
41 | ||
42 | def __init__(self, **kwargs): | |
43 | self.state = 'IGNORE START REPEAT' | |
44 | self.data = [] | |
45 | ||
8915b346 | 46 | def start(self): |
be465111 BV |
47 | # self.out_proto = self.register(srd.OUTPUT_PYTHON) |
48 | self.out_ann = self.register(srd.OUTPUT_ANN) | |
bc1385a6 | 49 | |
bc1385a6 UH |
50 | def putx(self, data): |
51 | self.put(self.ss, self.es, self.out_ann, data) | |
52 | ||
53 | # Quick hack implementation! This needs to be improved a lot! | |
54 | def decode(self, ss, es, data): | |
1b75abfd | 55 | cmd, databyte = data |
bc1385a6 UH |
56 | |
57 | # State machine. | |
58 | if self.state == 'IGNORE START REPEAT': | |
59 | if cmd != 'START REPEAT': | |
60 | return | |
61 | self.state = 'IGNORE ADDRESS WRITE' | |
62 | elif self.state == 'IGNORE ADDRESS WRITE': | |
63 | if cmd != 'ADDRESS WRITE': | |
64 | return | |
65 | self.state = 'GET TEMPERATURE' | |
66 | elif self.state == 'GET TEMPERATURE': | |
69ff19c8 UH |
67 | if cmd != 'DATA WRITE': |
68 | return | |
bc1385a6 | 69 | if len(self.data) == 0: |
7f7ea759 | 70 | self.data.append(databyte) |
bc1385a6 UH |
71 | self.ss = ss |
72 | elif len(self.data) == 1: | |
7f7ea759 | 73 | self.data.append(databyte) |
bc1385a6 UH |
74 | self.es = es |
75 | else: | |
76 | kelvin = (self.data[0] | (self.data[1] << 8)) * 0.02 | |
77 | celsius = kelvin - 273.15 | |
afff6b1a | 78 | self.putx([0, ['Temperature: %3.2f °C' % celsius]]) |
f2e114de | 79 | self.putx([1, ['Temperature: %3.2f K' % kelvin]]) |
bc1385a6 UH |
80 | self.state = 'IGNORE START REPEAT' |
81 | self.data = [] | |
82 | else: | |
0eeeb544 | 83 | raise Exception('Invalid state: %s' % self.state) |
bc1385a6 | 84 |