Skip to content

Commit f45a1ae

Browse files
committed
Limit sum of mix ratio to 1 unless disabled by M567 S0
1 parent 635314b commit f45a1ae

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

src/GCodes/GCodes2.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,8 +3107,14 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
31073107
Tool* const tool = reprap.GetTool(tNumber);
31083108
if (tool != nullptr)
31093109
{
3110+
bool seen = false;
3111+
if (gb.Seen('S')) {
3112+
seen = true;
3113+
tool->SetCanExceedMixSumOf1(gb.GetIValue() == 0);
3114+
}
31103115
if (gb.Seen(extrudeLetter))
31113116
{
3117+
seen = true;
31123118
float eVals[MaxExtruders];
31133119
size_t eCount = tool->DriveCount();
31143120
gb.GetFloatArray(eVals, eCount, false);
@@ -3118,10 +3124,12 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
31183124
}
31193125
else
31203126
{
3121-
tool->DefineMix(eVals);
3127+
if (!tool->DefineMix(eVals)) {
3128+
reply.printf("Setting mix ratios - sum of ratios > 1.0. Disable this check with M567 P%d S0", tNumber);
3129+
}
31223130
}
31233131
}
3124-
else
3132+
if (!seen)
31253133
{
31263134
reply.printf("Tool %d mix ratios:", tNumber);
31273135
char sep = ' ';
@@ -3130,6 +3138,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
31303138
reply.catf("%c%.3f", sep, (double)tool->GetMix()[drive]);
31313139
sep = ':';
31323140
}
3141+
reply.printf(". Mix ratio sum of 1.0 can be exceeded: %s", tool->GetCanExceedMixSumOf1() ? "true" : "false");
31333142
}
31343143
}
31353144
}

src/Tools/Tool.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Tool * Tool::freelist = nullptr;
116116
t->heaterFault = false;
117117
t->axisOffsetsProbed = 0;
118118
t->displayColdExtrudeWarning = false;
119+
t->canExceedMixSumOf1 = false;
119120

120121
for (size_t axis = 0; axis < MaxAxes; axis++)
121122
{
@@ -356,12 +357,33 @@ bool Tool::DisplayColdExtrudeWarning()
356357
return result;
357358
}
358359

359-
void Tool::DefineMix(const float m[])
360+
bool Tool::DefineMix(const float m[])
360361
{
362+
if (this->CheckExceedsMixSumOf1(m)) {
363+
return false;
364+
}
361365
for(size_t drive = 0; drive < driveCount; drive++)
362366
{
363367
mix[drive] = m[drive];
364368
}
369+
return true;
370+
}
371+
372+
bool Tool::CheckExceedsMixSumOf1(const float m[]) const {
373+
// We don't need to check if this is true
374+
if (this->canExceedMixSumOf1) {
375+
return false;
376+
}
377+
378+
float sum = 0.0;
379+
// Only check for the amount of configured drives
380+
for(size_t drive = 0; drive < driveCount; drive++) {
381+
sum += m[drive];
382+
if (sum > 1.0) {
383+
return true;
384+
}
385+
}
386+
return false;
365387
}
366388

367389
// Write the tool's settings to file returning true if successful

src/Tools/Tool.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class Tool
5858
int Heater(size_t heaterNumber) const;
5959
const char *GetName() const;
6060
int Number() const;
61-
void DefineMix(const float m[]);
61+
bool DefineMix(const float m[]);
62+
void SetCanExceedMixSumOf1(const bool m) { canExceedMixSumOf1 = m; }
63+
bool GetCanExceedMixSumOf1() const { return canExceedMixSumOf1; }
6264
const float* GetMix() const;
6365
float MaxFeedrate() const;
6466
void Print(const StringRef& reply) const;
@@ -94,11 +96,14 @@ class Tool
9496
void ResetTemperatureFault(int8_t wasDudHeater);
9597
bool AllHeatersAtHighTemperature(bool forExtrusion) const;
9698

99+
bool CheckExceedsMixSumOf1(const float m[]) const;
100+
97101
Tool* next;
98102
Filament *filament;
99103
char *name;
100104
float offset[MaxAxes];
101105
float mix[MaxExtruders];
106+
bool canExceedMixSumOf1;
102107
float activeTemperatures[Heaters];
103108
float standbyTemperatures[Heaters];
104109
size_t driveCount;

0 commit comments

Comments
 (0)