]> sigrok.org Git - libsigrokdecode.git/blame_incremental - decoders/mlx90614/pd.py
mlx90614: Add annotation rows.
[libsigrokdecode.git] / decoders / mlx90614 / pd.py
... / ...
CommitLineData
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, see <http://www.gnu.org/licenses/>.
18##
19
20import sigrokdecode as srd
21
22class Decoder(srd.Decoder):
23 api_version = 3
24 id = 'mlx90614'
25 name = 'MLX90614'
26 longname = 'Melexis MLX90614'
27 desc = 'Melexis MLX90614 infrared thermometer protocol.'
28 license = 'gplv2+'
29 inputs = ['i2c']
30 outputs = []
31 tags = ['IC', 'Sensor']
32 annotations = (
33 ('celsius', 'Temperature / °C'),
34 ('kelvin', 'Temperature / K'),
35 )
36 annotation_rows = (
37 ('temps-celsius', 'Temperature / °C', (0,)),
38 ('temps-kelvin', 'Temperature / K', (1,)),
39 )
40
41 def __init__(self):
42 self.reset()
43
44 def reset(self):
45 self.state = 'IGNORE START REPEAT'
46 self.data = []
47
48 def start(self):
49 self.out_ann = self.register(srd.OUTPUT_ANN)
50
51 def putx(self, data):
52 self.put(self.ss, self.es, self.out_ann, data)
53
54 # Quick hack implementation! This needs to be improved a lot!
55 def decode(self, ss, es, data):
56 cmd, databyte = data
57
58 # State machine.
59 if self.state == 'IGNORE START REPEAT':
60 if cmd != 'START REPEAT':
61 return
62 self.state = 'IGNORE ADDRESS WRITE'
63 elif self.state == 'IGNORE ADDRESS WRITE':
64 if cmd != 'ADDRESS WRITE':
65 return
66 self.state = 'GET TEMPERATURE'
67 elif self.state == 'GET TEMPERATURE':
68 if cmd != 'DATA WRITE':
69 return
70 if len(self.data) == 0:
71 self.data.append(databyte)
72 self.ss = ss
73 elif len(self.data) == 1:
74 self.data.append(databyte)
75 self.es = es
76 else:
77 kelvin = (self.data[0] | (self.data[1] << 8)) * 0.02
78 celsius = kelvin - 273.15
79 self.putx([0, ['Temperature: %3.2f °C' % celsius]])
80 self.putx([1, ['Temperature: %3.2f K' % kelvin]])
81 self.state = 'IGNORE START REPEAT'
82 self.data = []