Browse Source

Merge pull request #7802 from thinkyhead/bf2_fwretract_fixes

Fix G10/G11 with synchronize
Scott Lahteine 7 years ago
parent
commit
26d4c01660

+ 24
- 8
Marlin/src/feature/fwretract.cpp View File

30
 
30
 
31
 #include "fwretract.h"
31
 #include "fwretract.h"
32
 
32
 
33
-FWRetract fwretract; // Single instance
33
+FWRetract fwretract; // Single instance - this calls the constructor
34
 
34
 
35
 #include "../module/motion.h"
35
 #include "../module/motion.h"
36
 #include "../module/planner.h"
36
 #include "../module/planner.h"
37
+#include "../module/stepper.h"
38
+
39
+// private:
40
+
41
+#if EXTRUDERS > 1
42
+  bool FWRetract::retracted_swap[EXTRUDERS];         // Which extruders are swap-retracted
43
+#endif
44
+
45
+// public:
37
 
46
 
38
 bool FWRetract::autoretract_enabled,                 // M209 S - Autoretract switch
47
 bool FWRetract::autoretract_enabled,                 // M209 S - Autoretract switch
39
-     FWRetract::retracted[EXTRUDERS] = { false };    // Which extruders are currently retracted
48
+     FWRetract::retracted[EXTRUDERS];                // Which extruders are currently retracted
40
 float FWRetract::retract_length,                     // M207 S - G10 Retract length
49
 float FWRetract::retract_length,                     // M207 S - G10 Retract length
41
       FWRetract::retract_feedrate_mm_s,              // M207 F - G10 Retract feedrate
50
       FWRetract::retract_feedrate_mm_s,              // M207 F - G10 Retract feedrate
42
       FWRetract::retract_zlift,                      // M207 Z - G10 Retract hop size
51
       FWRetract::retract_zlift,                      // M207 Z - G10 Retract hop size
45
       FWRetract::swap_retract_length,                // M207 W - G10 Swap Retract length
54
       FWRetract::swap_retract_length,                // M207 W - G10 Swap Retract length
46
       FWRetract::swap_retract_recover_length,        // M208 W - G11 Swap Recover length
55
       FWRetract::swap_retract_recover_length,        // M208 W - G11 Swap Recover length
47
       FWRetract::swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
56
       FWRetract::swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
48
-#if EXTRUDERS > 1
49
-  bool FWRetract::retracted_swap[EXTRUDERS] = { false }; // Which extruders are swap-retracted
50
-#endif
51
 
57
 
52
 void FWRetract::reset() {
58
 void FWRetract::reset() {
53
   autoretract_enabled = false;
59
   autoretract_enabled = false;
59
   swap_retract_length = RETRACT_LENGTH_SWAP;
65
   swap_retract_length = RETRACT_LENGTH_SWAP;
60
   swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP;
66
   swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP;
61
   swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
67
   swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
68
+
69
+  for (uint8_t i = 0; i < EXTRUDERS; ++i) {
70
+    retracted[i] = false;
71
+    #if EXTRUDERS > 1
72
+      retracted_swap[i] = false;
73
+    #endif
74
+  }
62
 }
75
 }
63
 
76
 
