]> vault307.fbx.one Git - micorpython_ir.git/blob - ir_rx_test.py
908d23f83cb229e29f2610bba9971a2ec417b0ac
[micorpython_ir.git] / ir_rx_test.py
1 # ir_rx_test.py Test program for IR remote control decoder arem.py
2 # Supports Pyboard and ESP8266
3
4 # Author: Peter Hinch
5 # Copyright Peter Hinch 2020 Released under the MIT license
6
7 # Run this to characterise a remote.
8
9 from sys import platform
10 import time
11 from machine import Pin, freq
12 from arem import *
13
14 ESP32 = platform == 'esp32' or platform == 'esp32_LoBo'
15
16 if platform == 'pyboard':
17 p = Pin('X3', Pin.IN)
18 elif platform == 'esp8266':
19 freq(160000000)
20 p = Pin(13, Pin.IN)
21 elif ESP32:
22 p = Pin(23, Pin.IN)
23
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'}
27
28 def cb(data, addr, ctrl):
29 if data == REPEAT: # NEC protocol sends repeat codes.
30 print('Repeat code.')
31 elif data >= 0:
32 print('Data {:03x} Addr {:03x} Ctrl {:01x}'.format(data, addr, ctrl))
33 else:
34 print('{} Address: {}'.format(errors[data], hex(addr)))
35
36
37 s = '''Test for IR receiver. Run:
38 ir_tx_test.test() for NEC protocol,
39 ir_tx_test.test(5) for Philips RC-5 protocol,
40 ir_tx_test.test(6) for RC6 mode 0.
41
42 Background processing means REPL prompt reappears.
43 Hit ctrl-D to stop (soft reset).'''
44
45 print(s)
46
47 def test(proto=0):
48 if proto == 0:
49 ir = NEC_IR(p, cb, True, 0) # Extended mode, dummy ctrl arg for callback
50 elif proto == 5:
51 ir = RC5_IR(p, cb)
52 elif proto == 6:
53 ir = RC6_M0(p, cb)
54 # A real application would do something here...
55 #while True:
56 #time.sleep(5)
57 #print('running')