Skip to content

Commit c600993

Browse files
authored
fix: shorten NECCommand gap after initial command (#11)
1 parent 34c1c1e commit c600993

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

infrared_protocols/commands.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def get_raw_timings(self) -> list[Timing]:
6868
zero_low = 562
6969
one_low = 1687
7070
repeat_low = 2250
71+
initial_frame_gap = 41000 # Gap to make total frame ~108ms
7172
frame_gap = 96000 # Gap to make total frame ~108ms
7273

7374
timings: list[Timing] = [Timing(high_us=leader_high, low_us=leader_low)]
@@ -105,10 +106,12 @@ def get_raw_timings(self) -> list[Timing]:
105106
timings.append(Timing(high_us=bit_high, low_us=0))
106107

107108
# Add repeat codes if requested
109+
gap = initial_frame_gap
108110
for _ in range(self.repeat_count):
109111
# Replace the last timing's low_us with the frame gap
110112
last_timing = timings[-1]
111-
timings[-1] = Timing(high_us=last_timing.high_us, low_us=frame_gap)
113+
timings[-1] = Timing(high_us=last_timing.high_us, low_us=gap)
114+
gap = frame_gap # Use standard frame gap for subsequent repeats
112115

113116
# Repeat code: leader burst + shorter space + end pulse
114117
timings.extend(

tests/test_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_nec_command_get_raw_timings_standard() -> None:
5555
timings_with_repeats = command_with_repeats.get_raw_timings()
5656
assert timings_with_repeats == [
5757
*expected_raw_timings[:-1],
58-
Timing(high_us=562, low_us=96000),
58+
Timing(high_us=562, low_us=41000),
5959
Timing(high_us=9000, low_us=2250),
6060
Timing(high_us=562, low_us=96000),
6161
Timing(high_us=9000, low_us=2250),
@@ -116,7 +116,7 @@ def test_nec_command_get_raw_timings_extended() -> None:
116116
timings_with_repeats = command_with_repeats.get_raw_timings()
117117
assert timings_with_repeats == [
118118
*expected_raw_timings[:-1],
119-
Timing(high_us=562, low_us=96000),
119+
Timing(high_us=562, low_us=41000),
120120
Timing(high_us=9000, low_us=2250),
121121
Timing(high_us=562, low_us=96000),
122122
Timing(high_us=9000, low_us=2250),

0 commit comments

Comments
 (0)