]> vault307.fbx.one Git - micorpython_ir.git/blob - ir_rx_test.py
Receiver now a 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.print_error import print_error # Optional print of error codes
14 # Import all implemented classes
15 from ir_rx.nec import NEC_8, NEC_16
16 from ir_rx.sony import SONY_12, SONY_15, SONY_20
17 from ir_rx.philips import RC5_IR, RC6_M0
18
19 # Define pin according to platform
20 if platform == 'pyboard':
21 p = Pin('X3', Pin.IN)
22 elif platform == 'esp8266':
23 freq(160000000)
24 p = Pin(13, Pin.IN)
25 elif platform == 'esp32' or platform == 'esp32_LoBo':
26 p = Pin(23, Pin.IN) # was 27
27
28 # User callback
29 def cb(data, addr, ctrl):
30 if data < 0: # NEC protocol sends repeat codes.
31 print('Repeat code.')
32 else:
33 print('Data {:02x} Addr {:04x} Ctrl {:02x}'.format(data, addr, ctrl))
34
35 def test(proto=0):
36 classes = (NEC_8, NEC_16, SONY_12, SONY_15, SONY_20, RC5_IR, RC6_M0)
37 ir = classes[proto](p, cb) # Instantiate receiver
38 ir.error_function(print_error) # Show debug information
39 #ir.verbose = True
40 # A real application would do something here...
41 while True:
42 print('running')
43 time.sleep(5)
44 gc.collect()
45
46 # **** DISPLAY GREETING ****
47 s = '''Test for IR receiver. Run:
48 from ir_rx_test import test
49 test() for NEC 8 bit protocol,
50 test(1) for NEC 16 bit,
51 test(2) for Sony SIRC 12 bit,
52 test(3) for Sony SIRC 15 bit,
53 test(4) for Sony SIRC 20 bit,
54 test(5) for Philips RC-5 protocol,
55 test(6) for RC6 mode 0.
56
57 Hit ctrl-c to stop, then ctrl-d to soft reset.'''
58
59 print(s)