]> sigrok.org Git - libsigrokdecode.git/blame - decoders/rgb_led/pd.py
Initial RGB LED decoder
[libsigrokdecode.git] / decoders / rgb_led / pd.py
CommitLineData
2c173272
MR
1##
2## This file is part of the libsigrokdecode project.
3##
4## Copyright (C) 2014 Matt Ranostay <mranostay@gmail.com>
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
21import sigrokdecode as srd
22
23class Decoder(srd.Decoder):
24 api_version =1
25 id = 'rgb_led'
26 name = 'RGB LED (SPI mode)'
27 longname = 'RGB LED string decoder (SPI mode)'
28 desc = ''
29 license = 'gplv2'
30 inputs = ['spi']
31 outputs = ['rgb_led']
32 probes = []
33 optional_probes = []
34 options = {}
35 annotations = [
36 ['text', 'Human-readable text'],
37 ['warnings', 'Human-readable warnings'],
38 ]
39
40 def __init__(self, **kwargs):
41 self.cmd_ss, self.cmd_es = 0, 0
42 self.mosi_bytes = []
43
44 def start(self):
45 self.out_ann = self.register(srd.OUTPUT_ANN)
46
47 def putx(self, data):
48 self.put(self.cmd_ss, self.cmd_es, self.out_ann, data)
49
50 def decode(self, ss, es, data):
51 ptype, mosi, miso = data
52
53 # Only care about data packets
54 if ptype != 'DATA':
55 return
56 self.ss, self.es = ss, es
57
58 if len(self.mosi_bytes) == 0:
59 self.cmd_ss = ss
60 self.mosi_bytes.append(mosi)
61
62 # RGB value == 3 bytes
63 if len(self.mosi_bytes) != 3:
64 return
65
66 red, green, blue = self.mosi_bytes
67 rgb_value = int(red) << 16
68 rgb_value |= int(green) << 8
69 rgb_value |= int(blue)
70
71 self.putx([0, ["#%.6x" % rgb_value]])
72 self.mosi_bytes = []