Quote Originally Posted by AbuMaia View Post
I do have a problem of the M600 being sent 4 times, even with the "G4 P0" listed in that post. I haven't yet figured out how to fix it.
There are a number of approaches to do this 'Right'. By jamming commands into the serial buffer for the firmware to execute they gave up a lot of control, but it was a very quick and dirty way to get results.

One of the big flaws in how they did it is they have no idea how much buffer space is available for commands when the switch gets triggered. For starters, the buffer management routines should be rewritten to address the situation where there isn't enough room to jam more commands in the buffer.

But really... I would be very tempted to duplicate the M600 command as a stand alone routine that could be called when a condition is detected. Then it would not be very difficult in the main loop to check prior to executing any command if the filament needs to be changed. If so... You call the new (duplicate) routine and don't have to mess with the GCode command buffer.