micropython_ir icon indicating copy to clipboard operation
micropython_ir copied to clipboard

Return protocol detected with ir_rx/acquire.py acquire function

Open mario872 opened this issue 8 months ago • 2 comments

I was trying to detect the protocol of an IR command, and found there was no way to properly do it programmatically. So I modified ir_rx/acquire.py. The IR_GET.acquire function now returns a dict with the keys raw and protocol. raw returns the marks and spaces list as before, and protocol returns the protocol detected by decode(), or Unknown. I also modified acquire.py to still try and detect the protocol used, even if display is False. Setting display to True uses print statements and returns the protocol and marks and spaces programmatically, whereas False just doesn't print anything. I also updated the docs for the receiver and transmitter to reflect the changes.

Here is a small test script:

from ir_rx.acquire import IR_GET
from machine import Pin

IR_GET.Timer_id = 0 # For ESP32-C3, although I need to use this on ESP32-S3 for some reason too.
ir_rx = IR_GET(Pin(10, Pin.IN), display=False) # Run without output in terminal
data = ir_rx.acquire()
print("Raw data bursts: " + str(data["raw"]))
print("Protocol: " + data["protocol"])

This was only tested on an ESP32-S3, although I doubt further testing on other chip families is needed.

Thank you for this wonderful library, and as this is my first pull request, please let me know if I got something wrong.

mario872 avatar Jun 18 '25 08:06 mario872