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