Skip to content

Fix for uncleared buffer in NonblockingGenericDecode #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions adafruit_irremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,20 @@ def read(self) -> None:
# Consume from PulseIn.
while self.pulses:
pulse = self.pulses.popleft()
self._unparsed_pulses.append(pulse)
if pulse > self.max_pulse:
if pulse <= self.max_pulse:
self._unparsed_pulses.append(pulse)
else:
# End of message! Decode it and yield a BaseIRMessage.
result = None
try:
yield decode_bits(self._unparsed_pulses)
result = decode_bits(self._unparsed_pulses)
except FailedToDecode as err:
# If you want to debug failed decodes, this would be a good
# place to print/log or (re-)raise.
unparseable_message = err.args[0]
yield unparseable_message
result = err.args[0]

self._unparsed_pulses.clear()
# TODO Do we need to consume and throw away more pulses here?
# I'm unclear about the role that "pruning" plays in the
# original implementation in GenericDecode._read_pulses_non_blocking.
# When we reach here, we have consumed everything from PulseIn.
# If there are some pulses in self._unparsed_pulses, they represent
# partial messages. We'll finish them next time read() is called.
yield result


class GenericDecode:
Expand Down