@@ -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,21 @@ def read_pulses(
342342class 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 ,
354+ header : List [int ],
355+ one : List [int ],
356+ zero : List [int ],
357+ trail : int ,
358+ * ,
359+ debug : bool = False ,
354360 ) -> None :
355361 self .header = header
356362 self .one = one
@@ -381,14 +387,17 @@ def transmit(
381387 bits_to_send = nbits
382388
383389 durations = array .array (
384- "H" , [0 ] * (2 + bits_to_send * 2 + (0 if self .trail is None else 1 ))
390+ "H" ,
391+ [0 ]
392+ * (len (self .header ) + bits_to_send * 2 + (0 if self .trail is None else 1 )),
385393 )
386394
387- durations [0 ] = self .header [0 ]
388- durations [1 ] = self .header [1 ]
395+ for i , _ in enumerate (self .header ):
396+ durations [i ] = self .header [i ]
397+
389398 if self .trail is not None :
390399 durations [- 1 ] = self .trail
391- out = 2
400+ out = len ( self . header )
392401 bit_count = 0
393402 for byte_index , _ in enumerate (data ):
394403 for i in range (7 , - 1 , - 1 ):
0 commit comments