]> sigrok.org Git - libsigrokdecode.git/blame - decoders/mlx90614/pd.py
all decoders: introduce a reset() method
[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
4539e9ca 17## along with this program; if not, see <http://www.gnu.org/licenses/>.
bc1385a6
UH
18##
19
bc1385a6
UH
20import sigrokdecode as srd
21
22class Decoder(srd.Decoder):
b197383c 23 api_version = 3
bc1385a6
UH
24 id = 'mlx90614'
25 name = 'MLX90614'
26 longname = 'Melexis MLX90614'
a465436e 27 desc = 'Infrared Thermometer protocol.'
bc1385a6
UH
28 license = 'gplv2+'
29 inputs = ['i2c']
30 outputs = ['mlx90614']
da9bcbd9
BV
31 annotations = (
32 ('celsius', 'Temperature in degrees Celsius'),
33 ('kelvin', 'Temperature in Kelvin'),
34 )
bc1385a6 35
92b7b49f 36 def __init__(self):
10aeb8ea
GS
37 self.reset()
38
39 def reset(self):
bc1385a6
UH
40 self.state = 'IGNORE START REPEAT'
41 self.data = []
42
8915b346 43 def start(self):
be465111 44 self.out_ann = self.register(srd.OUTPUT_ANN)
bc1385a6 45
bc1385a6
UH
46 def putx(self, data):
47 self.put(self.ss, self.es, self.out_ann, data)
48
49 # Quick hack implementation! This needs to be improved a lot!
50 def decode(self, ss, es, data):
1b75abfd 51 cmd, databyte = data
bc1385a6
UH
52
53 # State machine.
54 if self.state == 'IGNORE START REPEAT':
55 if cmd != 'START REPEAT':
56 return
57 self.state = 'IGNORE ADDRESS WRITE'
58 elif self.state == 'IGNORE ADDRESS WRITE':
59 if cmd != 'ADDRESS WRITE':
60 return
61 self.state = 'GET TEMPERATURE'
62 elif self.state == 'GET TEMPERATURE':
69ff19c8
UH
63 if cmd != 'DATA WRITE':
64 return
bc1385a6 65 if len(self.data) == 0:
7f7ea759 66 self.data.append(databyte)
bc1385a6
UH
67 self.ss = ss
68 elif len(self.data) == 1:
7f7ea759 69 self.data.append(databyte)
bc1385a6
UH
70 self.es = es
71 else:
72 kelvin = (self.data[0] | (self.data[1] << 8)) * 0.02
73 celsius = kelvin - 273.15
afff6b1a 74 self.putx([0, ['Temperature: %3.2f °C' % celsius]])
f2e114de 75 self.putx([1, ['Temperature: %3.2f K' % kelvin]])
bc1385a6
UH
76 self.state = 'IGNORE START REPEAT'
77 self.data = []