Skip to content

Commit

Permalink
Fixed to resurrect.g contents
Browse files Browse the repository at this point in the history
- Don't include object names in M486 commands if they are empty
- Each motion system restores its own current object number
- Restore M204 settings
- Fixed a formatting error
  • Loading branch information
dc42 committed Apr 7, 2024
1 parent 3069f2d commit 657b157
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 35 deletions.
69 changes: 44 additions & 25 deletions src/GCodes/GCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,12 +1420,14 @@ void GCodes::SaveResumeInfo(bool wasPowerFailure) noexcept
// 'buf' is a convenient 256-byte buffer we can use
bool GCodes::SaveMoveStateResumeInfo(const MovementState& ms, FileStore * const f, const char *printingFilename, const StringRef& buf) noexcept
{
const RestorePoint& pauseRestorePoint = ms.GetPauseRestorePoint();
// Write the current printing object
buf.printf("M486 S%d\n", ms.currentObjectNumber);
bool ok = f->Write(buf.c_str());


// Now that we have homed, we can run the tool change files for the current tool
bool ok = true;
const int toolNumber = ms.GetCurrentToolNumber();
if (toolNumber >= 0)
if (ok && toolNumber >= 0)
{
buf.printf("T%d\n", toolNumber); // select the required tool
if (ms.currentTool->GetSpindleNumber() >= 0)
Expand Down Expand Up @@ -1489,6 +1491,8 @@ bool GCodes::SaveMoveStateResumeInfo(const MovementState& ms, FileStore * const
(oms.inverseTimeMode) ? "G93" : "G94");
ok = f->Write(buf.c_str()); // write virtual extruder position, absolute/relative extrusion flag, and inverse time mode/normal mode flag
}

const RestorePoint& pauseRestorePoint = ms.GetPauseRestorePoint();
if (ok)
{
const unsigned int selectedPlane = oms.selectedPlane;
Expand All @@ -1510,25 +1514,25 @@ bool GCodes::SaveMoveStateResumeInfo(const MovementState& ms, FileStore * const
buf.cat('\n');
ok = f->Write(buf.c_str()); // write G17/18/19, filename and file position, and if necessary proportion done and initial XY position
}

#if SUPPORT_ASYNC_MOVES
const AxesBitmap ownedAxes = ms.GetAxesAndExtrudersOwned();
if (ok && ownedAxes.IsBitSet(Z_AXIS))
#else
if (ok)
#endif
{
// Build the commands to restore the head position. These assume that we are working in mm.
// Start with a vertical move to 2mm above the final Z position
#if SUPPORT_ASYNC_MOVES
const AxesBitmap ownedAxes = ms.GetAxesAndExtrudersOwned();
if (ownedAxes.IsBitSet(Z_AXIS))
#endif
{
buf.printf("G0 F6000 Z%.3f\n", (double)(pauseRestorePoint.moveCoords[Z_AXIS] + 2.0));
}
#if SUPPORT_ASYNC_MOVES
else
{
buf.Clear();
}
#endif
buf.printf("G0 F6000 Z%.3f\n", (double)(pauseRestorePoint.moveCoords[Z_AXIS] + 2.0));
ok = f->Write(buf.c_str());
}

if (ok)
{
// Now set all the other axes
buf.cat("G0 F6000");
buf.copy("G0 F6000");
bool restoredAxes = false;
for (size_t axis = 0; axis < numVisibleAxes; ++axis)
{
#if SUPPORT_ASYNC_MOVES
Expand Down Expand Up @@ -1556,21 +1560,31 @@ bool GCodes::SaveMoveStateResumeInfo(const MovementState& ms, FileStore * const
if (axis != Z_AXIS)
#endif
{

restoredAxes = true;
buf.catf(" %c%.3f", axisLetters[axis], (double)pauseRestorePoint.moveCoords[axis]);
}
}

// Now move down to the correct Z height
#if SUPPORT_ASYNC_MOVES
if (ownedAxes.IsBitSet(Z_AXIS))
#endif
if (restoredAxes)
{
buf.catf("\nG0 F6000 Z%.3f\n", (double)pauseRestorePoint.moveCoords[Z_AXIS]);
buf.cat('\n');
ok = f->Write(buf.c_str());
}
}

// Now move down to the correct Z height
#if SUPPORT_ASYNC_MOVES
if (ok && ownedAxes.IsBitSet(Z_AXIS))
#else
if (ok)
#endif
{
buf.printf("G0 F6000 Z%.3f\n", (double)pauseRestorePoint.moveCoords[Z_AXIS]);
ok = f->Write(buf.c_str());
}
if (ok)
{
// Set the feed rate
buf.catf("G1 F%.1f", (double)InverseConvertSpeedToMmPerMin(pauseRestorePoint.feedRate));
buf.printf("G1 F%.1f", (double)InverseConvertSpeedToMmPerMin(pauseRestorePoint.feedRate));
#if SUPPORT_LASER
if (machineType == MachineType::laser)
{
Expand All @@ -1587,6 +1601,11 @@ bool GCodes::SaveMoveStateResumeInfo(const MovementState& ms, FileStore * const
ok = f->Write(buf.c_str()); // restore feed rate and output bits or laser power
}
if (ok)
{
buf.printf("M204 P%.1f T%.1f\n", (double)InverseConvertAcceleration(ms.maxPrintingAcceleration), (double)InverseConvertAcceleration(ms.maxTravelAcceleration));
ok = f->Write(buf.c_str()); // restore printing and travel accelerations
}
if (ok)
{
ok = f->Write((oms.usingInches) ? "G20\n" : "G21\n"); // restore inches/mm
}
Expand Down
16 changes: 6 additions & 10 deletions src/GCodes/ObjectTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ bool ObjectTracker::WriteObjectDirectory(FileStore *f) const noexcept
for (size_t i = 0; ok && i < min<unsigned int>(numObjects, MaxTrackedObjects); ++i)
{
String<StringLength100> buf;
buf.printf("M486 S%u A\"%s\"\n", i, objectDirectory[i].name.Get().Ptr());
buf.printf("M486 S%u", i);
if (!objectDirectory[i].name.IsNull())
{
buf.catf(" A\"%s\"", objectDirectory[i].name.Get().Ptr());
}
buf.cat('\n');
ok = f->Write(buf.c_str());
}

Expand All @@ -194,15 +199,6 @@ bool ObjectTracker::WriteObjectDirectory(FileStore *f) const noexcept
return f->Write(buf.c_str());
});
}

// Write the current object
if (ok)
{
String<StringLength20> buf;
buf.printf("M486 S%d\n", reprap.GetGCodes().GetPrimaryMovementState().currentObjectNumber);
ok = f->Write(buf.c_str());
}

return ok;
}

Expand Down

0 comments on commit 657b157

Please sign in to comment.