Skip to content

Commit 72b03fe

Browse files
authored
Merge pull request #67 from Kry-Vosa/main
Fix for uncleared buffer in NonblockingGenericDecode
2 parents bfcc72c + a44922f commit 72b03fe

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

adafruit_irremote.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,20 @@ def read(self) -> None:
237237
# Consume from PulseIn.
238238
while self.pulses:
239239
pulse = self.pulses.popleft()
240-
self._unparsed_pulses.append(pulse)
241-
if pulse > self.max_pulse:
240+
if pulse <= self.max_pulse:
241+
self._unparsed_pulses.append(pulse)
242+
else:
242243
# End of message! Decode it and yield a BaseIRMessage.
244+
result = None
243245
try:
244-
yield decode_bits(self._unparsed_pulses)
246+
result = decode_bits(self._unparsed_pulses)
245247
except FailedToDecode as err:
246248
# If you want to debug failed decodes, this would be a good
247249
# place to print/log or (re-)raise.
248-
unparseable_message = err.args[0]
249-
yield unparseable_message
250+
result = err.args[0]
251+
250252
self._unparsed_pulses.clear()
251-
# TODO Do we need to consume and throw away more pulses here?
252-
# I'm unclear about the role that "pruning" plays in the
253-
# original implementation in GenericDecode._read_pulses_non_blocking.
254-
# When we reach here, we have consumed everything from PulseIn.
255-
# If there are some pulses in self._unparsed_pulses, they represent
256-
# partial messages. We'll finish them next time read() is called.
253+
yield result
257254

258255

259256
class GenericDecode:

0 commit comments

Comments
 (0)