Skip to content

Commit 1820bf7

Browse files
committed
Don't modify the input pulses argument.
Instead of deleting header and trailer, just skip them when dividing the pulses in evens and odds.
1 parent d435fc9 commit 1820bf7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

adafruit_irremote.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ def decode_bits(self, pulses):
127127
if len(pulses) < 10:
128128
raise IRDecodeException("10 pulses minimum")
129129

130-
# remove any header
131-
del pulses[0]
132-
if len(pulses) % 2 == 1:
133-
del pulses[0]
130+
# Ignore any header (evens start at 1), and any trailer.
131+
if len(pulses) % 2 == 0:
132+
pulses_end = -1
133+
else:
134+
pulses_end = None
135+
136+
evens = pulses[1:pulses_end:2]
137+
odds = pulses[2:pulses_end:2]
134138

135-
evens = pulses[0::2]
136-
odds = pulses[1::2]
137139
# bin both halves
138140
even_bins = self.bin_data(evens)
139141
odd_bins = self.bin_data(odds)

0 commit comments

Comments
 (0)