Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/v3.02-dev' into v3.02-dev-unified
Browse files Browse the repository at this point in the history
  • Loading branch information
gloomyandy committed Nov 13, 2020
2 parents 4f674fb + 18ccfda commit 7ccfaf4
Show file tree
Hide file tree
Showing 39 changed files with 757 additions and 721 deletions.
293 changes: 50 additions & 243 deletions .cproject

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ constexpr uint32_t DefaultHeaterFaultTimeout = 10 * 60 * 1000; // How long we wa

// Heating model default parameters. For the chamber heater, we use the same values as for the bed heater.
// These parameters are about right for an E3Dv6 hot end with 30W heater.
constexpr float DefaultHotEndHeaterGain = 340.0;
constexpr float DefaultHotEndHeaterTimeConstant = 140.0;
constexpr float DefaultHotEndHeaterDeadTime = 5.5;
constexpr float DefaultHotEndHeaterCoolingRate = 1.0/140.0; // E3D V6 has a cooling time constant of about 140 seconds with the fan off
constexpr float DefaultHotEndHeaterHeatingRate = 340.0 * DefaultHotEndHeaterCoolingRate;
constexpr float DefaultHotEndHeaterDeadTime = 5.5; // E3D v6

constexpr unsigned int FirstExtraHeaterProtection = 100; // Index of the first extra heater protection item

Expand Down
26 changes: 23 additions & 3 deletions src/Fans/FansManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,30 @@ GCodeResult FansManager::SetFanValue(size_t fanNum, float speed, const StringRef
return GCodeResult::error;
}

void FansManager::SetFanValue(size_t fanNum, float speed) noexcept
// Update the PWM of the specified fan, returning the PWM change
float FansManager::SetFanValue(size_t fanNum, float speed) noexcept
{
String<1> dummy;
(void)SetFanValue(fanNum, speed, dummy.GetRef());
auto fan = FindFan(fanNum);
if (fan.IsNotNull())
{
const float oldPwm = fan->GetPwm();
String<1> dummy;
(void)fan->SetPwm(speed, dummy.GetRef());
return fan->GetPwm() - oldPwm;
}
return 0.0;
}

// Update the PWM of the specified fans, returning the total PWM change divided by the number of fans
float FansManager::SetFansValue(FansBitmap whichFans, float speed) noexcept
{
float pwmChange = 0;
if (!whichFans.IsEmpty())
{
whichFans.Iterate([speed, this, &pwmChange](unsigned int i, unsigned int) noexcept { pwmChange += SetFanValue(i, speed); });
pwmChange /= whichFans.CountSetBits();
}
return pwmChange;
}

// Check if the given fan can be controlled manually so that DWC can decide whether or not to show the corresponding fan
Expand Down
3 changes: 2 additions & 1 deletion src/Fans/FansManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class FansManager
bool ConfigureFan(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error) THROWS(GCodeException);
float GetFanValue(size_t fanNum) const noexcept;
GCodeResult SetFanValue(size_t fanNum, float speed, const StringRef& reply) noexcept;
void SetFanValue(size_t fanNum, float speed) noexcept;
float SetFanValue(size_t fanNum, float speed) noexcept;
float SetFansValue(FansBitmap whichFans, float speed) noexcept;
bool IsFanControllable(size_t fanNum) const noexcept;
const char *GetFanName(size_t fanNum) const noexcept;
int32_t GetFanRPM(size_t fanNum) const noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentMonitors/FilamentMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void FilamentMonitor::Disable() noexcept
// Try to get the pin number from the GCode command in the buffer, setting Seen if a pin number was provided and returning true if error.
// Also attaches the ISR.
// For a remote filament monitor, this does the full configuration or query of the remote object instead, and we always return seen true because we don't need to report local status.
GCodeResult FilamentMonitor::CommonConfigure(GCodeBuffer& gb, const StringRef& reply, InterruptMode interruptMode, bool& seen) noexcept
GCodeResult FilamentMonitor::CommonConfigure(GCodeBuffer& gb, const StringRef& reply, InterruptMode interruptMode, bool& seen) THROWS(GCodeException)
{
#if SUPPORT_CAN_EXPANSION
// Check that the port (if given) is on the same board as the extruder
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentMonitors/FilamentMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class FilamentMonitor INHERIT_OBJECT_MODEL
protected:
FilamentMonitor(unsigned int extruder, unsigned int t) noexcept;

GCodeResult CommonConfigure(GCodeBuffer& gb, const StringRef& reply, InterruptMode interruptMode, bool& seen) noexcept;
GCodeResult CommonConfigure(GCodeBuffer& gb, const StringRef& reply, InterruptMode interruptMode, bool& seen) THROWS(GCodeException);

const IoPort& GetPort() const noexcept { return port; }
bool HaveIsrStepsCommanded() const noexcept { return haveIsrStepsCommanded; }
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentMonitors/LaserFilamentMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ float LaserFilamentMonitor::MeasuredSensitivity() const noexcept
}

