]>
vault307.fbx.one Git - micorpython_ir.git/blob - ir_tx_test.py
1 # ir_tx_test.py Test for nonblocking NEC/RC-5/RC-6 mode 0 IR blaster.
3 # Released under the MIT License (MIT). See LICENSE.
5 # Copyright (c) 2020 Peter Hinch
7 # Implements a 2-button remote control on a Pyboard
9 from pyb
import Pin
, LED
10 import uasyncio
as asyncio
11 from aswitch
import Switch
, Delay_ms
12 from ir_tx
import NEC
, RC5
, RC6_M0
14 loop
= asyncio
.get_event_loop()
17 toggle
= 1 # toggle is ignored in NEC mode
18 def __init__(self
, irb
, pin
, addr
, data
, rep_code
=False):
23 self
.rep_code
= rep_code
24 self
.sw
.close_func(self
.cfunc
)
25 self
.sw
.open_func(self
.ofunc
)
26 self
.tim
= Delay_ms(self
.repeat
)
28 def cfunc(self
): # Button push: send data
29 self
.irb
.transmit(self
.addr
, self
.data
, Rbutton
.toggle
)
33 def ofunc(self
): # Button release: cancel repeat timer
35 Rbutton
.toggle ^
= 1 # Toggle control
37 async def repeat(self
):
38 await asyncio
.sleep(0) # Let timer stop before retriggering
39 if not self
.sw(): # Button is still pressed: retrigger
42 self
.irb
.repeat() # NEC special case: send REPEAT code
44 self
.irb
.transmit(self
.addr
, self
.data
, Rbutton
.toggle
)
46 async def main(proto
):
47 # Test uses a 38KHz carrier. Some Philips systems use 36KHz.
48 # If button is held down normal behaviour is to retransmit
49 # but most NEC models send a RPEAT code
50 rep_code
= False # Don't care for RC-X. NEC protocol only.
53 irb
= NEC(pin
) # Default NEC freq == 38KHz
54 # Option to send REPEAT code. Most remotes do this.
59 irb
= RC6_M0(pin
, 38000)
61 b
= [] # Rbutton instances
62 b
.append(Rbutton(irb
, Pin('X3', Pin
.IN
, Pin
.PULL_UP
), 0x1, 0x7, rep_code
))
63 b
.append(Rbutton(irb
, Pin('X4', Pin
.IN
, Pin
.PULL_UP
), 0x10, 0xb, rep_code
))
66 await asyncio
.sleep_ms(500) # Obligatory flashing LED.
69 s
= '''Test for IR transmitter. Run:
70 ir_tx_test.test() for NEC protocol
71 ir_tx_test.test(5) for RC-5 protocol
72 ir_tx_test.test(6) for RC-6 mode 0.
74 Ground X3 to send addr 1 data 7
75 Ground X4 to send addr 0x10 data 0x0b.'''
79 loop
.run_until_complete(main(proto
))