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