Process an 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.
| 1309 | // Process an event. The autoPauseGCode buffer calls this when there is a new event to be processed. |
| 1310 | // This is a separate function because it allocates strings on the stack. |
| 1311 | void GCodes::ProcessEvent(GCodeBuffer& gb) noexcept |
| 1312 | { |
| 1313 | // Get the event message |
| 1314 | String<StringLength100> eventText; |
| 1315 | const MessageType mt = Event::GetTextDescription(eventText.GetRef()); |
| 1316 | |
| 1317 | // Get the name of the macro file that we should look for |
| 1318 | String<StringLength50> macroName; |
| 1319 | Event::GetMacroFileName(macroName.GetRef()); |
| 1320 | |
| 1321 | #if HAS_MASS_STORAGE || HAS_SBC_INTERFACE || HAS_EMBEDDED_FILES |
| 1322 | if (platform.SysFileExists(macroName.c_str())) |
| 1323 | { |
| 1324 | // Set up the macro parameters |
| 1325 | VariableSet vars; |
| 1326 | Event::GetParameters(vars); |
| 1327 | try |
| 1328 | { |
| 1329 | vars.InsertNewParameter("S", ExpressionValue(StringHandle(eventText.c_str()))); |
| 1330 | } |
| 1331 | catch (const GCodeException&) { } |
| 1332 | |
| 1333 | // Run the macro |
| 1334 | gb.SetState(GCodeState::finishedProcessingEvent); // cancel the event when we have finished processing it |
| 1335 | if (DoFileMacro(gb, macroName.c_str(), false, AsyncSystemMacroCode, vars)) |
| 1336 | { |
| 1337 | return; |
| 1338 | } |
| 1339 | } |
| 1340 | #endif |
| 1341 | |
| 1342 | // We didn't execute the macro, so do the default action |
| 1343 | if (Event::GetDefaultPauseReason() == PrintPausedReason::dontPause) |
| 1344 | { |
| 1345 | platform.MessageF(mt, "%s\n", eventText.c_str()); // record the event on the console and log it |
| 1346 | Event::FinishedProcessing(); // nothing more to do |
| 1347 | } |
| 1348 | else |
| 1349 | { |
| 1350 | // It's a serious event that causes the print to pause by default, so send an alert |
| 1351 | if ((mt & LogLevelMask) != 0) |
| 1352 | { |
| 1353 | platform.MessageF((MessageType)(mt & (LogLevelMask | ErrorMessageFlag | WarningMessageFlag)), "%s\n", eventText.c_str()); // log the event |
| 1354 | } |
| 1355 | const bool isPrinting = IsReallyPrinting(); |
| 1356 | reprap.SendSimpleAlert(GenericMessage, eventText.c_str(), (isPrinting) ? "Printing paused" : "Event notification"); |
| 1357 | if (IsReallyPrinting()) |
| 1358 | { |
| 1359 | // We are going to pause. It may need to wait for the movement lock, so do it in a new state. |
| 1360 | gb.SetState(GCodeState::processingEvent); |
| 1361 | } |
| 1362 | else |
| 1363 | { |
| 1364 | Event::FinishedProcessing(); |
| 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 |
nothing calls this directly
no test coverage detected