瀏覽代碼

FWRETRACT as a feature

Scott Lahteine 6 年之前
父節點
當前提交
a98e9874db

+ 0
- 148
Marlin/src/Marlin.cpp 查看文件

@@ -272,24 +272,6 @@ static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL
272 272
           baricuda_e_to_p_pressure = 0;
273 273
 #endif
274 274
 
275
-#if ENABLED(FWRETRACT)                      // Initialized by settings.load()...
276
-  bool autoretract_enabled,                 // M209 S - Autoretract switch
277
-       retracted[EXTRUDERS] = { false };    // Which extruders are currently retracted
278
-  float retract_length,                     // M207 S - G10 Retract length
279
-        retract_feedrate_mm_s,              // M207 F - G10 Retract feedrate
280
-        retract_zlift,                      // M207 Z - G10 Retract hop size
281
-        retract_recover_length,             // M208 S - G11 Recover length
282
-        retract_recover_feedrate_mm_s,      // M208 F - G11 Recover feedrate
283
-        swap_retract_length,                // M207 W - G10 Swap Retract length
284
-        swap_retract_recover_length,        // M208 W - G11 Swap Recover length
285
-        swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
286
-  #if EXTRUDERS > 1
287
-    bool retracted_swap[EXTRUDERS] = { false }; // Which extruders are swap-retracted
288
-  #else
289
-    constexpr bool retracted_swap[1] = { false };
290
-  #endif
291
-#endif // FWRETRACT
292
-
293 275
 #if HAS_POWER_SWITCH
294 276
   bool powersupply_on =
295 277
     #if ENABLED(PS_DEFAULT_OFF)
@@ -2322,132 +2304,6 @@ static void homeaxis(const AxisEnum axis) {
2322 2304
   #endif
2323 2305
 } // homeaxis()
2324 2306
 
