From 49d1582ab6c21c4ecfb34162b78fdd33b5a22874 Mon Sep 17 00:00:00 2001 From: Adam Patt Date: Tue, 15 May 2018 14:03:19 -0400 Subject: [PATCH] https://github.com/adafruit/Adafruit_CircuitPython_IRRemote/issues/6 --- adafruit_irremote.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/adafruit_irremote.py b/adafruit_irremote.py index 0a2937b..4cd6e0e 100644 --- a/adafruit_irremote.py +++ b/adafruit_irremote.py @@ -189,16 +189,20 @@ def decode_bits(self, pulses, debug=False): output[i // 8] |= 1 return output - def read_pulses(self, input_pulses, max_pulse=10000): + def read_pulses(self, input_pulses, max_pulse=10000, blocking=True): """Read out a burst of pulses until a pulse is longer than ``max_pulse``. :param ~pulseio.PulseIn input_pulses: Object to read pulses from :param int max_pulse: Pulse duration to end a burst + :param bool blocking: If True, will block until pulses found. + If False, will return None if no pulses. + Defaults to True for backwards compatibility """ received = [] while True: while len(input_pulses) < 8: # not too big (slower) or too small (underruns)! - pass + if not blocking: + return None while input_pulses: pulse = input_pulses.popleft() if pulse > max_pulse: