Browse Source

Improved M900

vanilla_fb_2.0.x
Scott Lahteine 5 years ago
parent
commit
6b5347ee39
  1. 138
      Marlin/src/gcode/feature/advance/M900.cpp
  2. 4
      Marlin/src/module/configuration_store.cpp

138
Marlin/src/gcode/feature/advance/M900.cpp

@ -29,11 +29,10 @@
#include "../../../module/stepper.h" #include "../../../module/stepper.h"
#if ENABLED(EXTRA_LIN_ADVANCE_K) #if ENABLED(EXTRA_LIN_ADVANCE_K)
float saved_extruder_advance_K[EXTRUDERS]; float other_extruder_advance_K[EXTRUDERS];
uint8_t lin_adv_slot = 0; uint8_t lin_adv_slot = 0;
#endif #endif
/** /**
* M900: Get or Set Linear Advance K-factor * M900: Get or Set Linear Advance K-factor
* T<tool> Which tool to address * T<tool> Which tool to address
@ -43,100 +42,107 @@
*/ */
void GcodeSuite::M900() { void GcodeSuite::M900() {
auto echo_value_oor = [] (const char ltr, const bool ten=true) {
SERIAL_CHAR('?'); SERIAL_CHAR(ltr);
SERIAL_ECHOPGM(" value out of range");
if (ten) SERIAL_ECHOPGM(" (0-10)");
SERIAL_ECHOLNPGM(".");
}
if (!parser.seen_any()) {
#if ENABLED(EXTRA_LIN_ADVANCE_K)
#if EXTRUDERS < 2
SERIAL_ECHOLNPAIR("Advance S", int(new_slot), " K", kref, "(S", int(!new_slot), " K", lref, ")");
#else
LOOP_L_N(i, EXTRUDERS) {
const bool slot = TEST(lin_adv_slot, i);
SERIAL_ECHOLNPAIR("Advance T", int(i), " S", int(slot), " K", planner.extruder_advance_K[i],
"(S", int(!slot), " K", other_extruder_advance_K[i], ")");
SERIAL_EOL();
}
#endif
#else
SERIAL_ECHO_START();
#if EXTRUDERS < 2
SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K[0]);
#else
SERIAL_ECHOPGM("Advance K");
LOOP_L_N(i, EXTRUDERS) {
SERIAL_CHAR(' ', '0' + i, ':');
SERIAL_ECHO(planner.extruder_advance_K[i]);
}
SERIAL_EOL();
#endif
#endif
return;
}
#if EXTRUDERS < 2 #if EXTRUDERS < 2
constexpr uint8_t tool_index = 0; constexpr uint8_t tool_index = 0;
#else #else
const uint8_t tool_index = parser.intval('T', active_extruder); const uint8_t tool_index = parser.intval('T', active_extruder);
if (tool_index >= EXTRUDERS) { if (tool_index >= EXTRUDERS) {
SERIAL_ECHOLNPGM("?T value out of range."); echo_value_oor('T', false);
return; return;
} }
#endif #endif
float &kref = planner.extruder_advance_K[tool_index],
&lref = other_extruder_advance_K[tool_index];
const float oldK = kref, oldOther = lref;
float newK = oldK;
#if ENABLED(EXTRA_LIN_ADVANCE_K) #if ENABLED(EXTRA_LIN_ADVANCE_K)
bool ext_slot = TEST(lin_adv_slot, tool_index); const bool old_slot = TEST(lin_adv_slot, tool_index), // The tool's current slot (0 or 1)
new_slot = parser.boolval('S', old_slot); // The passed slot (default = current)
if (parser.seenval('S')) { // If a new slot is being selected swap the current and
const bool slot = parser.value_bool(); // saved K values. Do here so K/L will apply correctly.
if (ext_slot != slot) { if (new_slot != old_slot) { // Not the same slot?
ext_slot = slot; SET_BIT_TO(lin_adv_slot, tool_index, new_slot); // Update the slot for the tool
SET_BIT_TO(lin_adv_slot, tool_index, slot); newK = oldOther; // Get new K value from backup
planner.synchronize(); lref = oldK; // Save K to backup
const float temp = planner.extruder_advance_K[tool_index];
planner.extruder_advance_K[tool_index] = saved_extruder_advance_K[tool_index];
saved_extruder_advance_K[tool_index] = temp;
}
} }
// Set the main K value. Apply if the main slot is active.
if (parser.seenval('K')) { if (parser.seenval('K')) {
const float newK = parser.value_float(); const float newK = parser.value_float();
if (WITHIN(newK, 0, 10)) { if (!WITHIN(newK, 0, 10)) echo_value_oor('K');
if (ext_slot) else if (new_slot) lref = newK; // S1 Knn
saved_extruder_advance_K[tool_index] = newK; else newK = newK; // S0 Knn
else {
planner.synchronize();
planner.extruder_advance_K[tool_index] = newK;
}
}
else
SERIAL_ECHOLNPGM("?K value out of range (0-10).");
} }
// Set the extra K value. Apply if the extra slot is active.
if (parser.seenval('L')) { if (parser.seenval('L')) {
const float newL = parser.value_float(); const float newL = parser.value_float();
if (WITHIN(newL, 0, 10)) { if (!WITHIN(newL, 0, 10)) echo_value_oor('L');
if (!ext_slot) else if (!new_slot) lref = newL; // S0 Lnn
saved_extruder_advance_K[tool_index] = newL; else newK = newL; // S1 Lnn
else {
planner.synchronize();
planner.extruder_advance_K[tool_index] = newL;
}
}
else
SERIAL_ECHOLNPGM("?L value out of range (0-10).");
}
if (!parser.seen_any()) {
#if EXTRUDERS < 2
SERIAL_ECHOLNPAIR("Advance S", ext_slot, " K", planner.extruder_advance_K[0],
"(Slot ", 1 - ext_slot, " K", saved_extruder_advance_K[0], ")");
#else
LOOP_L_N(i, EXTRUDERS) {
const int slot = (int)TEST(lin_adv_slot, i);
SERIAL_ECHOLNPAIR("Advance T", int(i), " S", slot, " K", planner.extruder_advance_K[i],
"(Slot ", 1 - slot, " K", saved_extruder_advance_K[i], ")");
SERIAL_EOL();
}
#endif
} }
#else #else
if (parser.seenval('K')) { if (parser.seenval('K')) {
const float newK = parser.value_float(); const float newK = parser.value_float();
if (WITHIN(newK, 0, 10)) { if (WITHIN(newK, 0, 10))
planner.synchronize(); newK = newK;
planner.extruder_advance_K[tool_index] = newK;
}
else else
SERIAL_ECHOLNPGM("?K value out of range (0-10)."); echo_value_oor('K');
}
else {
SERIAL_ECHO_START();
#if EXTRUDERS < 2
SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K[0]);
#else
SERIAL_ECHOPGM("Advance K");
LOOP_L_N(i, EXTRUDERS) {
SERIAL_CHAR(' '); SERIAL_ECHO(int(i));
SERIAL_CHAR('='); SERIAL_ECHO(planner.extruder_advance_K[i]);
}
SERIAL_EOL();
#endif
} }
#endif #endif
if (newK != oldK) {
planner.synchronize();
kref = newK;
}
} }
#endif // LIN_ADVANCE #endif // LIN_ADVANCE

4
Marlin/src/module/configuration_store.cpp

@ -101,7 +101,7 @@
#endif #endif
#if ENABLED(EXTRA_LIN_ADVANCE_K) #if ENABLED(EXTRA_LIN_ADVANCE_K)
extern float saved_extruder_advance_K[EXTRUDERS]; extern float other_extruder_advance_K[EXTRUDERS];
#endif #endif
#if EXTRUDERS > 1 #if EXTRUDERS > 1
@ -2717,7 +2717,7 @@ void MarlinSettings::reset() {
LOOP_L_N(i, EXTRUDERS) { LOOP_L_N(i, EXTRUDERS) {
planner.extruder_advance_K[i] = LIN_ADVANCE_K; planner.extruder_advance_K[i] = LIN_ADVANCE_K;
#if ENABLED(EXTRA_LIN_ADVANCE_K) #if ENABLED(EXTRA_LIN_ADVANCE_K)
saved_extruder_advance_K[i] = LIN_ADVANCE_K; other_extruder_advance_K[i] = LIN_ADVANCE_K;
#endif #endif
} }
#endif #endif

Loading…
Cancel
Save