Skip to content

Commit 2827e35

Browse files
committed
Changed priority code implementation
Prioritize M292 to allow custom codes that create blocking message boxes Priority codes are preferrably sent to idle channels with the same firmware emulation
1 parent a8b990e commit 2827e35

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/DuetControlServer/Codes/Processor.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,43 @@ public static async ValueTask StartCodeAsync(Commands.Code code)
155155
// Deal with priority codes
156156
if (code.Flags.HasFlag(CodeFlags.IsPrioritized))
157157
{
158-
// Check if the code has to be moved to another channel first
158+
// Process this priority code here if it is idle
159159
if (processor.IsIdle(code))
160160
{
161161
await processor.WriteCodeAsync(code, stage);
162162
return;
163163
}
164164

165-
// Move priority codes to an empty code channel (if possible)
165+
// Otherwise move it to another idle code channel with the same emulation type (if possible)
166+
using (await Model.Provider.AccessReadOnlyAsync())
167+
{
168+
Compatibility compatibility = Model.Provider.Get.Inputs[code.Channel]?.Compatibility ?? Compatibility.RepRapFirmware;
169+
for (int input = 0; input < Inputs.Total; input++)
170+
{
171+
CodeChannel channel = (CodeChannel)input;
172+
if (channel != code.Channel && channel is not CodeChannel.File and not CodeChannel.File2)
173+
{
174+
ChannelProcessor next = _processors[input];
175+
if (Model.Provider.Get.Inputs[channel]?.Compatibility == compatibility && next.IsIdle(code))
176+
{
177+
code.Channel = channel;
178+
await next.WriteCodeAsync(code, stage); // This can't block if the channel is idle
179+
return;
180+
}
181+
}
182+
}
183+
}
184+
185+
// Otherwise move it to an arbitrary idle code channel (if possible)
166186
for (int input = 0; input < Inputs.Total; input++)
167187
{
168-
if ((CodeChannel)input != code.Channel)
188+
CodeChannel channel = (CodeChannel)input;
189+
if (channel != code.Channel && channel is not CodeChannel.File and not CodeChannel.File2)
169190
{
170191
ChannelProcessor next = _processors[input];
171192
if (next.IsIdle(code))
172193
{
173-
code.Channel = (CodeChannel)input;
194+
code.Channel = channel;
174195
await next.WriteCodeAsync(code, stage);
175196
return;
176197
}

src/DuetControlServer/Commands/Generic/SimpleCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public override async Task<string> Execute()
9191
code.Flags |= CodeFlags.Asynchronous;
9292
}
9393

94-
// M108, M112, M122, and M999 (B0) always go to an idle channel so we (hopefully) get a low-latency response
94+
// M108, M112, M122, M292, and M999 (B0) always go to an idle channel so we (hopefully) get a low-latency response
9595
if (code.Type == CodeType.MCode &&
96-
(code.MajorNumber == 108 || code.MajorNumber == 112 || code.MajorNumber == 122 || (code.MajorNumber == 999 && code.GetInt('B', 0) == 0)))
96+
(code.MajorNumber is 108 or 112 or 122 or 292 || (code.MajorNumber == 999 && code.GetInt('B', 0) == 0)))
9797
{
9898
code.Flags |= CodeFlags.IsPrioritized;
9999
priorityCodes.Add(code);

0 commit comments

Comments
 (0)