2017-09-06 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-17 22:42:53 +00:00
|
|
|
#include "../../../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
|
|
|
|
#include "../../gcode.h"
|
|
|
|
#include "../../../module/planner.h"
|
|
|
|
#include "../../../module/stepper.h"
|
|
|
|
|
2019-03-26 09:02:27 +00:00
|
|
|
#if ENABLED(EXTRA_LIN_ADVANCE_K)
|
2020-02-29 10:28:07 +00:00
|
|
|
float other_extruder_advance_K[EXTRUDERS];
|
2019-03-26 09:02:27 +00:00
|
|
|
uint8_t lin_adv_slot = 0;
|
|
|
|
#endif
|
|
|
|
|
2017-09-06 11:28:31 +00:00
|
|
|
/**
|
2018-03-01 21:11:12 +00:00
|
|
|
* M900: Get or Set Linear Advance K-factor
|
2019-03-26 09:02:27 +00:00
|
|
|
* T<tool> Which tool to address
|
|
|
|
* K<factor> Set current advance K factor (Slot 0).
|
|
|
|
* L<factor> Set secondary advance K factor (Slot 1). Requires EXTRA_LIN_ADVANCE_K.
|
|
|
|
* S<0/1> Activate slot 0 or 1. Requires EXTRA_LIN_ADVANCE_K.
|
2017-09-06 11:28:31 +00:00
|
|
|
*/
|
2017-09-17 22:42:53 +00:00
|
|
|
void GcodeSuite::M900() {
|
2018-09-11 03:37:32 +00:00
|
|
|
|
2020-03-18 15:30:19 +00:00
|
|
|
auto echo_value_oor = [](const char ltr, const bool ten=true) {
|
2021-02-05 01:18:31 +00:00
|
|
|
SERIAL_CHAR('?', ltr);
|
2020-02-29 10:28:07 +00:00
|
|
|
SERIAL_ECHOPGM(" value out of range");
|
|
|
|
if (ten) SERIAL_ECHOPGM(" (0-10)");
|
|
|
|
SERIAL_ECHOLNPGM(".");
|
2020-03-02 22:51:47 +00:00
|
|
|
};
|
2020-02-29 10:28:07 +00:00
|
|
|
|
2018-09-11 03:37:32 +00:00
|
|
|
#if EXTRUDERS < 2
|
2019-07-22 00:33:37 +00:00
|
|
|
constexpr uint8_t tool_index = 0;
|
2018-09-11 03:37:32 +00:00
|
|
|
#else
|
2019-07-22 00:33:37 +00:00
|
|
|
const uint8_t tool_index = parser.intval('T', active_extruder);
|
|
|
|
if (tool_index >= EXTRUDERS) {
|
2020-02-29 10:28:07 +00:00
|
|
|
echo_value_oor('T', false);
|
2018-09-11 03:37:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-03-02 23:43:37 +00:00
|
|
|
float &kref = planner.extruder_advance_K[tool_index], newK = kref;
|
|
|
|
const float oldK = newK;
|
2020-03-02 22:51:47 +00:00
|
|
|
|
|
|
|
#if ENABLED(EXTRA_LIN_ADVANCE_K)
|
2020-02-29 10:28:07 +00:00
|
|
|
|
2020-03-02 23:43:37 +00:00
|
|
|
float &lref = other_extruder_advance_K[tool_index];
|
2019-03-26 09:02:27 +00:00
|
|
|
|
2020-02-29 10:28:07 +00:00
|
|
|
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 a new slot is being selected swap the current and
|
|
|
|
// saved K values. Do here so K/L will apply correctly.
|
|
|
|
if (new_slot != old_slot) { // Not the same slot?
|
|
|
|
SET_BIT_TO(lin_adv_slot, tool_index, new_slot); // Update the slot for the tool
|
2020-03-02 22:51:47 +00:00
|
|
|
newK = lref; // Get new K value from backup
|
2020-02-29 10:28:07 +00:00
|
|
|
lref = oldK; // Save K to backup
|
2018-03-01 08:10:43 +00:00
|
|
|
}
|
2019-03-26 09:02:27 +00:00
|
|
|
|
2020-02-29 10:28:07 +00:00
|
|
|
// Set the main K value. Apply if the main slot is active.
|
2019-03-26 09:02:27 +00:00
|
|
|
if (parser.seenval('K')) {
|
2020-03-02 22:51:47 +00:00
|
|
|
const float K = parser.value_float();
|
|
|
|
if (!WITHIN(K, 0, 10)) echo_value_oor('K');
|
|
|
|
else if (new_slot) lref = K; // S1 Knn
|
|
|
|
else newK = K; // S0 Knn
|
2019-03-26 09:02:27 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 10:28:07 +00:00
|
|
|
// Set the extra K value. Apply if the extra slot is active.
|
2019-03-26 09:02:27 +00:00
|
|
|
if (parser.seenval('L')) {
|
2020-03-02 22:51:47 +00:00
|
|
|
const float L = parser.value_float();
|
|
|
|
if (!WITHIN(L, 0, 10)) echo_value_oor('L');
|
|
|
|
else if (!new_slot) lref = L; // S0 Lnn
|
|
|
|
else newK = L; // S1 Lnn
|
2019-03-26 09:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (parser.seenval('K')) {
|
2020-03-02 22:51:47 +00:00
|
|
|
const float K = parser.value_float();
|
|
|
|
if (WITHIN(K, 0, 10))
|
|
|
|
newK = K;
|
2019-03-26 09:02:27 +00:00
|
|
|
else
|
2020-02-29 10:28:07 +00:00
|
|
|
echo_value_oor('K');
|
2019-03-26 09:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2020-02-29 10:28:07 +00:00
|
|
|
|
|
|
|
if (newK != oldK) {
|
|
|
|
planner.synchronize();
|
|
|
|
kref = newK;
|
|
|
|
}
|
2020-03-02 22:51:47 +00:00
|
|
|
|
|
|
|
if (!parser.seen_any()) {
|
|
|
|
|
|
|
|
#if ENABLED(EXTRA_LIN_ADVANCE_K)
|
|
|
|
|
|
|
|
#if EXTRUDERS < 2
|
2021-02-08 06:37:24 +00:00
|
|
|
SERIAL_ECHOLNPAIR("Advance S", new_slot, " K", kref, "(S", !new_slot, " K", lref, ")");
|
2020-03-02 22:51:47 +00:00
|
|
|
#else
|
|
|
|
LOOP_L_N(i, EXTRUDERS) {
|
|
|
|
const bool slot = TEST(lin_adv_slot, i);
|
2021-02-08 06:37:24 +00:00
|
|
|
SERIAL_ECHOLNPAIR("Advance T", i, " S", slot, " K", planner.extruder_advance_K[i],
|
|
|
|
"(S", !slot, " K", other_extruder_advance_K[i], ")");
|
2020-03-02 22:51:47 +00:00
|
|
|
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, ':');
|
2020-06-23 02:12:45 +00:00
|
|
|
SERIAL_DECIMAL(planner.extruder_advance_K[i]);
|
2020-03-02 22:51:47 +00:00
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
2017-09-17 22:42:53 +00:00
|
|
|
|
|
|
|
#endif // LIN_ADVANCE
|