From 8a8fc29645419e7830d9709b8aad9787576821e2 Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Sun, 5 Jun 2022 17:51:45 +0100 Subject: [PATCH] Fix issue 14 NEC transmit error on RP2. --- ir_tx/__init__.py | 1 + ir_tx/rp2_rmt.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ir_tx/__init__.py b/ir_tx/__init__.py index a774bad..e791b4a 100644 --- a/ir_tx/__init__.py +++ b/ir_tx/__init__.py @@ -46,6 +46,7 @@ class IR: # 1μs resolution elif RP2: # PIO-based RMT-like device self._rmt = RP2_RMT(pin_pulse=None, carrier=(pin, cfreq, duty)) # 1μs resolution + asize += 1 # Allow for possible extra space pulse else: # Pyboard if not IR._active_high: duty = 100 - duty diff --git a/ir_tx/rp2_rmt.py b/ir_tx/rp2_rmt.py index 7b42fa8..2848419 100644 --- a/ir_tx/rp2_rmt.py +++ b/ir_tx/rp2_rmt.py @@ -82,10 +82,13 @@ class RP2_RMT: if d == 0: break if check: - # Discard any trailing mark which would leave carrier on. + # Pulse train must end with a space otherwise we leave carrier on. + # So, if it ends with a mark, append a space. Note __init__.py + # ensures that there is room in array. if (x & 1): - x -= 1 - ar[x] = 0 + ar[x] = 1 # space. Duration doesn't matter. + x += 1 + ar[x] = 0 # STOP self.icm = x # index of 1st STOP mv = memoryview(ar) n = min(x, 4) # Fill FIFO if there are enough data points. -- 2.47.3