Browse Source

Fix kill() and ExtensibleUI (#12160)

* Fix to isPrintingFromMedia()

  - isPrintingFromMedia() will now return true even if SD print is paused.
  - isPrintingFromMediaPaused() allows UI to determine if the print is paused.

* Don't use _delay_us in minkill (#12145)

  - In HAL_DUE, _delay_us is simply an alias for delay, which causes the board to hang and subsequently reboot due to the watchdog timer.

* Shorten code with IFSD macro
Marcio Teixeira 6 years ago
parent
commit
2e5e689a7f

+ 9
- 5
Marlin/src/Marlin.cpp View File

42
 #include "module/printcounter.h" // PrintCounter or Stopwatch
42
 #include "module/printcounter.h" // PrintCounter or Stopwatch
43
 #include "feature/closedloop.h"
43
 #include "feature/closedloop.h"
44
 
44
 
45
+#include "HAL/shared/Delay.h"
46
+
45
 #ifdef ARDUINO
47
 #ifdef ARDUINO
46
   #include <pins_arduino.h>
48
   #include <pins_arduino.h>
47
 #endif
49
 #endif
610
  * After this the machine will need to be reset.
612
  * After this the machine will need to be reset.
611
  */
613
  */
612
 void kill(PGM_P const lcd_msg/*=NULL*/) {
614
 void kill(PGM_P const lcd_msg/*=NULL*/) {
613
-
614
   thermalManager.disable_all_heaters();
615
   thermalManager.disable_all_heaters();
615
 
616
 
616
   SERIAL_ERROR_START();
617
   SERIAL_ERROR_START();
633
 
634
 
634
 void minkill() {
635
 void minkill() {
635
 
636
 
636
-  _delay_ms(600);  // Wait a short time (allows messages to get out before shutting down.
637
-  cli();           // Stop interrupts
638
-  _delay_ms(250);  // Wait to ensure all interrupts stopped
637
+  // Wait a short time (allows messages to get out before shutting down.
638
+  DELAY_US(600000);
639
+
640
+  cli(); // Stop interrupts
641
+
642
+  // Wait to ensure all interrupts stopped
643
+  DELAY_US(250000);
639
 
644
 
640
-  disable_all_steppers();
641
   thermalManager.disable_all_heaters(); // turn off heaters again
645
   thermalManager.disable_all_heaters(); // turn off heaters again
642
 
646
 
643
   #if HAS_POWER_SWITCH
647
   #if HAS_POWER_SWITCH

+ 17
- 49
Marlin/src/lcd/extensible_ui/ui_api.cpp View File

37
 #if ENABLED(SDSUPPORT)
37
 #if ENABLED(SDSUPPORT)
38
   #include "../../sd/cardreader.h"
38
   #include "../../sd/cardreader.h"
39
   #include "../../feature/emergency_parser.h"
39
   #include "../../feature/emergency_parser.h"
40
+  #define IFSD(A,B) (A)
41
+#else
42
+  #define IFSD(A,B) (B)
40
 #endif
43
 #endif
41
 
44
 
42
 #if ENABLED(PRINTCOUNTER)
45
 #if ENABLED(PRINTCOUNTER)
352
   #endif
355
   #endif
353
 
356
 
354
   uint8_t getProgress_percent() {
357
   uint8_t getProgress_percent() {
355
-    #if ENABLED(SDSUPPORT)
356
-      return card.percentDone();
357
-    #else
358
-      return 0;
359
-    #endif
358
+    return IFSD(card.percentDone(), 0);
360
   }
359
   }
361
 
360
 
362
   uint32_t getProgress_seconds_elapsed() {
361
   uint32_t getProgress_seconds_elapsed() {
415
   }
414
   }
416
 
415
 
417
   void printFile(const char *filename) {
416
   void printFile(const char *filename) {
418
-    #if ENABLED(SDSUPPORT)
419
-      card.openAndPrintFile(filename);
420
-    #endif
417
+    IFSD(card.openAndPrintFile(filename), NOOP);
418
+  }
419
+
420
+  bool isPrintingFromMediaPaused() {
421
+    return IFSD(isPrintingFromMedia() && !card.sdprinting, false);
421
   }
422
   }
422
 
423
 
423
   bool isPrintingFromMedia() {
424
   bool isPrintingFromMedia() {
424
-    #if ENABLED(SDSUPPORT)
425
-      return card.cardOK && card.isFileOpen() && card.sdprinting;
426
-    #else
427
-      return false;
428
-    #endif
425
+    return IFSD(card.cardOK && card.isFileOpen(), false);
429
   }
426
   }
430
 
427
 
431
   bool isPrinting() {
428
   bool isPrinting() {
432
-    return (planner.movesplanned() || IS_SD_PRINTING() ||
433
-      #if ENABLED(SDSUPPORT)
434
-        (card.cardOK && card.isFileOpen())
435
-      #else
436
-        false
437
-      #endif
438
-    );
429
+    return (planner.movesplanned() || IS_SD_PRINTING() || isPrintingFromMedia());
439
   }
430
   }
440
 
431
 
441
   bool isMediaInserted() {
432
   bool isMediaInserted() {
442
-    #if ENABLED(SDSUPPORT)
443
-      return IS_SD_INSERTED() && card.cardOK;
444
-    #else
445
-      return false;
446
-    #endif
433
+    return IFSD(IS_SD_INSERTED() && card.cardOK, false);
447
   }
434
   }
448
 
435
 
449
   void pausePrint() {
436
   void pausePrint() {
504
   }
491
   }
505
 
492
 
506
   const char* FileList::filename() {
493
   const char* FileList::filename() {
507
-    #if ENABLED(SDSUPPORT)
508
-      return (card.longFilename && card.longFilename[0]) ? card.longFilename : card.filename;
509
-    #else
510
-      return "";
511
-    #endif
494
+    return IFSD(card.longFilename && card.longFilename[0]) ? card.longFilename : card.filename, "");
512
   }
495
   }
513
 
496
 
514
   const char* FileList::shortFilename() {
497
   const char* FileList::shortFilename() {
515
-    #if ENABLED(SDSUPPORT)
516
-      return card.filename;
517
-    #else
518
-      return "";
519
-    #endif
498
+    return IFSD(card.filename, "");
520
   }
499
   }
521
 
500
 
522
   const char* FileList::longFilename() {
501
   const char* FileList::longFilename() {
523
-    #if ENABLED(SDSUPPORT)
524
-      return card.longFilename;
525
-    #else
526
-      return "";
527
-    #endif
502
+    return IFSD(card.longFilename, "");
528
   }
503
   }
529
 
504
 
530
   bool FileList::isDir() {
505
   bool FileList::isDir() {
531
-    #if ENABLED(SDSUPPORT)
532
-      return card.filenameIsDir;
533
-    #else
534
-      return false;
535
-    #endif
506
+    return IFSD(card.filenameIsDir, false);
536
   }
507
   }
537
 
508
 
538
   uint16_t FileList::count() {
509
   uint16_t FileList::count() {
539
-    #if ENABLED(SDSUPPORT)
540
-      if (num_files == 0xFFFF) num_files = card.get_num_Files();
541
-      return num_files;
542
-    #endif
510
+    return IFSD((num_files = (num_files == 0xFFFF ? card.get_num_Files() : num_files)), 0);
543
   }
511
   }
544
 
512
 
545
   bool FileList::isAtRootDir() {
513
   bool FileList::isAtRootDir() {

+ 1
- 0
Marlin/src/lcd/extensible_ui/ui_api.h View File

133
   void enqueueCommands(progmem_str gcode);
133
   void enqueueCommands(progmem_str gcode);
134
 
134
 
135
   void printFile(const char *filename);
135
   void printFile(const char *filename);
136
+  bool isPrintingFromMediaPaused();
136
   bool isPrintingFromMedia();
137
   bool isPrintingFromMedia();
137
   bool isPrinting();
138
   bool isPrinting();
138
   void stopPrint();
139
   void stopPrint();

Loading…
Cancel
Save