diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp index 347daccad1..2945855b2a 100644 --- a/src/GCodes/GCodes2.cpp +++ b/src/GCodes/GCodes2.cpp @@ -3157,8 +3157,14 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) Tool* const tool = reprap.GetTool(tNumber); if (tool != nullptr) { + bool seen = false; + if (gb.Seen('S')) { + seen = true; + tool->SetCanExceedMixSumOf1(gb.GetIValue() == 0); + } if (gb.Seen(extrudeLetter)) { + seen = true; float eVals[MaxExtruders]; size_t eCount = tool->DriveCount(); gb.GetFloatArray(eVals, eCount, false); @@ -3168,10 +3174,12 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) } else { - tool->DefineMix(eVals); + if (!tool->DefineMix(eVals)) { + reply.printf("Setting mix ratios - sum of ratios > 1.0. Disable this check with M567 P%d S0", tNumber); + } } } - else + if (!seen) { reply.printf("Tool %d mix ratios:", tNumber); char sep = ' '; @@ -3180,6 +3188,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) reply.catf("%c%.3f", sep, (double)tool->GetMix()[drive]); sep = ':'; } + reply.printf(". Mix ratio sum of 1.0 can be exceeded: %s", tool->GetCanExceedMixSumOf1() ? "true" : "false"); } } } diff --git a/src/Tools/Tool.cpp b/src/Tools/Tool.cpp index 156c2d612c..477787df51 100644 --- a/src/Tools/Tool.cpp +++ b/src/Tools/Tool.cpp @@ -117,6 +117,7 @@ Tool * Tool::freelist = nullptr; t->heaterFault = false; t->axisOffsetsProbed = 0; t->displayColdExtrudeWarning = false; + t->canExceedMixSumOf1 = false; for (size_t axis = 0; axis < MaxAxes; axis++) { @@ -357,12 +358,33 @@ bool Tool::DisplayColdExtrudeWarning() return result; } -void Tool::DefineMix(const float m[]) +bool Tool::DefineMix(const float m[]) { + if (this->CheckExceedsMixSumOf1(m)) { + return false; + } for(size_t drive = 0; drive < driveCount; drive++) { mix[drive] = m[drive]; } + return true; +} + +bool Tool::CheckExceedsMixSumOf1(const float m[]) const { + // We don't need to check if this is true + if (this->canExceedMixSumOf1) { + return false; + } + + float sum = 0.0; + // Only check for the amount of configured drives + for(size_t drive = 0; drive < driveCount; drive++) { + sum += m[drive]; + if (sum > 1.0) { + return true; + } + } + return false; } // Write the tool's settings to file returning true if successful diff --git a/src/Tools/Tool.h b/src/Tools/Tool.h index f7ecb68907..2ec875d008 100644 --- a/src/Tools/Tool.h +++ b/src/Tools/Tool.h @@ -62,7 +62,9 @@ class Tool int Heater(size_t heaterNumber) const; const char *GetName() const; int Number() const; - void DefineMix(const float m[]); + bool DefineMix(const float m[]); + void SetCanExceedMixSumOf1(const bool m) { canExceedMixSumOf1 = m; } + bool GetCanExceedMixSumOf1() const { return canExceedMixSumOf1; } const float* GetMix() const; float MaxFeedrate() const; void Print(const StringRef& reply) const; @@ -103,11 +105,14 @@ class Tool void ResetTemperatureFault(int8_t wasDudHeater); bool AllHeatersAtHighTemperature(bool forExtrusion) const; + bool CheckExceedsMixSumOf1(const float m[]) const; + Tool* next; Filament *filament; const char *name; float offset[MaxAxes]; float mix[MaxExtrudersPerTool]; + bool canExceedMixSumOf1; float activeTemperatures[MaxHeatersPerTool]; float standbyTemperatures[MaxHeatersPerTool]; uint8_t driveCount;