Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.3-dev' into wil-extend-m111
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Coenen committed Mar 10, 2021
2 parents 2cef720 + 2dab154 commit b762535
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
31 changes: 17 additions & 14 deletions src/GCodes/GCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ FilePosition GCodes::GetFilePosition() const noexcept
// Start running the config file
bool GCodes::RunConfigFile(const char* fileName) noexcept
{
runningConfigFile = DoFileMacro(*triggerGCode, fileName, false, SystemMacroCode);
runningConfigFile = DoFileMacro(*triggerGCode, fileName, false, AsyncSystemMacroCode);
return runningConfigFile;
}

Expand Down Expand Up @@ -542,7 +542,9 @@ bool GCodes::SpinGCodeBuffer(GCodeBuffer& gb) noexcept
result = true; // assume we did something useful (not necessarily true, e.g. could be waiting for movement to stop)
}

if (gb.IsExecuting() || (isWaiting && !cancelWait))
if ( gb.IsExecuting()
|| (isWaiting && !cancelWait) // this is needed to get reports sent during M109 commands
)
{
CheckReportDue(gb, reply.GetRef());
}
Expand Down Expand Up @@ -579,7 +581,7 @@ bool GCodes::StartNextGCode(GCodeBuffer& gb, const StringRef& reply) noexcept
&& gb.DoDwellTime(1000)
)
{
return DoFileMacro(gb, DAEMON_G, false, SystemMacroCode);
return DoFileMacro(gb, DAEMON_G, false, AsyncSystemMacroCode);
}
}
else
Expand Down Expand Up @@ -855,7 +857,7 @@ void GCodes::CheckTriggers() noexcept
triggersPending.ClearBit(lowestTriggerPending); // clear the trigger
String<StringLength20> filename;
filename.printf("trigger%u.g", lowestTriggerPending);
DoFileMacro(*triggerGCode, filename.c_str(), true, SystemMacroCode);
DoFileMacro(*triggerGCode, filename.c_str(), true, AsyncSystemMacroCode);
}
}
}
Expand Down Expand Up @@ -1300,9 +1302,9 @@ bool GCodes::ReHomeOnStall(DriversBitmap stalledDrivers) noexcept
// Now pass the machine axes to the rehome.g file
// TODO

autoPauseGCode->SetState(GCodeState::resuming1); // set up to resume after rehoming
autoPauseGCode->SetState(GCodeState::resuming1); // set up to resume after rehoming
pauseState = PauseState::resuming;
DoFileMacro(*autoPauseGCode, REHOME_G, true, SystemMacroCode); // run the SD card rehome-and-resume script
DoFileMacro(*autoPauseGCode, REHOME_G, true, AsyncSystemMacroCode); // run the SD card rehome-and-resume script
return true;
}

