Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility for NEC protocol is fixed #68

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading