]>
vault307.fbx.one Git - micorpython_ir.git/blob - ir_tx/philips.py
1 # philips.py Encoder for IR remote control using synchronous code
2 # RC-5 and RC-6 mode 0 protocols.
5 # Copyright Peter Hinch 2020 Released under the MIT license
7 from micropython
import const
8 from sys
import platform
9 ESP32
= platform
== 'esp32' or platform
== 'esp32_LoBo'
12 # Philips RC5 protocol
13 _T_RC5
= const(889) # Time for pulse of carrier
14 ermsg
= 'ESP32 does not support Philips protocols'
17 def __init__(self
, pin
, freq
=36000, verbose
=False):
19 raise RuntimeError(ermsg
)
20 super().__init
__(pin
, freq
, 28, 30, verbose
)
22 def tx(self
, addr
, data
, toggle
):
23 d
= (data
& 0x3f) |
((addr
& 0x1f) << 6) |
((data
& 0x40) << 6) |
((toggle
& 1) << 11)
24 self
.verbose
and print(bin(d
))
31 if bit ^ self
.carrier
:
35 self
.append(_T_RC5
, _T_RC5
)
38 # Philips RC6 mode 0 protocol
44 def __init__(self
, pin
, freq
=36000, verbose
=False):
46 raise RuntimeError(ermsg
)
47 super().__init
__(pin
, freq
, 44, 30, verbose
)
49 def tx(self
, addr
, data
, toggle
):
51 self
.append(2666, _T2_RC6
, _T_RC6
, _T2_RC6
, _T_RC6
, _T_RC6
, _T_RC6
, _T_RC6
, _T_RC6
)
52 # Append a single bit of twice duration
57 self
.append(_T2_RC6
, _T2_RC6
)
58 d
= (data
& 0xff) |
((addr
& 0xff) << 8)
60 self
.verbose
and print('toggle', toggle
, self
.carrier
, bool(d
& mask
))
63 if bit ^ self
.carrier
:
64 self
.append(_T_RC6
, _T_RC6
)