X-Git-Url: https://vault307.fbx.one/gitweb/micorpython_ir.git/blobdiff_plain/22acf8e1d02787907c7eacba1756b5acd1c4495f..7156dff5bcd19a1debf7db1ffd4add94e010c66f:/ir_rx/test.py?ds=sidebyside diff --git a/ir_rx/test.py b/ir_rx/test.py index 354a656..c4dbd7f 100644 --- a/ir_rx/test.py +++ b/ir_rx/test.py @@ -1,8 +1,8 @@ # test.py Test program for IR remote control decoder -# Supports Pyboard ESP32 and ESP8266 +# Supports Pyboard, ESP32 and ESP8266 # Author: Peter Hinch -# Copyright Peter Hinch 2020 Released under the MIT license +# Copyright Peter Hinch 2020-2022 Released under the MIT license # Run this to characterise a remote. @@ -11,49 +11,60 @@ import time import gc from machine import Pin, freq from ir_rx.print_error import print_error # Optional print of error codes + # Import all implemented classes -from ir_rx.nec import NEC_8, NEC_16 +from ir_rx.nec import NEC_8, NEC_16, SAMSUNG from ir_rx.sony import SONY_12, SONY_15, SONY_20 from ir_rx.philips import RC5_IR, RC6_M0 +from ir_rx.mce import MCE # Define pin according to platform -if platform == 'pyboard': - p = Pin('X3', Pin.IN) -elif platform == 'esp8266': +if platform == "pyboard": + p = Pin("X3", Pin.IN) +elif platform == "esp8266": freq(160000000) p = Pin(13, Pin.IN) -elif platform == 'esp32' or platform == 'esp32_LoBo': - p = Pin(23, Pin.IN) # was 27 +elif platform == "esp32" or platform == "esp32_LoBo": + p = Pin(23, Pin.IN) +elif platform == "rp2": + p = Pin(16, Pin.IN) # User callback def cb(data, addr, ctrl): if data < 0: # NEC protocol sends repeat codes. - print('Repeat code.') + print("Repeat code.") else: - print('Data {:02x} Addr {:04x} Ctrl {:02x}'.format(data, addr, ctrl)) + print(f"Data 0x{data:02x} Addr 0x{addr:04x} Ctrl 0x{ctrl:02x}") + -def run(proto=0): - classes = (NEC_8, NEC_16, SONY_12, SONY_15, SONY_20, RC5_IR, RC6_M0) +def test(proto=0): + classes = (NEC_8, NEC_16, SONY_12, SONY_15, SONY_20, RC5_IR, RC6_M0, MCE, SAMSUNG) ir = classes[proto](p, cb) # Instantiate receiver ir.error_function(print_error) # Show debug information - #ir.verbose = True + # ir.verbose = True # A real application would do something here... - while True: - print('running') - time.sleep(5) - gc.collect() + try: + while True: + print("running") + time.sleep(5) + gc.collect() + except KeyboardInterrupt: + ir.close() + # **** DISPLAY GREETING **** -s = '''Test for IR receiver. Run: -from ir_rx import test -test.run() for NEC 8 bit protocol, -test.run(1) for NEC 16 bit, -test.run(2) for Sony SIRC 12 bit, -test.run(3) for Sony SIRC 15 bit, -test.run(4) for Sony SIRC 20 bit, -test.run(5) for Philips RC-5 protocol, -test.run(6) for RC6 mode 0. - -Hit ctrl-c to stop, then ctrl-d to soft reset.''' +s = """Test for IR receiver. Run: +from ir_rx.test import test +test() for NEC 8 bit protocol, +test(1) for NEC 16 bit, +test(2) for Sony SIRC 12 bit, +test(3) for Sony SIRC 15 bit, +test(4) for Sony SIRC 20 bit, +test(5) for Philips RC-5 protocol, +test(6) for RC6 mode 0. +test(7) for Microsoft Vista MCE. +test(8) for Samsung. + +Hit ctrl-c to stop, then ctrl-d to soft reset.""" print(s)