Expand Down Expand Up @@ -2694,13 +2696,13 @@ bool GCodes::DoFileMacro(GCodeBuffer& gb, const char* fileName, bool reportMissi
#if HAS_LINUX_INTERFACE
if (reprap.UsingLinuxInterface())
{
if (!gb.RequestMacroFile(fileName, gb.IsBinary() && codeRunning >= 0))
if (!gb.RequestMacroFile(fileName, gb.IsBinary() && codeRunning != AsyncSystemMacroCode))
{
if (reportMissing)
{
MessageType mt = (gb.IsBinary() && codeRunning != SystemMacroCode)
? (MessageType)(gb.GetResponseMessageType() | WarningMessageFlag | PushFlag)
: WarningMessage;
MessageType mt = (gb.IsBinary() && codeRunning != SystemHelperMacroCode)
? (MessageType)(gb.GetResponseMessageType() | WarningMessageFlag | PushFlag)
: WarningMessage;
platform.MessageF(mt, "Macro file %s not found\n", fileName);
return true;
}
Expand Down Expand Up @@ -2759,7 +2761,8 @@ bool GCodes::DoFileMacro(GCodeBuffer& gb, const char* fileName, bool reportMissi
gb.LatestMachineState().doingFileMacro = true;
gb.LatestMachineState().runningM501 = (codeRunning == 501);
gb.LatestMachineState().runningM502 = (codeRunning == 502);
gb.LatestMachineState().runningSystemMacro = (codeRunning == SystemMacroCode || codeRunning == 29 || codeRunning == 32); // running a system macro e.g. homing or tool change, so don't use workplace coordinates
gb.LatestMachineState().runningSystemMacro = (codeRunning == SystemHelperMacroCode || codeRunning == AsyncSystemMacroCode || codeRunning == 29 || codeRunning == 32);
// running a system macro e.g. homing, so don't use workplace coordinates
gb.SetState(GCodeState::normal);
gb.Init();
return true;
Expand Down Expand Up @@ -3209,7 +3212,7 @@ void GCodes::StartPrinting(bool fromStart) noexcept
if (fromStart)
{
// Get the fileGCode to execute the start macro so that any M82/M83 codes will be executed in the correct context
DoFileMacro(*fileGCode, START_G, false, SystemMacroCode);
DoFileMacro(*fileGCode, START_G, false, AsyncSystemMacroCode);
}
}

Expand Down Expand Up @@ -3920,7 +3923,7 @@ GCodeResult GCodes::LoadFilament(GCodeBuffer& gb, const StringRef& reply)

String<StringLength256> scratchString;
scratchString.printf("%s%s/%s", FILAMENTS_DIRECTORY, filamentName.c_str(), LOAD_FILAMENT_G);
DoFileMacro(gb, scratchString.c_str(), true, SystemMacroCode);
DoFileMacro(gb, scratchString.c_str(), true, SystemHelperMacroCode);
}
else if (tool->GetFilament()->IsLoaded())
{
Expand Down Expand Up @@ -3954,7 +3957,7 @@ GCodeResult GCodes::UnloadFilament(GCodeBuffer& gb, const StringRef& reply)
gb.SetState(GCodeState::unloadingFilament);
String<StringLength256> scratchString;
scratchString.printf("%s%s/%s", FILAMENTS_DIRECTORY, tool->GetFilament()->GetName(), UNLOAD_FILAMENT_G);
DoFileMacro(gb, scratchString.c_str(), true, SystemMacroCode);
DoFileMacro(gb, scratchString.c_str(), true, SystemHelperMacroCode);
}
return GCodeResult::ok;
}
Expand Down
6 changes: 4 additions & 2 deletions src/GCodes/GCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,10 @@ class GCodes

static_assert(NumResources <= sizeof(Resource) * CHAR_BIT, "Too many resources to keep a bitmap of them in class GCodeMachineState");

static constexpr int ToolChangeMacroCode = -1;
static constexpr int SystemMacroCode = -2;
// Codes passed to DoFileMacro
static constexpr int ToolChangeMacroCode = -1; // A macro that is being called because of a tool change
static constexpr int SystemHelperMacroCode = -2; // Another system macro that is being called to help execute the current command
static constexpr int AsyncSystemMacroCode = -3; // A macro that is not being executed as part of a commend being executed, e.g. due to a trigger, filament out etc.

bool LockResource(const GCodeBuffer& gb, Resource r) noexcept; // Lock the resource, returning true if success
bool LockFileSystem(const GCodeBuffer& gb) noexcept; // Lock the unshareable parts of the file system
Expand Down
10 changes: 5 additions & 5 deletions src/GCodes/GCodes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,14 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
if (!wasSimulating) // don't run any macro files or turn heaters off etc. if we were simulating before we stopped the print
{
// If we are cancelling a paused print with M0 and we are homed and cancel.g exists then run it and do nothing else
if (oldPauseState != PauseState::notPaused && code == 0 && AllAxesAreHomed() && DoFileMacro(gb, CANCEL_G, false, SystemMacroCode))
if (oldPauseState != PauseState::notPaused && code == 0 && AllAxesAreHomed() && DoFileMacro(gb, CANCEL_G, false, SystemHelperMacroCode))
{
break;
}

const bool leaveHeatersOn = (gb.Seen('H') && gb.GetIValue() > 0);
gb.SetState((leaveHeatersOn) ? GCodeState::stoppingWithHeatersOn : GCodeState::stoppingWithHeatersOff);
(void)DoFileMacro(gb, (code == 0) ? STOP_G : SLEEP_G, false, SystemMacroCode);
(void)DoFileMacro(gb, (code == 0) ? STOP_G : SLEEP_G, false, SystemHelperMacroCode);
}
}
break;
Expand Down Expand Up @@ -944,7 +944,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
gb.SetState(GCodeState::resuming1);
if (AllAxesAreHomed())
{
DoFileMacro(gb, RESUME_G, true, SystemMacroCode);
DoFileMacro(gb, RESUME_G, true, SystemHelperMacroCode);
}
}
}
Expand Down Expand Up @@ -4120,7 +4120,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
{
String<StringLength256> scratchString;
scratchString.printf("%s%s/%s", FILAMENTS_DIRECTORY, filament->GetName(), CONFIG_FILAMENT_G);
DoFileMacro(gb, scratchString.c_str(), false, SystemMacroCode);
DoFileMacro(gb, scratchString.c_str(), false, SystemHelperMacroCode);
}
}
else
Expand Down Expand Up @@ -4479,7 +4479,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
}
else
{
DoFileMacro(gb, RESUME_AFTER_POWER_FAIL_G, true, SystemMacroCode);
DoFileMacro(gb, RESUME_AFTER_POWER_FAIL_G, true, SystemHelperMacroCode);
}
break;
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/GCodes/GCodes3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,9 +1573,9 @@ void GCodes::DeployZProbe(GCodeBuffer& gb) noexcept
{
String<StringLength20> fileName;
fileName.printf(DEPLOYPROBE "%u.g", currentZProbeNumber);
if (!DoFileMacro(gb, fileName.c_str(), false, SystemMacroCode))
if (!DoFileMacro(gb, fileName.c_str(), false, SystemHelperMacroCode))
{
DoFileMacro(gb, DEPLOYPROBE ".g", false, SystemMacroCode);
DoFileMacro(gb, DEPLOYPROBE ".g", false, SystemHelperMacroCode);
}
}
}
Expand All @@ -1589,9 +1589,9 @@ void GCodes::RetractZProbe(GCodeBuffer& gb) noexcept
{
String<StringLength20> fileName;
fileName.printf(RETRACTPROBE "%u.g", currentZProbeNumber);
if (!DoFileMacro(gb, fileName.c_str(), false, SystemMacroCode))
if (!DoFileMacro(gb, fileName.c_str(), false, SystemHelperMacroCode))
{
DoFileMacro(gb, RETRACTPROBE ".g", false, SystemMacroCode);
DoFileMacro(gb, RETRACTPROBE ".g", false, SystemHelperMacroCode);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/GCodes/GCodes4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
gb.AdvanceState();
if (AllAxesAreHomed())
{
DoFileMacro(gb, PAUSE_G, true, SystemMacroCode);
DoFileMacro(gb, PAUSE_G, true, SystemHelperMacroCode);
}
}
break;
Expand All @@ -376,9 +376,9 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
gb.AdvanceState();
if (AllAxesAreHomed())
{
if (!DoFileMacro(gb, FILAMENT_CHANGE_G, false, SystemMacroCode))
if (!DoFileMacro(gb, FILAMENT_CHANGE_G, false, AsyncSystemMacroCode))
{
DoFileMacro(gb, PAUSE_G, true, SystemMacroCode);
DoFileMacro(gb, PAUSE_G, true, AsyncSystemMacroCode);
}
}
}
Expand All @@ -392,11 +392,11 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
{
String<StringLength20> macroName;
macroName.printf(FILAMENT_ERROR "%u.g", gb.LatestMachineState().stateParameter);
if (!DoFileMacro(gb, macroName.c_str(), false, SystemMacroCode))
if (!DoFileMacro(gb, macroName.c_str(), false, AsyncSystemMacroCode))
{
if (!DoFileMacro(gb, FILAMENT_ERROR ".g", false, SystemMacroCode))
if (!DoFileMacro(gb, FILAMENT_ERROR ".g", false, AsyncSystemMacroCode))
{
DoFileMacro(gb, PAUSE_G, true, SystemMacroCode);
DoFileMacro(gb, PAUSE_G, true, AsyncSystemMacroCode);
}
}
}
Expand Down

0 comments on commit b762535

Please sign in to comment.