Skip to content

Commit e73de46

Browse files
committed
Compatibility fixed.
1 parent 72b03fe commit e73de46

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

adafruit_irremote.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ def decode_bits(pulses: List) -> NamedTuple:
171171
# convert marks/spaces to 0 and 1
172172
for i, pulse_length in enumerate(pulses):
173173
if (space * 0.75) <= pulse_length <= (space * 1.25):
174-
pulses[i] = False
175-
elif (mark * 0.75) <= pulse_length <= (mark * 1.25):
176174
pulses[i] = True
175+
elif (mark * 0.75) <= pulse_length <= (mark * 1.25):
176+
pulses[i] = False
177177
else:
178178
msg = UnparseableIRMessage(input_pulses, reason="Pulses outside mark/space")
179179
raise FailedToDecode(msg)
@@ -342,15 +342,15 @@ def read_pulses(
342342
class GenericTransmit:
343343
"""Generic infrared transmit class that handles encoding.
344344
345-
:param int header: The length of header in microseconds
346-
:param int one: The length of a one in microseconds
347-
:param int zero: The length of a zero in microseconds
345+
:param List[int] header: The length of header in microseconds, the length should be even
346+
:param List[int] one: The length of a one in microseconds
347+
:param List[int] zero: The length of a zero in microseconds
348348
:param int trail: The length of the trail in microseconds, set to None to disable
349349
:param bool debug: Enable debug output, default False
350350
"""
351351

352352
def __init__(
353-
self, header: int, one: int, zero: int, trail: int, *, debug: bool = False
353+
self, header: List[int], one: List[int], zero: List[int], trail: int, *, debug: bool = False
354354
) -> None:
355355
self.header = header
356356
self.one = one
@@ -381,14 +381,15 @@ def transmit(
381381
bits_to_send = nbits
382382

383383
durations = array.array(
384-
"H", [0] * (2 + bits_to_send * 2 + (0 if self.trail is None else 1))
384+
"H", [0] * (len(self.header) + bits_to_send * 2 + (0 if self.trail is None else 1))
385385
)
386-
387-
durations[0] = self.header[0]
388-
durations[1] = self.header[1]
386+
387+
for i, _ in enumerate(self.header):
388+
durations[i] = self.header[i]
389+
389390
if self.trail is not None:
390391
durations[-1] = self.trail
391-
out = 2
392+
out = len(self.header)
392393
bit_count = 0
393394
for byte_index, _ in enumerate(data):
394395
for i in range(7, -1, -1):

examples/irremote_transmit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
pulseout = pulseio.PulseOut(board.IR_TX, frequency=38000, duty_cycle=2**15)
1919
# Create an encoder that will take numbers and turn them into NEC IR pulses
2020
encoder = adafruit_irremote.GenericTransmit(
21-
header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0
21+
header=[9000, 4500], one=[560, 1700], zero=[560, 1700], trail=560
2222
)
2323

2424
while True:

0 commit comments

Comments
 (0)