Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/GCodes')
-rw-r--r--src/GCodes/GCodeBuffer/BinaryParser.cpp2
-rw-r--r--src/GCodes/GCodeBuffer/StringParser.cpp2
-rw-r--r--src/GCodes/GCodeMachineState.h2
-rw-r--r--src/GCodes/GCodes.cpp20
-rw-r--r--src/GCodes/GCodes.h1
-rw-r--r--src/GCodes/GCodes3.cpp34
-rw-r--r--src/GCodes/GCodes4.cpp35
7 files changed, 87 insertions, 9 deletions
diff --git a/src/GCodes/GCodeBuffer/BinaryParser.cpp b/src/GCodes/GCodeBuffer/BinaryParser.cpp
index 954c4e29..b1e8e4fa 100644
--- a/src/GCodes/GCodeBuffer/BinaryParser.cpp
+++ b/src/GCodes/GCodeBuffer/BinaryParser.cpp
@@ -873,7 +873,7 @@ void BinaryParser::AddParameters(VariableSet& vs, int codeRunning) noexcept
if (ev.GetType() != TypeCode::None)
{
char paramName[2] = { param->letter, 0 };
- vs.InsertNew(paramName, ev, -1);
+ vs.InsertNewParameter(paramName, ev);
}
}
diff --git a/src/GCodes/GCodeBuffer/StringParser.cpp b/src/GCodes/GCodeBuffer/StringParser.cpp
index 24a6aaa3..78669752 100644
--- a/src/GCodes/GCodeBuffer/StringParser.cpp
+++ b/src/GCodes/GCodeBuffer/StringParser.cpp
@@ -1914,7 +1914,7 @@ void StringParser::AddParameters(VariableSet& vs, int codeRunning) noexcept
ev.Set(nullptr);
}
char paramName[2] = { letter, 0 };
- vs.InsertNew(paramName, ev, -1);
+ vs.InsertNewParameter(paramName, ev);
}
}
);
diff --git a/src/GCodes/GCodeMachineState.h b/src/GCodes/GCodeMachineState.h
index 3ea86bce..c5ec5bbb 100644
--- a/src/GCodes/GCodeMachineState.h
+++ b/src/GCodes/GCodeMachineState.h
@@ -109,6 +109,8 @@ enum class GCodeState : uint8_t
unloadingFilament,
checkError, // go to this state after doing a macro when we need to check for a stored error message
+ processingEvent,
+ finishedProcessingEvent,
#if HAS_MASS_STORAGE
timingSDwrite,
diff --git a/src/GCodes/GCodes.cpp b/src/GCodes/GCodes.cpp
index 902c0ac0..01291c3f 100644
--- a/src/GCodes/GCodes.cpp
+++ b/src/GCodes/GCodes.cpp
@@ -34,6 +34,7 @@
#include <PrintMonitor/PrintMonitor.h>
#include <Platform/RepRap.h>
#include <Platform/Tasks.h>
+#include <Platform/Event.h>
#include <Tools/Tool.h>
#include <Endstops/ZProbe.h>
#include <ObjectModel/Variable.h>
@@ -573,6 +574,13 @@ bool GCodes::StartNextGCode(GCodeBuffer& gb, const StringRef& reply) noexcept
{
return DoFilePrint(gb, reply);
}
+ else if (&gb == autoPauseGCode)
+ {
+ if (Event::StartProcessing())
+ {
+ ProcessEvent(gb); // call out to separate function to avoid increasing stack usage of this function
+ }
+ }
else if (&gb == daemonGCode
#if SUPPORT_REMOTE_COMMANDS
&& !CanInterface::InExpansionMode() // looking for the daemon.g file increases the loop time too much
@@ -967,8 +975,8 @@ void GCodes::DoPause(GCodeBuffer& gb, PauseReason reason, const char *msg, uint1
FileData& fdata = fileGCode->LatestMachineState().fileState;
if (fdata.IsLive())
{
- fileGCode->RestartFrom(pauseRestorePoint.filePos); // TODO we ought to restore the line number too, but currently we don't save it
- UnlockAll(*fileGCode); // release any locks it had
+ fileGCode->RestartFrom(pauseRestorePoint.filePos); // TODO we ought to restore the line number too, but currently we don't save it
+ UnlockAll(*fileGCode); // release any locks it had
}
}
#endif
@@ -1317,7 +1325,7 @@ bool GCodes::ReHomeOnStall(DriversBitmap stalledDrivers) noexcept
if (cfg.driverNumbers[i].IsLocal() && stalledDrivers.IsBitSet(cfg.driverNumbers[i].localDriver))
{
char str[2] = { axisLetters[axis], 0 };
- vars.InsertNew(str, ExpressionValue((int32_t)1), -1); // create a parameter with value 1 for the axis
+ vars.InsertNewParameter(str, ExpressionValue((int32_t)1)); // create a parameter with value 1 for the axis
break;
}
}
@@ -3357,7 +3365,7 @@ GCodeResult GCodes::DoDwell(GCodeBuffer& gb) THROWS(GCodeException)
}
#endif
- if ( IsSimulating() // if we are simulating then simulate the G4...
+ if ( IsSimulating() // if we are simulating then simulate the G4...
&& &gb != daemonGCode // ...unless it comes from the daemon...
&& &gb != triggerGCode // ...or a trigger...
&& (&gb == fileGCode || !exitSimulationWhenFileComplete) // ...or we are simulating a file and this command doesn't come from the file
@@ -4689,7 +4697,7 @@ void GCodes::CheckReportDue(GCodeBuffer& gb, const StringRef& reply) const noexc
// Send a standard status response for PanelDue
OutputBuffer * const statusBuf =
(lastAuxStatusReportType == ObjectModelAuxStatusReportType) // PanelDueFirmware v3.2 or later, using M409 to retrieve object model
- ? reprap.GetModelResponse("", "d99f")
+ ? reprap.GetModelResponse("", "d99fi")
: GenerateJsonStatusResponse(lastAuxStatusReportType, -1, ResponseSource::AUX); // older PanelDueFirmware using M408
if (statusBuf != nullptr)
{
@@ -4891,7 +4899,7 @@ void GCodes::HandleHeaterFault() noexcept
}
}
-// Check for and respond to a heater fault, returning true if we should exit
+// Check for and respond to a heater fault
void GCodes::CheckHeaterFault() noexcept
{
switch (heaterFaultState)
diff --git a/src/GCodes/GCodes.h b/src/GCodes/GCodes.h
index e504f742..3cbddcaa 100644
--- a/src/GCodes/GCodes.h
+++ b/src/GCodes/GCodes.h
@@ -462,6 +462,7 @@ private:
void DoPause(GCodeBuffer& gb, PauseReason reason, const char *msg, uint16_t param = 0) noexcept // Pause the print
pre(resourceOwners[movementResource] == &gb);
void CheckForDeferredPause(GCodeBuffer& gb) noexcept; // Check if a pause is pending, action it if so
+ void ProcessEvent(GCodeBuffer& gb) noexcept; // Start processing a new event
#if HAS_VOLTAGE_MONITOR || HAS_SMART_DRIVERS
bool DoEmergencyPause() noexcept; // Do an emergency pause following loss of power or a motor stall
diff --git a/src/GCodes/GCodes3.cpp b/src/GCodes/GCodes3.cpp
index 0a13640b..f321cf0d 100644
--- a/src/GCodes/GCodes3.cpp
+++ b/src/GCodes/GCodes3.cpp
@@ -12,6 +12,7 @@
#include <Heating/Heat.h>
#include <Movement/Move.h>
#include <Platform/RepRap.h>
+#include <Platform/Event.h>
#include <Tools/Tool.h>
#include <Endstops/ZProbe.h>
#include <PrintMonitor/PrintMonitor.h>
@@ -1863,6 +1864,37 @@ bool GCodes::ProcessWholeLineComment(GCodeBuffer& gb, const StringRef& reply) TH
return true;
}
+// Process and event. The autoPauseGCode buffer calls this when there is a new event to be processed.
+// This is a separate function because it allocates strings on the stack.
+void GCodes::ProcessEvent(GCodeBuffer& gb) noexcept
+{
+ // Get the event message
+ String<StringLength100> eventText;
+ const MessageType mt = Event::GetTextDescription(eventText.GetRef());
+ platform.Message(mt, eventText.c_str()); // tell the user about the event and log it
+
+ // Get the name of the macro file that we should look for
+ String<StringLength50> macroName;
+ Event::GetMacroFileName(macroName.GetRef());
+ if (platform.SysFileExists(macroName.c_str()))
+ {
+ // Set up the macro parameters
+ VariableSet vars;
+ Event::GetParameters(vars);
+ vars.InsertNewParameter("S", ExpressionValue(StringHandle(eventText.c_str())));
+
+ // Run the macro
+ gb.SetState(GCodeState::finishedProcessingEvent); // cancel the event when we have finished processing it
+ if (DoFileMacro(gb, macroName.c_str(), false, AsyncSystemMacroCode, vars))
+ {
+ return;
+ }
+ }
+
+ // We didn't execute the macro, so do the default action. It may need to wait for the movement lock, so do it in a new state.
+ gb.SetState(GCodeState::processingEvent);
+}
+
#if !HAS_MASS_STORAGE && !HAS_EMBEDDED_FILES && defined(DUET_NG)
// Function called by RepRap.cpp to enable PanelDue by default in the Duet 2 SBC build
@@ -1873,4 +1905,4 @@ void GCodes::SetAux0CommsProperties(uint32_t mode) const noexcept
#endif
- // End
+// End
diff --git a/src/GCodes/GCodes4.cpp b/src/GCodes/GCodes4.cpp
index f2ccb6b5..961728f9 100644
--- a/src/GCodes/GCodes4.cpp
+++ b/src/GCodes/GCodes4.cpp
@@ -3,6 +3,7 @@
#include "GCodes.h"
#include "GCodeBuffer/GCodeBuffer.h"
#include <Platform/RepRap.h>
+#include <Platform/Event.h>
#include <Movement/Move.h>
#include <Tools/Tool.h>
#include <Heating/Heat.h>
@@ -1482,6 +1483,40 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
gb.SetState(GCodeState::normal);
break;
+ // Here when we need to execute the default action for an event because the macro file was not found. We have already sent a message and logged the event.
+ case GCodeState::processingEvent:
+ {
+ const Event::DefaultAction action = Event::GetDefaultAction();
+ if (action == Event::DefaultAction::none)
+ {
+ // Nothing more to do
+ gb.SetState(GCodeState::finishedProcessingEvent);
+ }
+ else
+ {
+ // We are going to pause
+ if (pauseState != PauseState::resuming) // if we are resuming, wait for the resume to complete
+ {
+ if (pauseState != PauseState::notPaused)
+ {
+ gb.SetState(GCodeState::finishedProcessingEvent); // already paused
+ }
+ else if (LockMovementAndWaitForStandstill(gb))
+ {
+ gb.SetState(GCodeState::finishedProcessingEvent);
+ DoPause(gb, qq);
+ }
+ }
+ }
+ }
+ break;
+
+ // Here when we have finished processing an event
+ case GCodeState::finishedProcessingEvent:
+ Event::FinishedProcessing();
+ gb.SetState(GCodeState::normal);
+ break;
+
default: // should not happen
gb.LatestMachineState().SetError("Undefined GCodeState");
gb.SetState(GCodeState::normal);