Skip to content

Commit

Permalink
Merge pull request #68 from tkomde/feature/updates202404
Browse files Browse the repository at this point in the history
Compatibility for NEC protocol is fixed
  • Loading branch information
FoamyGuy authored Apr 21, 2024
2 parents 72b03fe + 8e981d9 commit d3f3b31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions adafruit_irremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion examples/irremote_transmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d3f3b31

Please sign in to comment.