From e73de460d737d18bc3a07459de670a8e52d53d90 Mon Sep 17 00:00:00 2001 From: Taiki Komoda Date: Wed, 17 Apr 2024 08:01:42 +0900 Subject: [PATCH 1/3] Compatibility fixed. --- adafruit_irremote.py | 23 ++++++++++++----------- examples/irremote_transmit.py | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/adafruit_irremote.py b/adafruit_irremote.py index f640607..eed1b5e 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,15 @@ 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 +381,15 @@ 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: From b8ed7cb09fd82226f1c696b627002e00f1c9828b Mon Sep 17 00:00:00 2001 From: Taiki Komoda Date: Wed, 17 Apr 2024 08:46:19 +0900 Subject: [PATCH 2/3] fix for linting --- adafruit_irremote.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/adafruit_irremote.py b/adafruit_irremote.py index eed1b5e..327e9c2 100644 --- a/adafruit_irremote.py +++ b/adafruit_irremote.py @@ -350,7 +350,13 @@ class GenericTransmit: """ def __init__( - self, header: List[int], one: List[int], zero: List[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,12 +387,14 @@ def transmit( bits_to_send = nbits durations = array.array( - "H", [0] * (len(self.header) + 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)) ) - + for i, _ in enumerate(self.header): durations[i] = self.header[i] - + if self.trail is not None: durations[-1] = self.trail out = len(self.header) From 8e981d9e5c0f349d89e365937857b27ac6d1b54e Mon Sep 17 00:00:00 2001 From: Taiki Komoda Date: Wed, 17 Apr 2024 08:49:55 +0900 Subject: [PATCH 3/3] Correction by linting --- adafruit_irremote.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_irremote.py b/adafruit_irremote.py index 327e9c2..46e67c0 100644 --- a/adafruit_irremote.py +++ b/adafruit_irremote.py @@ -353,10 +353,10 @@ def __init__( self, header: List[int], one: List[int], - zero: List[int], + zero: List[int], trail: int, *, - debug: bool = False + debug: bool = False, ) -> None: self.header = header self.one = one @@ -388,8 +388,8 @@ def transmit( durations = array.array( "H", - [0] - * (len(self.header) + bits_to_send * 2 + (0 if self.trail is None else 1)) + [0] + * (len(self.header) + bits_to_send * 2 + (0 if self.trail is None else 1)), ) for i, _ in enumerate(self.header):