@@ -155,22 +155,43 @@ public static async ValueTask StartCodeAsync(Commands.Code code)
155
155
// Deal with priority codes
156
156
if ( code . Flags . HasFlag ( CodeFlags . IsPrioritized ) )
157
157
{
158
- // Check if the code has to be moved to another channel first
158
+ // Process this priority code here if it is idle
159
159
if ( processor . IsIdle ( code ) )
160
160
{
161
161
await processor . WriteCodeAsync ( code , stage ) ;
162
162
return ;
163
163
}
164
164
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)
166
186
for ( int input = 0 ; input < Inputs . Total ; input ++ )
167
187
{
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 )
169
190
{
170
191
ChannelProcessor next = _processors [ input ] ;
171
192
if ( next . IsIdle ( code ) )
172
193
{
173
- code . Channel = ( CodeChannel ) input ;
194
+ code . Channel = channel ;
174
195
await next . WriteCodeAsync ( code , stage ) ;
175
196
return ;
176
197
}
0 commit comments