2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
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.
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.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
20 import sigrokdecode as srd
22 class Decoder(srd.Decoder):
26 longname = 'Melexis MLX90614'
27 desc = 'Infrared Thermometer protocol.'
30 outputs = ['mlx90614']
32 ('celsius', 'Temperature in degrees Celsius'),
33 ('kelvin', 'Temperature in Kelvin'),
40 self.state = 'IGNORE START REPEAT'
44 self.out_ann = self.register(srd.OUTPUT_ANN)
47 self.put(self.ss, self.es, self.out_ann, data)
49 # Quick hack implementation! This needs to be improved a lot!
50 def decode(self, ss, es, data):
54 if self.state == 'IGNORE START REPEAT':
55 if cmd != 'START REPEAT':
57 self.state = 'IGNORE ADDRESS WRITE'
58 elif self.state == 'IGNORE ADDRESS WRITE':
59 if cmd != 'ADDRESS WRITE':
61 self.state = 'GET TEMPERATURE'
62 elif self.state == 'GET TEMPERATURE':
63 if cmd != 'DATA WRITE':
65 if len(self.data) == 0:
66 self.data.append(databyte)
68 elif len(self.data) == 1:
69 self.data.append(databyte)
72 kelvin = (self.data[0] | (self.data[1] << 8)) * 0.02
73 celsius = kelvin - 273.15
74 self.putx([0, ['Temperature: %3.2f °C' % celsius]])
75 self.putx([1, ['Temperature: %3.2f K' % kelvin]])
76 self.state = 'IGNORE START REPEAT'