diff --git a/adafruit_irremote.py b/adafruit_irremote.py index f640607..46e67c0 100644 --- a/adafruit_irremote.py +++ b/adafruit_irremote.py @@ -171,9 +171,9 @@ def decode_bits(pulses: List) -> NamedTuple: # convert marks/spaces to 0 and 1 for i, pulse_length in enumerate(pulses): if (space * 0.75) <= pulse_length <= (space * 1.25): - pulses[i] = False - elif (mark * 0.75) <= pulse_length <= (mark * 1.25): pulses[i] = True + elif (mark * 0.75) <= pulse_length <= (mark * 1.25): + pulses[i] = False else: msg = UnparseableIRMessage(input_pulses, reason="Pulses outside mark/space") raise FailedToDecode(msg) @@ -342,15 +342,21 @@ def read_pulses( class GenericTransmit: """Generic infrared transmit class that handles encoding. - :param int header: The length of header in microseconds - :param int one: The length of a one in microseconds - :param int zero: The length of a zero in microseconds + :param List[int] header: The length of header in microseconds, the length should be even + :param List[int] one: The length of a one in microseconds + :param List[int] zero: The length of a zero in microseconds :param int trail: The length of the trail in microseconds, set to None to disable :param bool debug: Enable debug output, default False """ def __init__( - self, header: int, one: int, zero: int, trail: int, *, debug: bool = False + self, + header: List[int], + one: List[int], + zero: List[int], + trail: int, + *, + debug: bool = False, ) -> None: self.header = header self.one = one @@ -381,14 +387,17 @@ def transmit( bits_to_send = nbits durations = array.array( - "H", [0] * (2 + bits_to_send * 2 + (0 if self.trail is None else 1)) + "H", + [0] + * (len(self.header) + bits_to_send * 2 + (0 if self.trail is None else 1)), ) - durations[0] = self.header[0] - durations[1] = self.header[1] + for i, _ in enumerate(self.header): + durations[i] = self.header[i] + if self.trail is not None: durations[-1] = self.trail - out = 2 + out = len(self.header) bit_count = 0 for byte_index, _ in enumerate(data): for i in range(7, -1, -1): diff --git a/examples/irremote_transmit.py b/examples/irremote_transmit.py index 385d3c5..18a88bf 100644 --- a/examples/irremote_transmit.py +++ b/examples/irremote_transmit.py @@ -18,7 +18,7 @@ pulseout = pulseio.PulseOut(board.IR_TX, frequency=38000, duty_cycle=2**15) # Create an encoder that will take numbers and turn them into NEC IR pulses encoder = adafruit_irremote.GenericTransmit( - header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0 + header=[9000, 4500], one=[560, 1700], zero=[560, 1700], trail=560 ) while True: