Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit sum of mix ratio to 1 unless disabled by M567 S0 #197

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/GCodes/GCodes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = ' ';
Expand All @@ -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");
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/Tools/Tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/Tools/Tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down