]>
vault307.fbx.one Git - micorpython_ir.git/blob - ir_tx/nec.py
da1af24a8ae75a0f32735a04aedf56c7c5e61b4c
1 # nec.py Encoder for IR remote control using synchronous code
5 # Copyright Peter Hinch 2020 Released under the MIT license
7 from micropython
import const
8 from ir_tx
import IR
, STOP
14 valid
= (0xffff, 0xff, 0) # Max addr, data, toggle
16 def __init__(self
, pin
, freq
=38000, verbose
=False): # NEC specifies 38KHz
17 super().__init
__(pin
, freq
, 68, 33, verbose
) # Measured duty ratio 33%
20 self
.append(_TBURST
, _T_ONE
if b
else _TBURST
)
22 def tx(self
, addr
, data
, _
): # Ignore toggle
23 self
.append(9000, 4500)
24 if addr
< 256: # Short address: append complement
25 addr |
= ((addr ^
0xff) << 8)
29 data |
= ((data ^
0xff) << 8)
37 self
.append(9000, 2250, _TBURST
)
38 self
.trigger() # Initiate physical transmission.