2325
-#if ENABLED(FWRETRACT)
2326
-
2327
-  /**
2328
-   * Retract or recover according to firmware settings
2329
-   *
2330
-   * This function handles retract/recover moves for G10 and G11,
2331
-   * plus auto-retract moves sent from G0/G1 when E-only moves are done.
2332
-   *
2333
-   * To simplify the logic, doubled retract/recover moves are ignored.
2334
-   *
2335
-   * Note: Z lift is done transparently to the planner. Aborting
2336
-   *       a print between G10 and G11 may corrupt the Z position.
2337
-   *
2338
-   * Note: Auto-retract will apply the set Z hop in addition to any Z hop
2339
-   *       included in the G-code. Use M207 Z0 to to prevent double hop.
2340
-   */
2341
-  void retract(const bool retracting
2342
-    #if EXTRUDERS > 1
2343
-      , bool swapping = false
2344
-    #endif
2345
-  ) {
2346
-
2347
-    static float hop_height,        // Remember where the Z height started
2348
-                 hop_amount = 0.0;  // Total amount lifted, for use in recover
2349
-
2350
-    // Simply never allow two retracts or recovers in a row
2351
-    if (retracted[active_extruder] == retracting) return;
2352
-
2353
-    #if EXTRUDERS < 2
2354
-      bool swapping = false;
2355
-    #endif
2356
-    if (!retracting) swapping = retracted_swap[active_extruder];
2357
-
2358
-    /* // debugging
2359
-      SERIAL_ECHOLNPAIR("retracting ", retracting);
2360
-      SERIAL_ECHOLNPAIR("swapping ", swapping);
2361
-      SERIAL_ECHOLNPAIR("active extruder ", active_extruder);
2362
-      for (uint8_t i = 0; i < EXTRUDERS; ++i) {
2363
-        SERIAL_ECHOPAIR("retracted[", i);
2364
-        SERIAL_ECHOLNPAIR("] ", retracted[i]);
2365
-        SERIAL_ECHOPAIR("retracted_swap[", i);
2366
-        SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
2367
-      }
2368
-      SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
2369
-      SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
2370
-    //*/
2371
-
2372
-    const bool has_zhop = retract_zlift > 0.01;     // Is there a hop set?
2373
-
2374
-    const float old_feedrate_mm_s = feedrate_mm_s;
2375
-    const int16_t old_flow = flow_percentage[active_extruder];
2376
-
2377
-    // Don't apply flow multiplication to retract/recover
2378
-    flow_percentage[active_extruder] = 100;
2379
-
2380
-    // The current position will be the destination for E and Z moves
2381
-    set_destination_to_current();
2382
-
2383
-    if (retracting) {
2384
-      // Remember the Z height since G-code may include its own Z-hop
2385
-      // For best results turn off Z hop if G-code already includes it
2386
-      hop_height = destination[Z_AXIS];
2387
-
2388
-      // Retract by moving from a faux E position back to the current E position
2389
-      feedrate_mm_s = retract_feedrate_mm_s;
2390
-      current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) / volumetric_multiplier[active_extruder];
2391
-      sync_plan_position_e();
2392
-      prepare_move_to_destination();
2393
-
2394
-      // Is a Z hop set, and has the hop not yet been done?
2395
-      if (has_zhop) {
2396
-        hop_amount += retract_zlift;                // Carriage is raised for retraction hop
2397
-        current_position[Z_AXIS] -= retract_zlift;  // Pretend current pos is lower. Next move raises Z.
2398
-        SYNC_PLAN_POSITION_KINEMATIC();             // Set the planner to the new position
2399
-        prepare_move_to_destination();              // Raise up to the old current pos
2400
-      }
2401
-    }
2402
-    else {
2403
-      // If a hop was done and Z hasn't changed, undo the Z hop
2404
-      if (hop_amount && NEAR(hop_height, destination[Z_AXIS])) {
2405
-        current_position[Z_AXIS] += hop_amount;     // Pretend current pos is higher. Next move lowers Z.
2406
-        SYNC_PLAN_POSITION_KINEMATIC();             // Set the planner to the new position
2407
-        prepare_move_to_destination();              // Lower to the old current pos
2408
-        hop_amount = 0.0;
2409
-      }
2410
-
2411
-      // A retract multiplier has been added here to get faster swap recovery
2412
-      feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
2413
-
2414
-      const float move_e = swapping ? swap_retract_length + swap_retract_recover_length : retract_length + retract_recover_length;
2415
-      current_position[E_AXIS] -= move_e / volumetric_multiplier[active_extruder];
2416
-      sync_plan_position_e();
2417
-
2418
-      prepare_move_to_destination();  // Recover E
2419
-    }
2420
-
2421
-    // Restore flow and feedrate
2422
-    flow_percentage[active_extruder] = old_flow;
2423
-    feedrate_mm_s = old_feedrate_mm_s;
2424
-
2425
-    // The active extruder is now retracted or recovered
2426
-    retracted[active_extruder] = retracting;
2427
-
2428
-    // If swap retract/recover then update the retracted_swap flag too
2429
-    #if EXTRUDERS > 1
2430
-      if (swapping) retracted_swap[active_extruder] = retracting;
2431
-    #endif
2432
-
2433
-    /* // debugging
2434
-      SERIAL_ECHOLNPAIR("retracting ", retracting);
2435
-      SERIAL_ECHOLNPAIR("swapping ", swapping);
2436
-      SERIAL_ECHOLNPAIR("active_extruder ", active_extruder);
2437
-      for (uint8_t i = 0; i < EXTRUDERS; ++i) {
2438
-        SERIAL_ECHOPAIR("retracted[", i);
2439
-        SERIAL_ECHOLNPAIR("] ", retracted[i]);
2440
-        SERIAL_ECHOPAIR("retracted_swap[", i);
2441
-        SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
2442
-      }
2443
-      SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
2444
-      SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
2445
-    //*/
2446
-
2447
-  } // retract()
2448
-
2449
-#endif // FWRETRACT
2450
-
2451 2307
 #if ENABLED(MIXING_EXTRUDER)
2452 2308
 
