forked from mriscoc/Ender3V2S1
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathM900.cpp
More file actions
177 lines (148 loc) · 5.3 KB
/
M900.cpp
File metadata and controls
177 lines (148 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#include "../../../inc/MarlinConfig.h"
#if ENABLED(LIN_ADVANCE)
#include "../../gcode.h"
#include "../../../module/planner.h"
#include "../../../module/stepper.h"
#if ENABLED(ADVANCE_K_EXTRA)
float other_extruder_advance_K[DISTINCT_E];
uint8_t lin_adv_slot = 0;
#endif
/**
* M900: Get or Set Linear Advance K-factor
* 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 ADVANCE_K_EXTRA.
* S<0/1> Activate slot 0 or 1. Requires ADVANCE_K_EXTRA.
*/
void GcodeSuite::M900() {
auto echo_value_oor = [](const char ltr, const bool ten=true) {
SERIAL_CHAR('?', ltr);
SERIAL_ECHOPGM(" value out of range");
if (ten) SERIAL_ECHOPGM(" (0-10)");
SERIAL_ECHOLNPGM(".");
};
#if EXTRUDERS < 2
constexpr uint8_t tool_index = 0;
UNUSED(tool_index);
#else
const uint8_t tool_index = parser.intval('T', active_extruder);
if (tool_index >= EXTRUDERS) {
echo_value_oor('T', false);
return;
}
#endif
float &kref = planner.extruder_advance_K[E_INDEX_N(tool_index)], newK = kref;
const float oldK = newK;
#if ENABLED(ADVANCE_K_EXTRA)
float &lref = other_extruder_advance_K[E_INDEX_N(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 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
newK = lref; // Get new K value from backup
lref = oldK; // Save K to backup
}
// Set the main K value. Apply if the main slot is active.
if (parser.seenval('K')) {
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
}
// Set the extra K value. Apply if the extra slot is active.
if (parser.seenval('L')) {
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
}
#else
if (parser.seenval('K')) {
const float K = parser.value_float();
if (WITHIN(K, 0, 10))
newK = K;
else
echo_value_oor('K');
}
#endif
#if ENABLED(SMOOTH_LIN_ADV)
if (parser.seenval('U')) {
const float tau = parser.value_float();
if (WITHIN(tau, 0, .5)) {
planner.synchronize();
Stepper::set_advance_tau(tau);
}
else
echo_value_oor('U');
}
#endif
if (newK != oldK) {
planner.synchronize();
kref = newK;
}
if (!parser.seen_any()) {
#if ENABLED(ADVANCE_K_EXTRA)
#if DISTINCT_E < 2
SERIAL_ECHOLNPGM("Advance S", new_slot, " K", kref, "(S", !new_slot, " K", lref, ")");
#else
EXTRUDER_LOOP() {
const bool slot = TEST(lin_adv_slot, e);
SERIAL_ECHOLNPGM("Advance T", e, " S", slot, " K", planner.extruder_advance_K[e],
"(S", !slot, " K", other_extruder_advance_K[e], ")");
}
#endif
#else
SERIAL_ECHO_START();
#if DISTINCT_E < 2
SERIAL_ECHOLNPGM("Advance K=", planner.extruder_advance_K[0]);
#else
SERIAL_ECHOPGM("Advance K");
EXTRUDER_LOOP() SERIAL_ECHO(C(' '), C('0' + e), C(':'), planner.extruder_advance_K[e]);
SERIAL_EOL();
#endif
#if ENABLED(SMOOTH_LIN_ADV)
SERIAL_ECHOLNPGM("Advance TAU=", Stepper::get_advance_tau());
#endif
#endif
}
}
void GcodeSuite::M900_report(const bool forReplay/*=true*/) {
TERN_(MARLIN_SMALL_BUILD, return);
report_heading(forReplay, F(STR_LINEAR_ADVANCE));
#if DISTINCT_E < 2
report_echo_start(forReplay);
SERIAL_ECHOLNPGM(" M900 K", planner.extruder_advance_K[0]);
#else
EXTRUDER_LOOP() {
report_echo_start(forReplay);
SERIAL_ECHOLNPGM(" M900 T", e, " K", planner.extruder_advance_K[e]);
}
#endif
#if ENABLED(SMOOTH_LIN_ADV)
SERIAL_ECHOLNPGM(" M900 U", Stepper::get_advance_tau());
#endif
}
#endif // LIN_ADVANCE