]> vault307.fbx.one Git - micorpython_ir.git/blob - ir_tx/mce.py
Add MCE. Fix bug with RC5X.
[micorpython_ir.git] / ir_tx / mce.py
1 # mce.py Encoder for IR remote control using synchronous code
2 # Supports Microsoft MCE edition remote protocol.
3
4 # Author: Peter Hinch
5 # Copyright Peter Hinch 2020 Released under the MIT license
6
7 # WARNING: This is experimental and subject to change.
8
9 from micropython import const
10 from ir_tx import IR
11
12 _TBIT = const(500) # Time (μs) for pulse of carrier
13
14
15 class MCE(IR):
16 init_cs = 4 # http://www.hifi-remote.com/johnsfine/DecodeIR.html#OrtekMCE says 3
17
18 def __init__(self, pin, freq=38000, verbose=False):
19 super().__init__(pin, freq, 34, 30, verbose)
20
21 def tx(self, addr, data, toggle):
22 def checksum(v):
23 cs = self.init_cs
24 for _ in range(12):
25 if v & 1:
26 cs += 1
27 v >>= 1
28 return cs
29
30 self.append(2000, 1000, _TBIT)
31 d = ((data & 0x3f) << 6) | (addr & 0xf) | ((toggle & 3) << 4)
32 d |= checksum(d) << 12
33 self.verbose and print(bin(d))
34
35 mask = 1
36 while mask < 0x10000:
37 bit = bool(d & mask)
38 if bit ^ self.carrier:
39 self.add(_TBIT)
40 self.append(_TBIT)
41 else:
42 self.append(_TBIT, _TBIT)
43 mask <<= 1