Browse Source

Clarify solenoid active / magnet-on state

Scott Lahteine 4 years ago
parent
commit
c0a3931595
2 changed files with 17 additions and 20 deletions
  1. 14
    17
      Marlin/src/module/tool_change.cpp
  2. 3
    3
      Marlin/src/module/tool_change.h

+ 14
- 17
Marlin/src/module/tool_change.cpp View File

259
 #elif ENABLED(PARKING_EXTRUDER)
259
 #elif ENABLED(PARKING_EXTRUDER)
260
 
260
 
261
   void pe_solenoid_init() {
261
   void pe_solenoid_init() {
262
-    LOOP_LE_N(n, 1)
263
-      TERN(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid, pe_deactivate_solenoid)(n);
262
+    LOOP_LE_N(n, 1) pe_solenoid_set_pin_state(n, !PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE);
264
   }
263
   }
265
 
264
 
266
-  void pe_set_solenoid(const uint8_t extruder_num, const uint8_t state) {
265
+  void pe_solenoid_set_pin_state(const uint8_t extruder_num, const uint8_t state) {
267
     switch (extruder_num) {
266
     switch (extruder_num) {
268
       case 1: OUT_WRITE(SOL1_PIN, state); break;
267
       case 1: OUT_WRITE(SOL1_PIN, state); break;
269
       default: OUT_WRITE(SOL0_PIN, state); break;
268
       default: OUT_WRITE(SOL0_PIN, state); break;
282
     if (!extruder_parked) return false; // nothing to do
281
     if (!extruder_parked) return false; // nothing to do
283
 
282
 
284
     if (homed_towards_final_tool) {
283
     if (homed_towards_final_tool) {
285
-      pe_deactivate_solenoid(1 - final_tool);
284
+      pe_solenoid_magnet_off(1 - final_tool);
286
       DEBUG_ECHOLNPAIR("Disengage magnet", (int)(1 - final_tool));
285
       DEBUG_ECHOLNPAIR("Disengage magnet", (int)(1 - final_tool));
287
-      pe_activate_solenoid(final_tool);
286
+      pe_solenoid_magnet_on(final_tool);
288
       DEBUG_ECHOLNPAIR("Engage magnet", (int)final_tool);
287
       DEBUG_ECHOLNPAIR("Engage magnet", (int)final_tool);
289
-      extruder_parked = false;
288
+      parking_extruder_set_parked(false);
290
       return false;
289
       return false;
291
     }
290
     }
292
 
291
 
335
 
334
 
336
         planner.synchronize();
335
         planner.synchronize();
337
         DEBUG_ECHOLNPGM("(2) Disengage magnet");
336
         DEBUG_ECHOLNPGM("(2) Disengage magnet");
338
-        pe_deactivate_solenoid(active_extruder);
337
+        pe_solenoid_magnet_off(active_extruder);
339
 
338
 
340
         // STEP 3
339
         // STEP 3
341
 
340
 
353
       DEBUG_ECHOLNPGM("(4) Engage magnetic field");
352
       DEBUG_ECHOLNPGM("(4) Engage magnetic field");
354
 
353
 
355
       // Just save power for inverted magnets
354
       // Just save power for inverted magnets
356
-      TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid(active_extruder));
357
-      pe_activate_solenoid(new_tool);
355
+      TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_solenoid_magnet_on(active_extruder));
356
+      pe_solenoid_magnet_on(new_tool);
358
 
357
 
359
       // STEP 5
358
       // STEP 5
360
 
359
 
382
       extruder_parked = false;
381
       extruder_parked = false;
383
     }
382
     }
384
     else if (do_solenoid_activation) { // && nomove == true
383
     else if (do_solenoid_activation) { // && nomove == true
385
-      // Deactivate old extruder solenoid
386
-      TERN(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid, pe_deactivate_solenoid)(active_extruder);
387
-      // Only engage magnetic field for new extruder
388
-      TERN(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_deactivate_solenoid, pe_activate_solenoid)(new_tool);
384
+      // Deactivate current extruder solenoid
385
+      pe_solenoid_set_pin_state(active_extruder, !PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE);
386
+      // Engage new extruder magnetic field
387
+      pe_solenoid_set_pin_state(new_tool, PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE);
389
     }
388
     }
390
 
389
 
391
     do_solenoid_activation = true; // Activate solenoid for subsequent tool_change()
390
     do_solenoid_activation = true; // Activate solenoid for subsequent tool_change()
1149
             // Just move back down
1148
             // Just move back down
1150
             DEBUG_ECHOLNPGM("Move back Z only");
1149
             DEBUG_ECHOLNPGM("Move back Z only");
1151
 
1150
 
1152
-            #if ENABLED(TOOLCHANGE_PARK)
1153
-              if (toolchange_settings.enable_park)
1154
-            #endif
1155
-            do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]);
1151
+            if (TERN1(TOOLCHANGE_PARK, toolchange_settings.enable_park))
1152
+              do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]);
1156
 
1153
 
1157
           #else
1154
           #else
1158
             // Move back to the original (or adjusted) position
1155
             // Move back to the original (or adjusted) position

+ 3
- 3
Marlin/src/module/tool_change.h View File

86
     #define PE_MAGNET_ON_STATE PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE
86
     #define PE_MAGNET_ON_STATE PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE
87
   #endif
87
   #endif
88
 
88
 
89
-  void pe_set_solenoid(const uint8_t extruder_num, const uint8_t state);
89
+  void pe_solenoid_set_pin_state(const uint8_t extruder_num, const uint8_t state);
90
 
90
 
91
-  inline void pe_activate_solenoid(const uint8_t extruder_num) { pe_set_solenoid(extruder_num, PE_MAGNET_ON_STATE); }
92
-  inline void pe_deactivate_solenoid(const uint8_t extruder_num) { pe_set_solenoid(extruder_num, !PE_MAGNET_ON_STATE); }
91
+  inline void pe_solenoid_magnet_on(const uint8_t extruder_num)  { pe_solenoid_set_pin_state(extruder_num,  PE_MAGNET_ON_STATE); }
92
+  inline void pe_solenoid_magnet_off(const uint8_t extruder_num) { pe_solenoid_set_pin_state(extruder_num, !PE_MAGNET_ON_STATE); }
93
 
93
 
94
   void pe_solenoid_init();
94
   void pe_solenoid_init();
95
 
95
 

Loading…
Cancel
Save