]> vault307.fbx.one Git - micorpython_ir.git/blob - ir_rx_test.py
Prior to package.
[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 import gc
12 from machine import Pin, freq
13 from ir_rx import *
14
15 ESP32 = platform == 'esp32' or platform == 'esp32_LoBo'
16
17 if platform == 'pyboard':
18 p = Pin('X3', Pin.IN)
19 elif platform == 'esp8266':
20 freq(160000000)
21 p = Pin(13, Pin.IN)
22 elif ESP32:
23 p = Pin(23, Pin.IN) # was 27
24
25 # User callback
26 def cb(data, addr, ctrl):
27 if data < 0: # NEC protocol sends repeat codes.
28 print('Repeat code.')
29 else:
30 print('Data {:03x} Addr {:03x} Ctrl {:01x}'.format(data, addr, ctrl))
31
32 # Optionally print debug information
33 def errf(data):
34 errors = {BADSTART : 'Invalid start pulse', BADBLOCK : 'Error: bad block',
35 BADREP : 'Error: repeat', OVERRUN : 'Error: overrun',
36 BADDATA : 'Error: invalid data', BADADDR : 'Error: invalid address'}
37 print(errors[data])
38
39 s = '''Test for IR receiver. Run:
40 from ir_rx_test import test
41 test() for NEC protocol,
42 test(1) for Sony SIRC 12 bit,
43 test(2) for Sony SIRC 15 bit,
44 test(3) for Sony SIRC 20 bit,
45 test(5) for Philips RC-5 protocol,
46 test(6) for RC6 mode 0.
47
48 Hit ctrl-c to stop, then ctrl-d to soft reset.'''
49
50 print(s)
51
52 def test(proto=0):
53 if proto == 0:
54 ir = NEC_IR(p, cb) # Extended mode
55 elif proto < 4:
56 ir = SONY_IR(p, cb)
57 ir.bits = (12, 15, 20)[proto - 1]
58 #ir.verbose = True
59 elif proto == 5:
60 ir = RC5_IR(p, cb)
61 elif proto == 6:
62 ir = RC6_M0(p, cb)
63 ir.error_function(errf) # Show debug information
64 # A real application would do something here...
65 while True:
66 print('running')
67 time.sleep(5)
68 gc.collect()