]> vault307.fbx.one Git - micorpython_ir.git/blob - ir_tx/sony.py
Release 0.1 Various bugfixes and improvements.
[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 valid = (0x1f, 0x7f, 0) # Max addr, data, toggle
36 def __init__(self, pin, freq=40000, verbose=False):
37 super().__init__(pin, 12, freq, verbose)
38
39 class SONY_15(SONY_ABC):
40 valid = (0xff, 0x7f, 0) # Max addr, data, toggle
41 def __init__(self, pin, freq=40000, verbose=False):
42 super().__init__(pin, 15, freq, verbose)
43
44 class SONY_20(SONY_ABC):
45 valid = (0x1f, 0x7f, 0xff) # Max addr, data, toggle
46 def __init__(self, pin, freq=40000, verbose=False):
47 super().__init__(pin, 20, freq, verbose)
48