Browse Source

Break out prevent_dangerous_extrude feature

- It’s inline here, but could be a macro and duplicated for
`planner.cpp`
Scott Lahteine 10 years ago
parent
commit
8b16ebe705
1 changed files with 46 additions and 35 deletions
  1. 46
    35
      Marlin/Marlin_main.cpp

+ 46
- 35
Marlin/Marlin_main.cpp View File

547
   #endif
547
   #endif
548
 }
548
 }
549
 
549
 
550
-
551
-void setup()
552
-{
550
+void setup() {
553
   setup_killpin();
551
   setup_killpin();
554
   setup_filrunoutpin();
552
   setup_filrunoutpin();
555
   setup_powerhold();
553
   setup_powerhold();
559
 
557
 
560
   // Check startup - does nothing if bootloader sets MCUSR to 0
558
   // Check startup - does nothing if bootloader sets MCUSR to 0
561
   byte mcu = MCUSR;
559
   byte mcu = MCUSR;
562
-  if(mcu & 1) SERIAL_ECHOLNPGM(MSG_POWERUP);
563
-  if(mcu & 2) SERIAL_ECHOLNPGM(MSG_EXTERNAL_RESET);
564
-  if(mcu & 4) SERIAL_ECHOLNPGM(MSG_BROWNOUT_RESET);
565
-  if(mcu & 8) SERIAL_ECHOLNPGM(MSG_WATCHDOG_RESET);
566
-  if(mcu & 32) SERIAL_ECHOLNPGM(MSG_SOFTWARE_RESET);
567
-  MCUSR=0;
560
+  if (mcu & 1) SERIAL_ECHOLNPGM(MSG_POWERUP);
561
+  if (mcu & 2) SERIAL_ECHOLNPGM(MSG_EXTERNAL_RESET);
562
+  if (mcu & 4) SERIAL_ECHOLNPGM(MSG_BROWNOUT_RESET);
563
+  if (mcu & 8) SERIAL_ECHOLNPGM(MSG_WATCHDOG_RESET);
564
+  if (mcu & 32) SERIAL_ECHOLNPGM(MSG_SOFTWARE_RESET);
565
+  MCUSR = 0;
568
 
566
 
569
   SERIAL_ECHOPGM(MSG_MARLIN);
567
   SERIAL_ECHOPGM(MSG_MARLIN);
570
-  SERIAL_ECHOLNPGM(STRING_VERSION);
568
+  SERIAL_ECHOLNPGM(" " STRING_VERSION);
569
+
571
   #ifdef STRING_VERSION_CONFIG_H
570
   #ifdef STRING_VERSION_CONFIG_H
572
     #ifdef STRING_CONFIG_H_AUTHOR
571
     #ifdef STRING_CONFIG_H_AUTHOR
573
       SERIAL_ECHO_START;
572
       SERIAL_ECHO_START;
579
       SERIAL_ECHOLNPGM(__DATE__);
578
       SERIAL_ECHOLNPGM(__DATE__);
580
     #endif // STRING_CONFIG_H_AUTHOR
579
     #endif // STRING_CONFIG_H_AUTHOR
581
   #endif // STRING_VERSION_CONFIG_H
580
   #endif // STRING_VERSION_CONFIG_H
581
+
582
   SERIAL_ECHO_START;
582
   SERIAL_ECHO_START;
583
   SERIAL_ECHOPGM(MSG_FREE_MEMORY);
583
   SERIAL_ECHOPGM(MSG_FREE_MEMORY);
584
   SERIAL_ECHO(freeMemory());
584
   SERIAL_ECHO(freeMemory());
585
   SERIAL_ECHOPGM(MSG_PLANNER_BUFFER_BYTES);
585
   SERIAL_ECHOPGM(MSG_PLANNER_BUFFER_BYTES);
586
   SERIAL_ECHOLN((int)sizeof(block_t)*BLOCK_BUFFER_SIZE);
586
   SERIAL_ECHOLN((int)sizeof(block_t)*BLOCK_BUFFER_SIZE);
587
+
587
   #ifdef SDSUPPORT
588
   #ifdef SDSUPPORT
588
-  for(int8_t i = 0; i < BUFSIZE; i++)
589
-  {
590
-    fromsd[i] = false;
591
-  }
592
-  #endif //!SDSUPPORT
589
+    for (int8_t i = 0; i < BUFSIZE; i++) fromsd[i] = false;
590
+  #endif // !SDSUPPORT
593
 
591
 
594
   // loads data from EEPROM if available else uses defaults (and resets step acceleration rate)
592
   // loads data from EEPROM if available else uses defaults (and resets step acceleration rate)
595
   Config_RetrieveSettings();
593
   Config_RetrieveSettings();
600
   st_init();    // Initialize stepper, this enables interrupts!
598
   st_init();    // Initialize stepper, this enables interrupts!
601
   setup_photpin();
599
   setup_photpin();
602
   servo_init();
600
   servo_init();
603
-  
604
 
601
 
605
   lcd_init();
602
   lcd_init();
606
   _delay_ms(1000);  // wait 1sec to display the splash screen
603
   _delay_ms(1000);  // wait 1sec to display the splash screen
612
   #ifdef DIGIPOT_I2C
609
   #ifdef DIGIPOT_I2C
613
     digipot_i2c_init();
610
     digipot_i2c_init();
614
   #endif
611
   #endif
615
-#ifdef Z_PROBE_SLED
616
-  pinMode(SERVO0_PIN, OUTPUT);
617
-  digitalWrite(SERVO0_PIN, LOW); // turn it off
618
-#endif // Z_PROBE_SLED
612
+
613
+  #ifdef Z_PROBE_SLED
614
+    pinMode(SERVO0_PIN, OUTPUT);
615
+    digitalWrite(SERVO0_PIN, LOW); // turn it off
616
+  #endif // Z_PROBE_SLED
617
+
619
   setup_homepin();
618
   setup_homepin();
620
   
619
   
621
-#ifdef STAT_LED_RED
622
-  pinMode(STAT_LED_RED, OUTPUT);
623
-  digitalWrite(STAT_LED_RED, LOW); // turn it off
624
-#endif
625
-#ifdef STAT_LED_BLUE
626
-  pinMode(STAT_LED_BLUE, OUTPUT);
627
-  digitalWrite(STAT_LED_BLUE, LOW); // turn it off
628
-#endif  
620
+  #ifdef STAT_LED_RED
621
+    pinMode(STAT_LED_RED, OUTPUT);
622
+    digitalWrite(STAT_LED_RED, LOW); // turn it off
623
+  #endif
624
+
625
+  #ifdef STAT_LED_BLUE
626
+    pinMode(STAT_LED_BLUE, OUTPUT);
627
+    digitalWrite(STAT_LED_BLUE, LOW); // turn it off
628
+  #endif  
629
 }
629
 }
