]> vault307.fbx.one Git - micorpython_ir.git/blob - ir_tx/sony.py
Prior to merge.
[micorpython_ir.git] / ir_tx / sony.py
1 # sony.py Encoder for IR remote control using synchronous code
2 # Sony SIRC protocol.
3
4 # Author: Peter Hinch
5 # Copyright Peter Hinch 2020 Released under the MIT license
6
7 from micropython import const
8 from ir_tx import IR
9
10 class SONY_ABC(IR):
11
12 def __init__(self, pin, bits, freq, verbose):
13 super().__init__(pin, freq, 3 + bits * 2, 30, verbose)
14 if bits not in (12, 15, 20):
15 raise ValueError('bits must be 12, 15 or 20.')
16 self.bits = bits
17
18 def tx(self, addr, data, ext):
19 self.append(2400, 600)
20 bits = self.bits
21 v = data & 0x7f
22 if bits == 12:
23 v |= (addr & 0x1f) << 7
24 elif bits == 15:
25 v |= (addr & 0xff) << 7
26 else:
27 v |= (addr & 0x1f) << 7
28 v |= (ext & 0xff) << 12
29 for _ in range(bits):
30 self.append(1200 if v & 1 else 600, 600)
31 v >>= 1
32
33 # Sony specifies 40KHz
34 class SONY_12(SONY_ABC):
35 def __init__(self, pin, freq=40000, verbose=False):
36 super().__init__(pin, 12, freq, verbose)
37
38 class SONY_15(SONY_ABC):
39 def __init__(self, pin, freq=40000, verbose=False):
40 super().__init__(pin, 15, freq, verbose)
41
42 class SONY_20(SONY_ABC):
43 def __init__(self, pin, freq=40000, verbose=False):
44 super().__init__(pin, 20, freq, verbose)
45