Skip to content

Commit 646272d

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

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/GCodes/GCodes2.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3107,6 +3107,9 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
31073107
Tool* const tool = reprap.GetTool(tNumber);
31083108
if (tool != nullptr)
31093109
{
3110+
if (gb.Seen('S')) {
3111+
tool->SetCanExceedMixSumOf1(gb.GetIValue() == 0);
3112+
}
31103113
if (gb.Seen(extrudeLetter))
31113114
{
31123115
float eVals[MaxExtruders];
@@ -3118,7 +3121,9 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
31183121
}
31193122
else
31203123
{
3121-
tool->DefineMix(eVals);
3124+
if (!tool->DefineMix(eVals)) {
3125+
reply.printf("Setting mix ratios - sum of ratios > 1.0. Disable this check with M567 P%d S0", tNumber);
3126+
}
31223127
}
31233128
}
31243129
else
@@ -3130,6 +3135,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
31303135
reply.catf("%c%.3f", sep, (double)tool->GetMix()[drive]);
31313136
sep = ':';
31323137
}
3138+
reply.printf(". Mix ratio sum of 1.0 can be exceeded: %s", tool->GetCanExceedMixSumOf1() ? "true" : "false");
31333139
}
31343140
}
31353141
}

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)