Skip to content

Commit

Permalink
Changed priority code implementation
Browse files Browse the repository at this point in the history
Prioritize M292 to allow custom codes that create blocking message boxes
Priority codes are preferrably sent to idle channels with the same firmware emulation
  • Loading branch information
chrishamm committed Oct 18, 2024
1 parent a8b990e commit 2827e35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
29 changes: 25 additions & 4 deletions src/DuetControlServer/Codes/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,43 @@ public static async ValueTask StartCodeAsync(Commands.Code code)
// Deal with priority codes
if (code.Flags.HasFlag(CodeFlags.IsPrioritized))
{
// Check if the code has to be moved to another channel first
// Process this priority code here if it is idle
if (processor.IsIdle(code))
{
await processor.WriteCodeAsync(code, stage);
return;
}

// Move priority codes to an empty code channel (if possible)
// Otherwise move it to another idle code channel with the same emulation type (if possible)
using (await Model.Provider.AccessReadOnlyAsync())
{
Compatibility compatibility = Model.Provider.Get.Inputs[code.Channel]?.Compatibility ?? Compatibility.RepRapFirmware;
for (int input = 0; input < Inputs.Total; input++)
{
CodeChannel channel = (CodeChannel)input;
if (channel != code.Channel && channel is not CodeChannel.File and not CodeChannel.File2)
{
ChannelProcessor next = _processors[input];
if (Model.Provider.Get.Inputs[channel]?.Compatibility == compatibility && next.IsIdle(code))
{
code.Channel = channel;
await next.WriteCodeAsync(code, stage); // This can't block if the channel is idle
return;
}
}
}
}

// Otherwise move it to an arbitrary idle code channel (if possible)
for (int input = 0; input < Inputs.Total; input++)
{
if ((CodeChannel)input != code.Channel)
CodeChannel channel = (CodeChannel)input;
if (channel != code.Channel && channel is not CodeChannel.File and not CodeChannel.File2)
{
ChannelProcessor next = _processors[input];
if (next.IsIdle(code))
{
code.Channel = (CodeChannel)input;
code.Channel = channel;
await next.WriteCodeAsync(code, stage);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DuetControlServer/Commands/Generic/SimpleCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public override async Task<string> Execute()
code.Flags |= CodeFlags.Asynchronous;
}

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

0 comments on commit 2827e35

Please sign in to comment.