]>
vault307.fbx.one Git - micorpython_ir.git/blob - ir_rx_test.py
2785398cefbccb39537156312947b2590e5ae786
1 # ir_rx_test.py Test program for IR remote control decoder arem.py
2 # Supports Pyboard and ESP8266
5 # Copyright Peter Hinch 2020 Released under the MIT license
7 # Run this to characterise a remote.
9 from sys
import platform
11 from machine
import Pin
, freq
14 ESP32
= platform
== 'esp32' or platform
== 'esp32_LoBo'
16 if platform
== 'pyboard':
18 elif platform
== 'esp8266':
24 errors
= {BADSTART
: 'Invalid start pulse', BADBLOCK
: 'Error: bad block',
25 BADREP
: 'Error: repeat', OVERRUN
: 'Error: overrun',
26 BADDATA
: 'Error: invalid data', BADADDR
: 'Error: invalid address'}
28 def cb(data
, addr
, ctrl
):
29 if data
== REPEAT
: # NEC protocol sends repeat codes.
32 print('Data {:03x} Addr {:03x} Ctrl {:01x}'.format(data
, addr
, ctrl
))
34 print(errors
[data
]) # Application would ignore errors
37 s
= '''Test for IR receiver. Run:
38 from ir_rx_test import test
39 test() for NEC protocol,
40 test(1) for Sony SIRC 12 bit,
41 test(2) for Sony SIRC 15 bit,
42 test(3) for Sony SIRC 20 bit,
43 test(5) for Philips RC-5 protocol,
44 test(6) for RC6 mode 0.
46 Background processing means REPL prompt reappears.
47 Hit ctrl-D to stop (soft reset).'''
53 ir
= NEC_IR(p
, cb
) # Extended mode
55 bits
= (12, 15, 20)[proto
- 1]
56 ir
= SONY_IR(p
, cb
, bits
)
63 # A real application would do something here...