2453 2309
   void normalize_mix() {
@@ -2547,10 +2403,6 @@ void dwell(millis_t time) {
2547 2403
   #include "gcode/motion/G5.h"
2548 2404
 #endif
2549 2405
 
2550
-#if ENABLED(FWRETRACT)
2551
-  #include "gcode/feature/fwretract/G10_G11.h"
2552
-#endif
2553
-
2554 2406
 #if ENABLED(NOZZLE_CLEAN_FEATURE)
2555 2407
   #include "gcode/feature/clean/G12.h"
2556 2408
 #endif

+ 0
- 12
Marlin/src/Marlin.h 查看文件

@@ -302,18 +302,6 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
302 302
   extern int lpq_len;
303 303
 #endif
304 304
 
305
-#if ENABLED(FWRETRACT)
306
-  extern bool autoretract_enabled;                 // M209 S - Autoretract switch
307
-  extern float retract_length,                     // M207 S - G10 Retract length
308
-               retract_feedrate_mm_s,              // M207 F - G10 Retract feedrate
309
-               retract_zlift,                      // M207 Z - G10 Retract hop size
310
-               retract_recover_length,             // M208 S - G11 Recover length
311
-               retract_recover_feedrate_mm_s,      // M208 F - G11 Recover feedrate
312
-               swap_retract_length,                // M207 W - G10 Swap Retract length
313
-               swap_retract_recover_length,        // M208 W - G11 Swap Recover length
314
-               swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
315
-#endif
316
-
317 305
 // Print job timer
318 306
 #if ENABLED(PRINTCOUNTER)
319 307
   extern PrintCounter print_job_timer;

+ 185
- 0
Marlin/src/feature/fwretract.cpp 查看文件

@@ -0,0 +1,185 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * fwretract.cpp - Implement firmware-based retraction
25
+ */
26
+
27
+#include "../inc/MarlinConfig.h"
28
+
29
+#if ENABLED(FWRETRACT)
30
+
31
+#include "fwretract.h"
32
+
33
+FWRetract fwretract; // Single instance
34
+
35
+#include "../module/motion.h"
36
+
37
+bool FWRetract::autoretract_enabled,                 // M209 S - Autoretract switch
38
+     FWRetract::retracted[EXTRUDERS] = { false };    // Which extruders are currently retracted
39
+float FWRetract::retract_length,                     // M207 S - G10 Retract length
40
+      FWRetract::retract_feedrate_mm_s,              // M207 F - G10 Retract feedrate
41
+      FWRetract::retract_zlift,                      // M207 Z - G10 Retract hop size
42
+      FWRetract::retract_recover_length,             // M208 S - G11 Recover length
43
+      FWRetract::retract_recover_feedrate_mm_s,      // M208 F - G11 Recover feedrate
44
+      FWRetract::swap_retract_length,                // M207 W - G10 Swap Retract length
45
+      FWRetract::swap_retract_recover_length,        // M208 W - G11 Swap Recover length
46
+      FWRetract::swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
47
+#if EXTRUDERS > 1
48
+  bool FWRetract::retracted_swap[EXTRUDERS] = { false }; // Which extruders are swap-retracted
49
+#endif
50
+
51
+void FWRetract::reset() {
52
+  autoretract_enabled = false;
53
+  retract_length = RETRACT_LENGTH;
54
+  retract_feedrate_mm_s = RETRACT_FEEDRATE;
55
+  retract_zlift = RETRACT_ZLIFT;
56
+  retract_recover_length = RETRACT_RECOVER_LENGTH;
57
+  retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE;
58
+  swap_retract_length = RETRACT_LENGTH_SWAP;
59
+  swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP;
60
+  swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
61
+}
62
+
63
+/**
64
+ * Retract or recover according to firmware settings
65
+ *
66
+ * This function handles retract/recover moves for G10 and G11,
67
+ * plus auto-retract moves sent from G0/G1 when E-only moves are done.
68
+ *
69
+ * To simplify the logic, doubled retract/recover moves are ignored.
70
+ *
71
+ * Note: Z lift is done transparently to the planner. Aborting
72
+ *       a print between G10 and G11 may corrupt the Z position.
73
+ *
74
+ * Note: Auto-retract will apply the set Z hop in addition to any Z hop
75
+ *       included in the G-code. Use M207 Z0 to to prevent double hop.
76
+ */
77
+void FWRetract::retract(const bool retracting
78
+  #if EXTRUDERS > 1
79
+    , bool swapping /* =false */
80
+  #endif
81
+) {
82
+
83
+  static float hop_height,        // Remember where the Z height started
84
+               hop_amount = 0.0;  // Total amount lifted, for use in recover
85
+
86
+  // Simply never allow two retracts or recovers in a row
87
+  if (retracted[active_extruder] == retracting) return;
88
+
89
+  #if EXTRUDERS < 2
90
+    bool swapping = false;
91
+  #endif
92
+  if (!retracting) swapping = retracted_swap[active_extruder];
93
+
94
+  /* // debugging
95
+    SERIAL_ECHOLNPAIR("retracting ", retracting);
96
+    SERIAL_ECHOLNPAIR("swapping ", swapping);
97
+    SERIAL_ECHOLNPAIR("active extruder ", active_extruder);
98
+    for (uint8_t i = 0; i < EXTRUDERS; ++i) {
99
+      SERIAL_ECHOPAIR("retracted[", i);
100
+      SERIAL_ECHOLNPAIR("] ", retracted[i]);
101
+      SERIAL_ECHOPAIR("retracted_swap[", i);
102
+      SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
103
+    }
104
+    SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
105
+    SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
106
+  //*/
107
+
108
+  const bool has_zhop = retract_zlift > 0.01;     // Is there a hop set?
109
+
110
+  const float old_feedrate_mm_s = feedrate_mm_s;
111
+  const int16_t old_flow = flow_percentage[active_extruder];
112
+
113
+  // Don't apply flow multiplication to retract/recover
114
+  flow_percentage[active_extruder] = 100;
115
+
116
+  // The current position will be the destination for E and Z moves
117
+  set_destination_to_current();
118
+
119
+  if (retracting) {
120
+    // Remember the Z height since G-code may include its own Z-hop
121
+    // For best results turn off Z hop if G-code already includes it
122
+    hop_height = destination[Z_AXIS];
123
+
124
+    // Retract by moving from a faux E position back to the current E position
125
+    feedrate_mm_s = retract_feedrate_mm_s;
126
+    current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) / volumetric_multiplier[active_extruder];
127
+    sync_plan_position_e();
128
+    prepare_move_to_destination();
129
+
130
+    // Is a Z hop set, and has the hop not yet been done?
131
+    if (has_zhop) {
132
+      hop_amount += retract_zlift;                // Carriage is raised for retraction hop
133
+      current_position[Z_AXIS] -= retract_zlift;  // Pretend current pos is lower. Next move raises Z.
134
+      SYNC_PLAN_POSITION_KINEMATIC();             // Set the planner to the new position
135
+      prepare_move_to_destination();              // Raise up to the old current pos
136
+    }
137
+  }
138
+  else {
139
+    // If a hop was done and Z hasn't changed, undo the Z hop
140
+    if (hop_amount && NEAR(hop_height, destination[Z_AXIS])) {
141
+      current_position[Z_AXIS] += hop_amount;     // Pretend current pos is higher. Next move lowers Z.
142
+      SYNC_PLAN_POSITION_KINEMATIC();             // Set the planner to the new position
143
+      prepare_move_to_destination();              // Lower to the old current pos
144
+      hop_amount = 0.0;
145
+    }
146
+
147
+    // A retract multiplier has been added here to get faster swap recovery
148
+    feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
149
+
150
+    const float move_e = swapping ? swap_retract_length + swap_retract_recover_length : retract_length + retract_recover_length;
151
+    current_position[E_AXIS] -= move_e / volumetric_multiplier[active_extruder];
152
+    sync_plan_position_e();
153
+
154
+    prepare_move_to_destination();  // Recover E
155
+  }
156
+
157
+  // Restore flow and feedrate
158
+  flow_percentage[active_extruder] = old_flow;
159
+  feedrate_mm_s = old_feedrate_mm_s;
160
+
161
+  // The active extruder is now retracted or recovered
162
+  retracted[active_extruder] = retracting;
163
+
164
+  // If swap retract/recover then update the retracted_swap flag too
165
+  #if EXTRUDERS > 1
166
+    if (swapping) retracted_swap[active_extruder] = retracting;
167
+  #endif
168
+
169
+  /* // debugging
170
+    SERIAL_ECHOLNPAIR("retracting ", retracting);
171
+    SERIAL_ECHOLNPAIR("swapping ", swapping);
172
+    SERIAL_ECHOLNPAIR("active_extruder ", active_extruder);
173
+    for (uint8_t i = 0; i < EXTRUDERS; ++i) {
174
+      SERIAL_ECHOPAIR("retracted[", i);
175
+      SERIAL_ECHOLNPAIR("] ", retracted[i]);
176
+      SERIAL_ECHOPAIR("retracted_swap[", i);
177
+      SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
178
+    }
179
+    SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
180
+    SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
181
+  //*/
182
+
183
+} // retract()
184
+
185
+#endif // FWRETRACT

+ 65
- 0
Marlin/src/feature/fwretract.h 查看文件

@@ -0,0 +1,65 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * fwretract.h - Define firmware-based retraction interface
25
+ */
26
+
27
+#ifndef FWRETRACT_H
28
+#define FWRETRACT_H
29
+
30
+#include "../inc/MarlinConfig.h"
31
+
32
+class FWRetract {
33
+public:
34
+  static bool autoretract_enabled,                 // M209 S - Autoretract switch
35
+              retracted[EXTRUDERS];                // Which extruders are currently retracted
36
+  static float retract_length,                     // M207 S - G10 Retract length
37
+               retract_feedrate_mm_s,              // M207 F - G10 Retract feedrate
38
+               retract_zlift,                      // M207 Z - G10 Retract hop size
39
+               retract_recover_length,             // M208 S - G11 Recover length
40
+               retract_recover_feedrate_mm_s,      // M208 F - G11 Recover feedrate
41
+               swap_retract_length,                // M207 W - G10 Swap Retract length
42
+               swap_retract_recover_length,        // M208 W - G11 Swap Recover length
43
+               swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
44
+
45
+  #if EXTRUDERS > 1
46
+    static bool retracted_swap[EXTRUDERS];         // Which extruders are swap-retracted
47
+  #else
48
+    static bool constexpr retracted_swap[1] = { false };
49
+  #endif
50
+
51
+  FWRetract() {}
52
+
53
+  static void reset();
54
+
55
+  static void retract(const bool retracting
56
+    #if EXTRUDERS > 1
57
+      , bool swapping = false
58
+    #endif
59
+  );
60
+
61
+};
62
+
63
+extern FWRetract fwretract;
64
+
65
+#endif // FWRETRACT_H

Marlin/src/gcode/feature/fwretract/G10_G11.h → Marlin/src/gcode/feature/fwretract/G10_G11.cpp 查看文件

@@ -20,15 +20,23 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(FWRETRACT)
26
+
27
+#include "../../../feature/fwretract.h"
28
+#include "../../gcode.h"
29
+#include "../../../module/motion.h"
30
+
23 31
 /**
24 32
  * G10 - Retract filament according to settings of M207
25 33
  */
26
-void gcode_G10() {
34
+void GcodeSuite::G10() {
27 35
   #if EXTRUDERS > 1
28 36
     const bool rs = parser.boolval('S');
29
-    retracted_swap[active_extruder] = rs; // Use 'S' for swap, default to false
37
+    fwretract.retracted_swap[active_extruder] = rs; // Use 'S' for swap, default to false
30 38
   #endif
31
-  retract(true
39
+  fwretract.retract(true
32 40
     #if EXTRUDERS > 1
33 41
       , rs
34 42
     #endif
@@ -38,4 +46,6 @@ void gcode_G10() {
38 46
 /**
39 47
  * G11 - Recover filament according to settings of M208
40 48
  */
41
-void gcode_G11() { retract(false); }
49
+void GcodeSuite::G11() { fwretract.retract(false); }
50
+
51
+#endif // FWRETRACT

Marlin/src/gcode/feature/fwretract/M207.h → Marlin/src/gcode/feature/fwretract/M207.cpp 查看文件

@@ -20,6 +20,13 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(FWRETRACT)
26
+
27
+#include "../../../feature/fwretract.h"
28
+#include "../../gcode.h"
29
+
23 30
 /**
24 31
  * M207: Set firmware retraction values
25 32
  *
@@ -28,9 +35,11 @@
28 35
  *   F[units/min] retract_feedrate_mm_s
29 36
  *   Z[units]     retract_zlift
30 37
  */
31
-void gcode_M207() {
32
-  if (parser.seen('S')) retract_length = parser.value_axis_units(E_AXIS);
33
-  if (parser.seen('F')) retract_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
34
-  if (parser.seen('Z')) retract_zlift = parser.value_linear_units();
35
-  if (parser.seen('W')) swap_retract_length = parser.value_axis_units(E_AXIS);
38
+void GcodeSuite::M207() {
39
+  if (parser.seen('S')) fwretract.retract_length = parser.value_axis_units(E_AXIS);
40
+  if (parser.seen('F')) fwretract.retract_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
41
+  if (parser.seen('Z')) fwretract.retract_zlift = parser.value_linear_units();
42
+  if (parser.seen('W')) fwretract.swap_retract_length = parser.value_axis_units(E_AXIS);
36 43
 }
44
+
45
+#endif // FWRETRACT

Marlin/src/gcode/feature/fwretract/M208.h → Marlin/src/gcode/feature/fwretract/M208.cpp 查看文件

@@ -20,6 +20,13 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(FWRETRACT)
26
+
27
+#include "../../../feature/fwretract.h"
28
+#include "../../gcode.h"
29
+
23 30
 /**
24 31
  * M208: Set firmware un-retraction values
25 32
  *
@@ -28,9 +35,11 @@
28 35
  *   F[units/min] retract_recover_feedrate_mm_s
29 36
  *   R[units/min] swap_retract_recover_feedrate_mm_s
30 37
  */
31
-void gcode_M208() {
32
-  if (parser.seen('S')) retract_recover_length = parser.value_axis_units(E_AXIS);
33
-  if (parser.seen('F')) retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
34
-  if (parser.seen('R')) swap_retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
35
-  if (parser.seen('W')) swap_retract_recover_length = parser.value_axis_units(E_AXIS);
38
+void GcodeSuite::M208() {
39
+  if (parser.seen('S')) fwretract.retract_recover_length = parser.value_axis_units(E_AXIS);
40
+  if (parser.seen('F')) fwretract.retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
41
+  if (parser.seen('R')) fwretract.swap_retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
42
+  if (parser.seen('W')) fwretract.swap_retract_recover_length = parser.value_axis_units(E_AXIS);
36 43
 }
44
+
45
+#endif // FWRETRACT

Marlin/src/gcode/feature/fwretract/M209.h → Marlin/src/gcode/feature/fwretract/M209.cpp 查看文件

@@ -20,16 +20,25 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(FWRETRACT)
26
+
27
+#include "../../../feature/fwretract.h"
28
+#include "../../gcode.h"
29
+
23 30
 /**
24 31
  * M209: Enable automatic retract (M209 S1)
25 32
  *   For slicers that don't support G10/11, reversed extrude-only
26 33
  *   moves will be classified as retraction.
27 34
  */
28
-void gcode_M209() {
35
+void GcodeSuite::M209() {
29 36
   if (MIN_AUTORETRACT <= MAX_AUTORETRACT) {
30 37
     if (parser.seen('S')) {
31
-      autoretract_enabled = parser.value_bool();
32
-      for (uint8_t i = 0; i < EXTRUDERS; i++) retracted[i] = false;
38
+      fwretract.autoretract_enabled = parser.value_bool();
39
+      for (uint8_t i = 0; i < EXTRUDERS; i++) fwretract.retracted[i] = false;
33 40
     }
34 41
   }
35 42
 }
43
+
44
+#endif // FWRETRACT

+ 4
- 10
Marlin/src/gcode/gcode.cpp 查看文件

@@ -754,16 +754,10 @@ void GcodeSuite::process_next_command() {
754 754
       #endif
755 755
 
756 756
       #if ENABLED(FWRETRACT)
757
-        case 207: // M207: Set Retract Length, Feedrate, and Z lift
758
-          M207();
759
-          break;
760
-        case 208: // M208: Set Recover (unretract) Additional Length and Feedrate
761
-          M208();
762
-          break;
763
-        case 209: // M209: Turn Automatic Retract Detection on/off
764
-          if (MIN_AUTORETRACT <= MAX_AUTORETRACT) M209();
765
-          break;
766
-      #endif // FWRETRACT
757
+        case 207: M207(); break;  // M207: Set Retract Length, Feedrate, and Z lift
758
+        case 208: M208(); break;  // M208: Set Recover (unretract) Additional Length and Feedrate
759
+        case 209: if (MIN_AUTORETRACT <= MAX_AUTORETRACT) M209(); break;  // M209: Turn Automatic Retract Detection on/off
760
+      #endif
767 761
 
768 762
       case 211: // M211: Enable, Disable, and/or Report software endstops
769 763
         gcode_M211();

+ 9
- 3
Marlin/src/gcode/motion/G0_G1.cpp 查看文件

@@ -25,6 +25,10 @@
25 25
 
26 26
 #include "../../Marlin.h"
27 27
 
28
+#if ENABLED(FWRETRACT)
29
+  #include "../../feature/fwretract.h"
30
+#endif
31
+
28 32
 #include "../../sd/cardreader.h"
29 33
 
30 34
 extern float destination[XYZE];
@@ -41,18 +45,20 @@ void GcodeSuite::G0_G1(
41 45
     get_destination_from_command(); // For X Y Z E F
42 46
 
43 47
     #if ENABLED(FWRETRACT)
48
+
44 49
       if (MIN_AUTORETRACT <= MAX_AUTORETRACT) {
45 50
         // When M209 Autoretract is enabled, convert E-only moves to firmware retract/recover moves
46
-        if (autoretract_enabled && parser.seen('E') && !(parser.seen('X') || parser.seen('Y') || parser.seen('Z'))) {
51
+        if (fwretract.autoretract_enabled && parser.seen('E') && !(parser.seen('X') || parser.seen('Y') || parser.seen('Z'))) {
47 52
           const float echange = destination[E_AXIS] - current_position[E_AXIS];
48 53
           // Is this a retract or recover move?
49
-          if (WITHIN(FABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && retracted[active_extruder] == (echange > 0.0)) {
54
+          if (WITHIN(FABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[active_extruder] == (echange > 0.0)) {
50 55
             current_position[E_AXIS] = destination[E_AXIS]; // Hide a G1-based retract/recover from calculations
51 56
             sync_plan_position_e();                         // AND from the planner
52
-            return retract(echange < 0.0);                  // Firmware-based retract/recover (double-retract ignored)
57
+            return fwretract.retract(echange < 0.0);        // Firmware-based retract/recover (double-retract ignored)
53 58
           }
54 59
         }
55 60
       }
61
+
56 62
     #endif // FWRETRACT
57 63
 
58 64
     #if IS_SCARA

+ 9
- 8
Marlin/src/lcd/ultralcd.cpp 查看文件

@@ -164,6 +164,7 @@ uint16_t max_display_update_time = 0;
164 164
   #endif
165 165
 
166 166
   #if ENABLED(FWRETRACT)
167
+    #include "../feature/fwretract.h"
167 168
     void lcd_control_retract_menu();
168 169
   #endif
169 170
 
@@ -3477,18 +3478,18 @@ void kill_screen(const char* lcd_msg) {
3477 3478
     void lcd_control_retract_menu() {
3478 3479
       START_MENU();
3479 3480
       MENU_BACK(MSG_CONTROL);
3480
-      MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
3481
-      MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
3481
+      MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled);
3482
+      MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100);
3482 3483
       #if EXTRUDERS > 1
3483
-        MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &swap_retract_length, 0, 100);
3484
+        MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100);
3484 3485
       #endif
3485
-      MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
3486
-      MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
3487
-      MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
3486
+      MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &fwretract.retract_feedrate_mm_s, 1, 999);
3487
+      MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &fwretract.retract_zlift, 0, 999);
3488
+      MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &fwretract.retract_recover_length, -100, 100);
3488 3489
       #if EXTRUDERS > 1
3489
-        MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &swap_retract_recover_length, -100, 100);
3490
+        MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &fwretract.swap_retract_recover_length, -100, 100);
3490 3491
       #endif
3491
-      MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
3492
+      MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &fwretract.retract_recover_feedrate_mm_s, 1, 999);
3492 3493
       END_MENU();
3493 3494
     }
3494 3495
 

+ 36
- 44
Marlin/src/module/configuration_store.cpp 查看文件

@@ -205,6 +205,10 @@ MarlinSettings settings;
205 205
   extern void refresh_bed_level();
206 206
 #endif
207 207
 
208
+#if ENABLED(FWRETRACT)
209
+  #include "../gcode/feature/fwretract/fwretract.h"
210
+#endif
211
+
208 212
 /**
209 213
  * Post-process after Retrieve or Reset
210 214
  */
@@ -492,24 +496,20 @@ void MarlinSettings::postprocess() {
492 496
 
493 497
     #if DISABLED(FWRETRACT)
494 498
       const bool autoretract_enabled = false;
495
-      const float retract_length = 3,
496
-                  retract_feedrate_mm_s = 45,
497
-                  retract_zlift = 0,
498
-                  retract_recover_length = 0,
499
-                  retract_recover_feedrate_mm_s = 0,
500
-                  swap_retract_length = 13,
501
-                  swap_retract_recover_length = 0,
502
-                  swap_retract_recover_feedrate_mm_s = 8;
499
+      const float autoretract_defaults[] = { 3, 45, 0, 0, 0, 13, 0, 8 };
500
+      EEPROM_WRITE(autoretract_enabled);
501
+      EEPROM_WRITE(autoretract_defaults);
502
+    #else
503
+      EEPROM_WRITE(fwretract.autoretract_enabled);
504
+      EEPROM_WRITE(fwretract.retract_length);
505
+      EEPROM_WRITE(fwretract.retract_feedrate_mm_s);
506
+      EEPROM_WRITE(fwretract.retract_zlift);
507
+      EEPROM_WRITE(fwretract.retract_recover_length);
508
+      EEPROM_WRITE(fwretract.retract_recover_feedrate_mm_s);
509
+      EEPROM_WRITE(fwretract.swap_retract_length);
510
+      EEPROM_WRITE(fwretract.swap_retract_recover_length);
511
+      EEPROM_WRITE(fwretract.swap_retract_recover_feedrate_mm_s);
503 512
     #endif
504
-    EEPROM_WRITE(autoretract_enabled);
505
-    EEPROM_WRITE(retract_length);
506
-    EEPROM_WRITE(retract_feedrate_mm_s);
507
-    EEPROM_WRITE(retract_zlift);
508
-    EEPROM_WRITE(retract_recover_length);
509
-    EEPROM_WRITE(retract_recover_feedrate_mm_s);
510
-    EEPROM_WRITE(swap_retract_length);
511
-    EEPROM_WRITE(swap_retract_recover_length);
512
-    EEPROM_WRITE(swap_retract_recover_feedrate_mm_s);
513 513
 
514 514
     EEPROM_WRITE(volumetric_enabled);
515 515
 
@@ -883,15 +883,15 @@ void MarlinSettings::postprocess() {
883 883
       EEPROM_READ(lcd_contrast);
884 884
 
885 885
       #if ENABLED(FWRETRACT)
886
-        EEPROM_READ(autoretract_enabled);
887
-        EEPROM_READ(retract_length);
888
-        EEPROM_READ(retract_feedrate_mm_s);
889
-        EEPROM_READ(retract_zlift);
890
-        EEPROM_READ(retract_recover_length);
891
-        EEPROM_READ(retract_recover_feedrate_mm_s);
892
-        EEPROM_READ(swap_retract_length);
893
-        EEPROM_READ(swap_retract_recover_length);
894
-        EEPROM_READ(swap_retract_recover_feedrate_mm_s);
886
+        EEPROM_READ(fwretract.autoretract_enabled);
887
+        EEPROM_READ(fwretract.retract_length);
888
+        EEPROM_READ(fwretract.retract_feedrate_mm_s);
889
+        EEPROM_READ(fwretract.retract_zlift);
890
+        EEPROM_READ(fwretract.retract_recover_length);
891
+        EEPROM_READ(fwretract.retract_recover_feedrate_mm_s);
892
+        EEPROM_READ(fwretract.swap_retract_length);
893
+        EEPROM_READ(fwretract.swap_retract_recover_length);
894
+        EEPROM_READ(fwretract.swap_retract_recover_feedrate_mm_s);
895 895
       #else
896 896
         EEPROM_READ(dummyb);
897 897
         for (uint8_t q=8; q--;) EEPROM_READ(dummy);
@@ -1256,16 +1256,8 @@ void MarlinSettings::reset() {
1256 1256
   #endif
1257 1257
 
1258 1258
   #if ENABLED(FWRETRACT)
1259
-    autoretract_enabled = false;
1260
-    retract_length = RETRACT_LENGTH;
1261
-    retract_feedrate_mm_s = RETRACT_FEEDRATE;
1262
-    retract_zlift = RETRACT_ZLIFT;
1263
-    retract_recover_length = RETRACT_RECOVER_LENGTH;
1264
-    retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE;
1265
-    swap_retract_length = RETRACT_LENGTH_SWAP;
1266
-    swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP;
1267
-    swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
1268
-  #endif // FWRETRACT
1259
+    fwretract.reset();
1260
+  #endif
1269 1261
 
1270 1262
   volumetric_enabled =
1271 1263
     #if ENABLED(VOLUMETRIC_DEFAULT_ON)
@@ -1716,26 +1708,26 @@ void MarlinSettings::reset() {
1716 1708
         SERIAL_ECHOLNPGM("Retract: S<length> F<units/m> Z<lift>");
1717 1709
       }
1718 1710
       CONFIG_ECHO_START;
1719
-      SERIAL_ECHOPAIR("  M207 S", LINEAR_UNIT(retract_length));
1720
-      SERIAL_ECHOPAIR(" W", LINEAR_UNIT(swap_retract_length));
1721
-      SERIAL_ECHOPAIR(" F", MMS_TO_MMM(LINEAR_UNIT(retract_feedrate_mm_s)));
1722
-      SERIAL_ECHOLNPAIR(" Z", LINEAR_UNIT(retract_zlift));
1711
+      SERIAL_ECHOPAIR("  M207 S", LINEAR_UNIT(fwretract.retract_length));
1712
+      SERIAL_ECHOPAIR(" W", LINEAR_UNIT(fwretract.swap_retract_length));
1713
+      SERIAL_ECHOPAIR(" F", MMS_TO_MMM(LINEAR_UNIT(fwretract.retract_feedrate_mm_s)));
1714
+      SERIAL_ECHOLNPAIR(" Z", LINEAR_UNIT(fwretract.retract_zlift));
1723 1715
 
1724 1716
       if (!forReplay) {
1725 1717
         CONFIG_ECHO_START;
1726 1718
         SERIAL_ECHOLNPGM("Recover: S<length> F<units/m>");
1727 1719
       }
1728 1720
       CONFIG_ECHO_START;
1729
-      SERIAL_ECHOPAIR("  M208 S", LINEAR_UNIT(retract_recover_length));
1730
-      SERIAL_ECHOPAIR(" W", LINEAR_UNIT(swap_retract_recover_length));
1731
-      SERIAL_ECHOLNPAIR(" F", MMS_TO_MMM(LINEAR_UNIT(retract_recover_feedrate_mm_s)));
1721
+      SERIAL_ECHOPAIR("  M208 S", LINEAR_UNIT(fwretract.retract_recover_length));
1722
+      SERIAL_ECHOPAIR(" W", LINEAR_UNIT(fwretract.swap_retract_recover_length));
1723
+      SERIAL_ECHOLNPAIR(" F", MMS_TO_MMM(LINEAR_UNIT(fwretract.retract_recover_feedrate_mm_s)));
1732 1724
 
1733 1725
       if (!forReplay) {
1734 1726
         CONFIG_ECHO_START;
1735 1727
         SERIAL_ECHOLNPGM("Auto-Retract: S=0 to disable, 1 to interpret E-only moves as retract/recover");
1736 1728
       }
1737 1729
       CONFIG_ECHO_START;
1738
-      SERIAL_ECHOLNPAIR("  M209 S", autoretract_enabled ? 1 : 0);
1730
+      SERIAL_ECHOLNPAIR("  M209 S", fwretract.autoretract_enabled ? 1 : 0);
1739 1731
 
1740 1732
     #endif // FWRETRACT
1741 1733
 

Loading…
取消
儲存