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