Thanks to visit codestin.com
Credit goes to github.com

Skip to content

read_pulses() still blocks #32

Closed
Closed
@mfeif

Description

@mfeif

I've read through #18 after having trouble reading repeat commands from my IR remote. Here's some code to illustrate what I'm seeing, which is that while the remote is "clicked" on anything, the loop gets stuck:

(this is a light change from the bundled example file in this repo)

import pulseio
import board
import adafruit_irremote

pin = board.D17

pulsein = pulseio.PulseIn(pin, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()

while True:
    pulses = decoder.read_pulses(pulsein, blocking=False)
    if pulses:
        print("\nHeard", len(pulses), "Pulses:", pulses, flush=True)
        try:
            code = decoder.decode_bits(pulses)
            print("Decoded:", code)
        except adafruit_irremote.IRNECRepeatException:
            pass
        except adafruit_irremote.IRDecodeException as e:
            pass
    else:
        print('.', end='', flush=True)

If you run this, you'll see a flood of "." filling the console, as expected, but as soon as you put some activity on the pin, the flood will pause. This will pause indefinitely... I held down for 10+ seconds, and it blocked. When I let go, only one event was returned.

I tried to reason through _read_pulses_non_blocking() in adafruit_irremote.py but I'm having trouble, since I don't really know what it's trying to do, so I can't spot the bug in the logic there.

I've also seen Kevin's work here that includes a timeout feature that seems to taking a stab at the same thing. It works, and even supports the repeat exception that in the example code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions