Skip to content

Commit

Permalink
Limit sum of mix ratio to 1 unless disabled by M567 S0
Browse files Browse the repository at this point in the history
  • Loading branch information
wilriker committed Aug 14, 2018
1 parent 635314b commit f45a1ae
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/GCodes/GCodes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3107,8 +3107,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);
Expand All @@ -3118,10 +3124,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 = ' ';
Expand All @@ -3130,6 +3138,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");
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/Tools/Tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,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++)
{
Expand Down Expand Up @@ -356,12 +357,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
Expand Down
7 changes: 6 additions & 1 deletion src/Tools/Tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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;
Expand Down Expand Up @@ -94,11 +96,14 @@ class Tool
void ResetTemperatureFault(int8_t wasDudHeater);
bool AllHeatersAtHighTemperature(bool forExtrusion) const;

bool CheckExceedsMixSumOf1(const float m[]) const;

Tool* next;
Filament *filament;
char *name;
float offset[MaxAxes];
float mix[MaxExtruders];
bool canExceedMixSumOf1;
float activeTemperatures[Heaters];
float standbyTemperatures[Heaters];
size_t driveCount;
Expand Down

0 comments on commit f45a1ae

Please sign in to comment.