630
 
630
 
631
 
631
 
5447
 }
5447
 }
5448
 #endif  // MESH_BED_LEVELING
5448
 #endif  // MESH_BED_LEVELING
5449
 
5449
 
5450
-void prepare_move() {
5451
-  clamp_to_software_endstops(destination);
5452
-  refresh_cmd_timeout();
5450
+#ifdef PREVENT_DANGEROUS_EXTRUDE
5453
 
5451
 
5454
-  #ifdef PREVENT_DANGEROUS_EXTRUDE
5455
-    float de = destination[E_AXIS] - current_position[E_AXIS];
5452
+  inline float prevent_dangerous_extrude(float &curr_e, float &dest_e) {
5453
+    float de = dest_e - curr_e;
5456
     if (de) {
5454
     if (de) {
5457
       if (degHotend(active_extruder) < extrude_min_temp) {
5455
       if (degHotend(active_extruder) < extrude_min_temp) {
5458
-        current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
5456
+        curr_e = dest_e; // Behave as if the move really took place, but ignore E part
5459
         SERIAL_ECHO_START;
5457
         SERIAL_ECHO_START;
5460
         SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
5458
         SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
5459
+        return 0;
5461
       }
5460
       }
5462
       #ifdef PREVENT_LENGTHY_EXTRUDE
5461
       #ifdef PREVENT_LENGTHY_EXTRUDE
5463
         if (labs(de) > EXTRUDE_MAXLENGTH) {
5462
         if (labs(de) > EXTRUDE_MAXLENGTH) {
5464
-          current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
5463
+          curr_e = dest_e; // Behave as if the move really took place, but ignore E part
5465
           SERIAL_ECHO_START;
5464
           SERIAL_ECHO_START;
5466
           SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
5465
           SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
5466
+          return 0;
5467
         }
5467
         }
5468
       #endif
5468
       #endif
5469
     }
5469
     }
5470
+    return de;
5471
+  }
5472
+
5473
+#endif // PREVENT_DANGEROUS_EXTRUDE
5474
+
5475
+void prepare_move() {
5476
+  clamp_to_software_endstops(destination);
5477
+  refresh_cmd_timeout();
5478
+
5479
+  #ifdef PREVENT_DANGEROUS_EXTRUDE
5480
+    (void)prevent_dangerous_extrude(current_position[E_AXIS], destination[E_AXIS]);
5470
   #endif
5481
   #endif
5471
 
5482
 
5472
   #ifdef SCARA //for now same as delta-code
5483
   #ifdef SCARA //for now same as delta-code

Loading…
Cancel
Save