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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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)
|
|
|
|
float saved_extruder_advance_K[EXTRUDERS];
|
|
|
|
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
|
|
|
|
|
|
|
#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) {
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("?T value out of range.");
|
2018-09-11 03:37:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-03-26 09:02:27 +00:00
|
|
|
#if ENABLED(EXTRA_LIN_ADVANCE_K)
|
|
|
|
|
2019-07-22 00:33:37 +00:00
|
|
|
bool ext_slot = TEST(lin_adv_slot, tool_index);
|
2019-03-26 09:02:27 +00:00
|
|
|
|
|
|
|
if (parser.seenval('S')) {
|
|
|
|
const bool slot = parser.value_bool();
|
|
|
|
if (ext_slot != slot) {
|
|
|
|
ext_slot = slot;
|
2019-07-22 00:33:37 +00:00
|
|
|
SET_BIT_TO(lin_adv_slot, tool_index, slot);
|
2019-03-26 09:02:27 +00:00
|
|
|
planner.synchronize();
|
2019-07-22 00:33:37 +00:00
|
|
|
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;
|
2019-03-26 09:02:27 +00:00
|
|
|
}
|
2018-03-01 08:10:43 +00:00
|
|
|
}
|
2019-03-26 09:02:27 +00:00
|
|
|
|
|
|
|
if (parser.seenval('K')) {
|
|
|
|
const float newK = parser.value_float();
|
|
|
|
if (WITHIN(newK, 0, 10)) {
|
|
|
|
if (ext_slot)
|
2019-07-22 00:33:37 +00:00
|
|
|
saved_extruder_advance_K[tool_index] = newK;
|
2019-03-26 09:02:27 +00:00
|
|
|
else {
|
|
|
|
planner.synchronize();
|
2019-07-22 00:33:37 +00:00
|
|
|
planner.extruder_advance_K[tool_index] = newK;
|
2019-03-26 09:02:27 +00:00
|
|
|
}
|
2018-09-11 03:37:32 +00:00
|
|
|
}
|
2019-03-26 09:02:27 +00:00
|
|
|
else
|
|
|
|
SERIAL_ECHOLNPGM("?K value out of range (0-10).");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.seenval('L')) {
|
|
|
|
const float newL = parser.value_float();
|
|
|
|
if (WITHIN(newL, 0, 10)) {
|
|
|
|
if (!ext_slot)
|
2019-07-22 00:33:37 +00:00
|
|
|
saved_extruder_advance_K[tool_index] = newL;
|
2019-03-26 09:02:27 +00:00
|
|
|
else {
|
|
|
|
planner.synchronize();
|
2019-07-22 00:33:37 +00:00
|
|
|
planner.extruder_advance_K[tool_index] = newL;
|
2019-03-26 09:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SERIAL_ECHOLNPGM("?L value out of range (0-10).");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parser.seen_any()) {
|
|
|
|
#if EXTRUDERS < 2
|
2019-09-26 08:47:26 +00:00
|
|
|
SERIAL_ECHOLNPAIR("Advance S", ext_slot, " K", planner.extruder_advance_K[0],
|
|
|
|
"(Slot ", 1 - ext_slot, " K", saved_extruder_advance_K[0], ")");
|
2019-03-26 09:02:27 +00:00
|
|
|
#else
|
|
|
|
LOOP_L_N(i, EXTRUDERS) {
|
2019-05-15 06:07:07 +00:00
|
|
|
const int slot = (int)TEST(lin_adv_slot, i);
|
2019-09-26 08:47:26 +00:00
|
|
|
SERIAL_ECHOLNPAIR("Advance T", int(i), " S", slot, " K", planner.extruder_advance_K[i],
|
|
|
|
"(Slot ", 1 - slot, " K", saved_extruder_advance_K[i], ")");
|
2019-03-26 09:02:27 +00:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (parser.seenval('K')) {
|
|
|
|
const float newK = parser.value_float();
|
|
|
|
if (WITHIN(newK, 0, 10)) {
|
|
|
|
planner.synchronize();
|
2019-07-22 00:33:37 +00:00
|
|
|
planner.extruder_advance_K[tool_index] = newK;
|
2019-03-26 09:02:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
SERIAL_ECHOLNPGM("?K value out of range (0-10).");
|
|
|
|
}
|
|
|
|
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
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
2017-09-17 22:42:53 +00:00
|
|
|
|
|
|
|
#endif // LIN_ADVANCE
|