64
 /**
77
 /**
87
   // Simply never allow two retracts or recovers in a row
100
   // Simply never allow two retracts or recovers in a row
88
   if (retracted[active_extruder] == retracting) return;
101
   if (retracted[active_extruder] == retracting) return;
89
 
102
 
90
-  #if EXTRUDERS < 2
91
-    bool swapping = false;
103
+  #if EXTRUDERS > 1
104
+    if (!retracting) swapping = retracted_swap[active_extruder];
105
+  #else
106
+    const bool swapping = false;
92
   #endif
107
   #endif
93
-  if (!retracting) swapping = retracted_swap[active_extruder];
94
 
108
 
95
   /* // debugging
109
   /* // debugging
96
     SERIAL_ECHOLNPAIR("retracting ", retracting);
110
     SERIAL_ECHOLNPAIR("retracting ", retracting);
117
   // The current position will be the destination for E and Z moves
131
   // The current position will be the destination for E and Z moves
118
   set_destination_to_current();
132
   set_destination_to_current();
119
 
133
 
134
+  stepper.synchronize();  // Wait for buffered moves to complete
135
+
120
   if (retracting) {
136
   if (retracting) {
121
     // Remember the Z height since G-code may include its own Z-hop
137
     // Remember the Z height since G-code may include its own Z-hop
122
     // For best results turn off Z hop if G-code already includes it
138
     // For best results turn off Z hop if G-code already includes it

+ 15
- 8
Marlin/src/feature/fwretract.h View File

30
 #include "../inc/MarlinConfig.h"
30
 #include "../inc/MarlinConfig.h"
31
 
31
 
32
 class FWRetract {
32
 class FWRetract {
33
+private:
34
+  #if EXTRUDERS > 1
35
+    static bool retracted_swap[EXTRUDERS];         // Which extruders are swap-retracted
36
+  #endif
37
+
33
 public:
38
 public:
34
   static bool autoretract_enabled,                 // M209 S - Autoretract switch
39
   static bool autoretract_enabled,                 // M209 S - Autoretract switch
35
               retracted[EXTRUDERS];                // Which extruders are currently retracted
40
               retracted[EXTRUDERS];                // Which extruders are currently retracted
42
                swap_retract_recover_length,        // M208 W - G11 Swap Recover length
47
                swap_retract_recover_length,        // M208 W - G11 Swap Recover length
43
                swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
48
                swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
44
 
49
 
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() {}
50
+  FWRetract() { reset(); }
52
 
51
 
53
   static void reset();
52
   static void reset();
54
 
53
 
54
+  static void refresh_autoretract() {
55
+    for (uint8_t i = 0; i < EXTRUDERS; i++) retracted[i] = false;
56
+  }
57
+
58
+  static void enable_autoretract(const bool enable) {
59
+    autoretract_enabled = enable;
60
+    refresh_autoretract();
61
+  }
62
+
55
   static void retract(const bool retracting
63
   static void retract(const bool retracting
56
     #if EXTRUDERS > 1
64
     #if EXTRUDERS > 1
57
       , bool swapping = false
65
       , bool swapping = false
58
     #endif
66
     #endif
59
   );
67
   );
60
-
61
 };
68
 };
62
 
69
 
63
 extern FWRetract fwretract;
70
 extern FWRetract fwretract;

+ 0
- 1
Marlin/src/gcode/feature/fwretract/G10_G11.cpp View File

34
 void GcodeSuite::G10() {
34
 void GcodeSuite::G10() {
35
   #if EXTRUDERS > 1
35
   #if EXTRUDERS > 1
36
     const bool rs = parser.boolval('S');
36
     const bool rs = parser.boolval('S');
37
-    fwretract.retracted_swap[active_extruder] = rs; // Use 'S' for swap, default to false
38
   #endif
37
   #endif
39
   fwretract.retract(true
38
   fwretract.retract(true
40
     #if EXTRUDERS > 1
39
     #if EXTRUDERS > 1

+ 1
- 2
Marlin/src/gcode/feature/fwretract/M207-M209.cpp View File

65
 void GcodeSuite::M209() {
65
 void GcodeSuite::M209() {
66
   if (MIN_AUTORETRACT <= MAX_AUTORETRACT) {
66
   if (MIN_AUTORETRACT <= MAX_AUTORETRACT) {
67
     if (parser.seen('S')) {
67
     if (parser.seen('S')) {
68
-      fwretract.autoretract_enabled = parser.value_bool();
69
-      for (uint8_t i = 0; i < EXTRUDERS; i++) fwretract.retracted[i] = false;
68
+      fwretract.enable_autoretract(parser.value_bool());
70
     }
69
     }
71
   }
70
   }
72
 }
71
 }

+ 1
- 1
Marlin/src/lcd/ultralcd.cpp View File

3557
     void lcd_control_retract_menu() {
3557
     void lcd_control_retract_menu() {
3558
       START_MENU();
3558
       START_MENU();
3559
       MENU_BACK(MSG_CONTROL);
3559
       MENU_BACK(MSG_CONTROL);
3560
-      MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled);
3560
+      MENU_ITEM_EDIT_CALLBACK(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled, fwretract.refresh_autoretract);
3561
       MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100);
3561
       MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100);
3562
       #if EXTRUDERS > 1
3562
       #if EXTRUDERS > 1
3563
         MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100);
3563
         MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100);

+ 4
- 0
Marlin/src/module/configuration_store.cpp View File

247
   #if HAS_MOTOR_CURRENT_PWM
247
   #if HAS_MOTOR_CURRENT_PWM
248
     stepper.refresh_motor_power();
248
     stepper.refresh_motor_power();
249
   #endif
249
   #endif
250
+
251
+  #if ENABLED(FWRETRACT)
252
+    fwretract.refresh_autoretract();
253
+  #endif
250
 }
254
 }
251
 
255
 
252
 #if ENABLED(EEPROM_SETTINGS)
256
 #if ENABLED(EEPROM_SETTINGS)

Loading…
Cancel
Save