// Configure this sensor, returning true if error and setting 'seen' if we processed any configuration parameters
GCodeResult LaserFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen)
GCodeResult LaserFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) THROWS(GCodeException)
{
const GCodeResult rslt = CommonConfigure(gb, reply, INTERRUPT_MODE_CHANGE, seen);
if (rslt <= GCodeResult::warning)
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentMonitors/PulsedFilamentMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ float PulsedFilamentMonitor::MeasuredSensitivity() const noexcept
}

// Configure this sensor, returning true if error and setting 'seen' if we processed any configuration parameters
GCodeResult PulsedFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen)
GCodeResult PulsedFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) THROWS(GCodeException)
{
const GCodeResult rslt = CommonConfigure(gb, reply, INTERRUPT_MODE_RISING, seen);
if (rslt <= GCodeResult::warning)
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ float RotatingMagnetFilamentMonitor::MeasuredSensitivity() const noexcept
}

// Configure this sensor, returning true if error and setting 'seen' if we processed any configuration parameters
GCodeResult RotatingMagnetFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen)
GCodeResult RotatingMagnetFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) THROWS(GCodeException)
{
const GCodeResult rslt = CommonConfigure(gb, reply, INTERRUPT_MODE_CHANGE, seen);
if (rslt <= GCodeResult::warning)
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentMonitors/SimpleFilamentMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SimpleFilamentMonitor::SimpleFilamentMonitor(unsigned int extruder, unsigned int
}

// Configure this sensor, returning true if error and setting 'seen' if we processed any configuration parameters
GCodeResult SimpleFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen)
GCodeResult SimpleFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) THROWS(GCodeException)
{
const GCodeResult rslt = CommonConfigure(gb, reply, INTERRUPT_MODE_NONE, seen);
if (rslt <= GCodeResult::warning)
Expand Down
2 changes: 1 addition & 1 deletion src/GCodes/GCodeBuffer/BinaryParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BinaryParser
public:
BinaryParser(GCodeBuffer& gcodeBuffer) noexcept;
void Init() noexcept; // Set it up to parse another G-code
void Put(const uint32_t *data, size_t len) noexcept; // Add an entire string, overwriting any existing content
void Put(const uint32_t *data, size_t len) noexcept; // Add an entire binary code, overwriting any existing content
void DecodeCommand() noexcept; // Print the buffer content in debug mode and prepare for execution
bool Seen(char c) noexcept __attribute__((hot)); // Is a character present?

Expand Down
55 changes: 41 additions & 14 deletions src/GCodes/GCodeBuffer/GCodeBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,33 +766,55 @@ void GCodeBuffer::AbortFile(bool abortAll, bool requestAbort) noexcept

void GCodeBuffer::SetFileFinished() noexcept
{
uint32_t lastFileId = machineState->fileId;
if (lastFileId != 0)
FileId macroFileId = NoFileId, printFileId = OriginalMachineState().fileId;
for (GCodeMachineState *ms = machineState; ms != nullptr; ms = ms->GetPrevious())
{
for (GCodeMachineState *ms = machineState; ms != nullptr; ms = ms->GetPrevious())
if (macroFileId == NoFileId && ms->fileId != NoFileId && ms->fileId != printFileId && !ms->fileFinished)
{
// Get the next macro file being executed
macroFileId = ms->fileId;
}

if (macroFileId != NoFileId)
{
if (ms->fileId == lastFileId)
if (ms->fileId == macroFileId)
{
// Flag it (and following machine states) as finished
ms->fileFinished = true;
}
else
{
break;
}
}
}

if (macroFileId == NoFileId)
{
reprap.GetPlatform().Message(WarningMessage, "Cannot set macro file finished because there is no file ID\n");
}
}

void GCodeBuffer::SetPrintFinished() noexcept
{
uint32_t printFileId = OriginalMachineState().fileId;
if (printFileId != 0)
FileId printFileId = OriginalMachineState().fileId;
if (printFileId != NoFileId)
{
for (GCodeMachineState *ms = machineState; ms != nullptr; ms = ms->GetPrevious())
{
if (ms->fileId == printFileId)
{
// Mark machine states executing the print file as finished
ms->fileFinished = true;
}
}
}
else
{
reprap.GetPlatform().Message(WarningMessage, "Cannot set print file finished because there is no file ID\n");
}
}

// This is only called when using the Linux interface and returns if the macro file could be opened
bool GCodeBuffer::RequestMacroFile(const char *filename, bool fromCode) noexcept
{
Expand All @@ -802,20 +824,25 @@ bool GCodeBuffer::RequestMacroFile(const char *filename, bool fromCode) noexcept
return false;
}
// Request the macro file from the SBC
macroJustStarted = false;
macroJustStarted = macroFileError = macroFileEmpty = false;
machineState->macroStartedByCode = fromCode;
requestedMacroFile.copy(filename);
isWaitingForMacro = true;

// Wait for a response (but not forever)
if (!macroSemaphore.Take(SpiConnectionTimeout))
// There is no need to block the main task if daemon.g is requested.
// If it doesn't exist, DSF will simply close the virtual file again
if (GetChannel() != GCodeChannel::Daemon || machineState->doingFileMacro)
{
isWaitingForMacro = false;
reprap.GetPlatform().MessageF(ErrorMessage, "Failed to get macro response within %" PRIu32 "ms from SBC (channel %s)\n", SpiConnectionTimeout, GetChannel().ToString());
return false;
// Wait for a response (but not forever)
isWaitingForMacro = true;
if (!macroSemaphore.Take(SpiConnectionTimeout))
{
isWaitingForMacro = false;
reprap.GetPlatform().MessageF(ErrorMessage, "Failed to get macro response within %" PRIu32 "ms from SBC (channel %s)\n", SpiConnectionTimeout, GetChannel().ToString());
return false;
}
}

// When we get here most of the variables above have been set
// When we get here we expect the Linux interface to have set the variables above for us
if (!macroFileError)
{
macroJustStarted = true;
Expand Down
10 changes: 9 additions & 1 deletion src/GCodes/GCodeBuffer/GCodeBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ class GCodeBuffer INHERIT_OBJECT_MODEL

inline bool GCodeBuffer::IsDoingFileMacro() const noexcept
{
#if HAS_LINUX_INTERFACE
return machineState->doingFileMacro || IsMacroRequestPending();
#else
return machineState->doingFileMacro;
#endif
}

#if HAS_LINUX_INTERFACE
Expand Down Expand Up @@ -329,12 +333,16 @@ inline void GCodeBuffer::AdvanceState() noexcept
// Return true if we can queue gcodes from this source. This is the case if a file is being executed
inline bool GCodeBuffer::CanQueueCodes() const noexcept
{
return IsDoingFile();
return machineState->DoingFile();
}

inline bool GCodeBuffer::IsDoingFile() const noexcept
{
#if HAS_LINUX_INTERFACE
return machineState->DoingFile() || IsMacroRequestPending();
#else
return machineState->DoingFile();
#endif
}

inline bool GCodeBuffer::IsReady() const noexcept
Expand Down
2 changes: 1 addition & 1 deletion src/GCodes/GCodeFileInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ unsigned int GCodeFileInfo::GetNumLayers() const noexcept
const float nl = (firstLayerHeight > 0.0)
? (objectHeight - firstLayerHeight)/layerHeight + 1
: objectHeight/layerHeight;
return rintf(max<float>(nl, 0.0));
return (unsigned int)lrintf(max<float>(nl, 0.0));
}

// End
23 changes: 12 additions & 11 deletions src/GCodes/GCodeMachineState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@

#include <limits>

#if HAS_LINUX_INTERFACE
static uint8_t LastFileId = 1;
#endif

// Create a default initialised GCodeMachineState
GCodeMachineState::GCodeMachineState() noexcept
: feedRate(DefaultFeedRate * SecondsToMinutes),
#if HAS_LINUX_INTERFACE
fileId(0),
fileId(NoFileId),
#endif
lineNumber(0),
drivesRelative(false), axesRelative(false),
Expand Down Expand Up @@ -86,7 +82,12 @@ void GCodeMachineState::SetFileExecuting() noexcept
if (!fileState.IsLive())
#endif
{
fileId = LastFileId++;
fileId = (GetPrevious() != nullptr ? GetPrevious()->fileId : NoFileId) + 1;
if (fileId == NoFileId)
{
// In case the ID overlapped increase it once more (should never happen)
fileId++;
}
fileFinished = false;
}
}
Expand All @@ -97,7 +98,7 @@ void GCodeMachineState::SetFileExecuting() noexcept
bool GCodeMachineState::DoingFile() const noexcept
{
#if HAS_LINUX_INTERFACE
if (reprap.UsingLinuxInterface() && fileId != 0)
if (reprap.UsingLinuxInterface() && fileId != NoFileId)
{
return true;
}
Expand All @@ -113,14 +114,14 @@ bool GCodeMachineState::DoingFile() const noexcept
void GCodeMachineState::CloseFile() noexcept
{
#if HAS_LINUX_INTERFACE
if (reprap.UsingLinuxInterface() && fileId != 0)
if (reprap.UsingLinuxInterface() && fileId != NoFileId)
{
const uint8_t lastFileId = fileId;
for (GCodeMachineState *ms = this; ms != nullptr; ms = ms->previous)
const FileId lastFileId = fileId;
for (GCodeMachineState *ms = this; ms != nullptr; ms = ms->GetPrevious())
{
if (ms->fileId == lastFileId)
{
ms->fileId = 0;
ms->fileId = NoFileId;
ms->fileFinished = false;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/GCodes/GCodeMachineState.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ enum class BlockType : uint8_t
loop // block inside a 'while' command
};

#if HAS_LINUX_INTERFACE
typedef uint8_t FileId;

constexpr FileId NoFileId = 0;
#endif

// Class to hold the state of gcode execution for some input source
class GCodeMachineState
{
Expand Down Expand Up @@ -181,7 +187,7 @@ class GCodeMachineState
FileData fileState;
#endif
#if HAS_LINUX_INTERFACE
uint8_t fileId; // virtual file ID to deal with stack push/pops when a file is being cancelled or finished in the wrong stack level
FileId fileId; // virtual ID to distinguish files in different stack levels (only unique per GB)
#endif
ResourceBitmap lockedResources;
BlockState blockStates[MaxBlockIndent];
Expand Down
Loading

0 comments on commit 7ccfaf4

Please sign in to comment.