Browse Source

Improve menu pause / resume (#12876)

InsanityAutomation 5 years ago
parent
commit
a403d9a50c

+ 5
- 5
Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp View File

@@ -19,7 +19,7 @@ void sd_mmc_spi_mem_init(void) {
19 19
 }
20 20
 
21 21
 Ctrl_status sd_mmc_spi_test_unit_ready(void) {
22
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
22
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
23 23
     return CTRL_NO_PRESENT;
24 24
   return CTRL_GOOD;
25 25
 }
@@ -27,7 +27,7 @@ Ctrl_status sd_mmc_spi_test_unit_ready(void) {
27 27
 // NOTE: This function is defined as returning the address of the last block
28 28
 // in the card, which is cardSize() - 1
29 29
 Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
30
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
30
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
31 31
     return CTRL_NO_PRESENT;
32 32
   *nb_sector = card.getSd2Card().cardSize() - 1;
33 33
   return CTRL_GOOD;
@@ -42,7 +42,7 @@ bool sd_mmc_spi_wr_protect(void) {
42 42
 }
43 43
 
44 44
 bool sd_mmc_spi_removal(void) {
45
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
45
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
46 46
     return true;
47 47
   return false;
48 48
 }
@@ -61,7 +61,7 @@ uint8_t sector_buf[SD_MMC_BLOCK_SIZE];
61 61
 // #define DEBUG_MMC
62 62
 
63 63
 Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
64
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
64
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
65 65
     return CTRL_NO_PRESENT;
66 66
 
67 67
   #ifdef DEBUG_MMC
@@ -95,7 +95,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
95 95
 }
96 96
 
97 97
 Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
98
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
98
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
99 99
     return CTRL_NO_PRESENT;
100 100
 
101 101
   #ifdef DEBUG_MMC

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/main.cpp View File

@@ -106,7 +106,7 @@ void HAL_idletask(void) {
106 106
     // the disk if Marlin has it mounted. Unfortuately there is currently no way
107 107
     // to unmount the disk from the LCD menu.
108 108
     // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
109
-    if (card.flag.cardOK)
109
+    if (card.isDetected())
110 110
       MSC_Aquire_Lock();
111 111
     else
112 112
       MSC_Release_Lock();

+ 2
- 2
Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp View File

@@ -41,7 +41,7 @@ char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
41 41
 char eeprom_filename[] = "eeprom.dat";
42 42
 
43 43
 bool PersistentStore::access_start() {
44
-  if (!card.flag.cardOK) return false;
44
+  if (!card.isDetected()) return false;
45 45
   int16_t bytes_read = 0;
46 46
   constexpr char eeprom_zero = 0xFF;
47 47
   card.openFile(eeprom_filename, true);
@@ -54,7 +54,7 @@ bool PersistentStore::access_start() {
54 54
 }
55 55
 
56 56
 bool PersistentStore::access_finish() {
57
-  if (!card.flag.cardOK) return false;
57
+  if (!card.isDetected()) return false;
58 58
   card.openFile(eeprom_filename, true);
59 59
   int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
60 60
   card.closefile();

+ 2
- 2
Marlin/src/feature/power_loss_recovery.cpp View File

@@ -84,8 +84,8 @@ void PrintJobRecovery::changed() {
84 84
  */
85 85
 void PrintJobRecovery::check() {
86 86
   if (enabled) {
87
-    if (!card.flag.cardOK) card.initsd();
88
-    if (card.flag.cardOK) {
87
+    if (!card.isDetected()) card.initsd();
88
+    if (card.isDetected()) {
89 89
       load();
90 90
       if (!valid()) return purge();
91 91
       enqueue_and_echo_commands_P(PSTR("M1000 S"));

+ 25
- 10
Marlin/src/gcode/sdcard/M20-M30_M32-M34_M524_M928.cpp View File

@@ -85,18 +85,26 @@ void GcodeSuite::M23() {
85 85
  * M24: Start or Resume SD Print
86 86
  */
87 87
 void GcodeSuite::M24() {
88
-  #if ENABLED(PARK_HEAD_ON_PAUSE)
89
-    resume_print();
90
-  #endif
91 88
 
92 89
   #if ENABLED(POWER_LOSS_RECOVERY)
93 90
     if (parser.seenval('S')) card.setIndex(parser.value_long());
94 91
     if (parser.seenval('T')) print_job_timer.resume(parser.value_long());
95 92
   #endif
96 93
 
97
-  card.startFileprint();
98
-  print_job_timer.start();
99
-  ui.reset_status();
94
+  #if ENABLED(PARK_HEAD_ON_PAUSE)
95
+    resume_print();
96
+  #else
97
+    if (card.isFileOpen()) {
98
+      card.startFileprint();
99
+      print_job_timer.start();
100
+    }
101
+
102
+    ui.reset_status();
103
+    
104
+    #ifdef ACTION_ON_RESUME
105
+      SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
106
+    #endif
107
+  #endif
100 108
 }
101 109
 
102 110
 /**
@@ -106,9 +114,16 @@ void GcodeSuite::M25() {
106 114
   #if ENABLED(PARK_HEAD_ON_PAUSE)
107 115
     M125();
108 116
   #else
109
-    card.pauseSDPrint();
117
+    #if ENABLED(SDSUPPORT)
118
+      if (IS_SD_PRINTING()) card.pauseSDPrint();
119
+    #endif
120
+
110 121
     print_job_timer.pause();
111 122
     ui.reset_status();
123
+
124
+    #ifdef ACTION_ON_PAUSE
125
+      SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
126
+    #endif
112 127
   #endif
113 128
 }
114 129
 
@@ -116,7 +131,7 @@ void GcodeSuite::M25() {
116 131
  * M26: Set SD Card file index
117 132
  */
118 133
 void GcodeSuite::M26() {
119
-  if (card.flag.cardOK && parser.seenval('S'))
134
+  if (card.isDetected() && parser.seenval('S'))
120 135
     card.setIndex(parser.value_long());
121 136
 }
122 137
 
@@ -207,7 +222,7 @@ void GcodeSuite::M29() {
207 222
  * M30 <filename>: Delete SD Card file
208 223
  */
209 224
 void GcodeSuite::M30() {
210
-  if (card.flag.cardOK) {
225
+  if (card.isDetected()) {
211 226
     card.closefile();
212 227
     card.removeFile(parser.string_arg);
213 228
   }
@@ -226,7 +241,7 @@ void GcodeSuite::M30() {
226 241
 void GcodeSuite::M32() {
227 242
   if (IS_SD_PRINTING()) planner.synchronize();
228 243
 
229
-  if (card.flag.cardOK) {
244
+  if (card.isDetected()) {
230 245
     const bool call_procedure = parser.boolval('P');
231 246
 
232 247
     card.openFile(parser.string_arg, true, call_procedure);

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

@@ -578,7 +578,7 @@ namespace ExtUI {
578 578
   }
579 579
 
580 580
   bool isPrintingFromMedia() {
581
-    return IFSD(card.flag.cardOK && card.isFileOpen(), false);
581
+    return IFSD(card.isFileOpen(), false);
582 582
   }
583 583
 
584 584
   bool isPrinting() {
@@ -586,7 +586,7 @@ namespace ExtUI {
586 586
   }
587 587
 
588 588
   bool isMediaInserted() {
589
-    return IFSD(IS_SD_INSERTED() && card.flag.cardOK, false);
589
+    return IFSD(IS_SD_INSERTED() && card.isDetected(), false);
590 590
   }
591 591
 
592 592
   void pausePrint() {
@@ -703,13 +703,13 @@ void MarlinUI::update() {
703 703
       last_sd_status = sd_status;
704 704
       if (sd_status) {
705 705
         card.initsd();
706
-        if (card.flag.cardOK)
706
+        if (card.isDetected())
707 707
           ExtUI::onMediaInserted();
708 708
         else
709 709
           ExtUI::onMediaError();
710 710
       }
711 711
       else {
712
-        const bool ok = card.flag.cardOK;
712
+        const bool ok = card.isDetected();
713 713
         card.release();
714 714
         if (ok) ExtUI::onMediaRemoved();
715 715
       }

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

@@ -330,7 +330,7 @@ void process_lcd_s_command(const char* command) {
330 330
 
331 331
     case 'L': {
332 332
       #if ENABLED(SDSUPPORT)
333
-        if (!card.flag.cardOK) card.initsd();
333
+        if (!card.isDetected()) card.initsd();
334 334
 
335 335
         // A more efficient way to do this would be to
336 336
         // implement a callback in the ls_SerialPrint code, but

+ 48
- 46
Marlin/src/lcd/menu/menu_main.cpp View File

@@ -30,33 +30,38 @@
30 30
 
31 31
 #include "menu.h"
32 32
 #include "../../module/temperature.h"
33
+#include "../../gcode/queue.h"
34
+#include "../../module/printcounter.h"
33 35
 
34
-#if ENABLED(SDSUPPORT)
35
-
36
-  #include "../../sd/cardreader.h"
37
-  #include "../../gcode/queue.h"
38
-  #include "../../module/printcounter.h"
36
+#if ENABLED(POWER_LOSS_RECOVERY)
37
+  #include "../../feature/power_loss_recovery.h"
38
+#endif
39 39
 
40
+void lcd_pause() {
40 41
   #if ENABLED(POWER_LOSS_RECOVERY)
41
-    #include "../../feature/power_loss_recovery.h"
42
+    if (recovery.enabled) recovery.save(true, false);
42 43
   #endif
43 44
 
44
-  void lcd_sdcard_pause() {
45
-    #if ENABLED(POWER_LOSS_RECOVERY)
46
-      if (recovery.enabled) recovery.save(true, false);
47
-    #endif
45
+  #if ENABLED(PARK_HEAD_ON_PAUSE)
46
+    pause_print(PAUSE_PARK_RETRACT_LENGTH, NOZZLE_PARK_POINT, 0, true);
47
+  #elif ENABLED(SDSUPPORT)
48 48
     enqueue_and_echo_commands_P(PSTR("M25"));
49
-  }
49
+  #elif defined(ACTION_ON_PAUSE)
50
+    SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
51
+  #endif
52
+}
50 53
 
51
-  void lcd_sdcard_resume() {
52
-    #if ENABLED(PARK_HEAD_ON_PAUSE)
53
-      enqueue_and_echo_commands_P(PSTR("M24"));
54
-    #else
55
-      card.startFileprint();
56
-      print_job_timer.start();
57
-      ui.reset_status();
58
-    #endif
59
-  }
54
+void lcd_resume() {
55
+  #if ENABLED(SDSUPPORT)
56
+    if (card.isPaused()) enqueue_and_echo_commands_P(PSTR("M24"));
57
+  #elif ENABLED(ACTION_ON_RESUME)
58
+    SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
59
+  #endif
60
+}
61
+
62
+#if ENABLED(SDSUPPORT)
63
+
64
+  #include "../../sd/cardreader.h"
60 65
 
61 66
   void lcd_sdcard_stop() {
62 67
     wait_for_heatup = wait_for_user = false;
@@ -88,35 +93,18 @@ void menu_main() {
88 93
   START_MENU();
89 94
   MENU_BACK(MSG_WATCH);
90 95
 
91
-  #if ENABLED(SDSUPPORT)
92
-    if (card.flag.cardOK) {
93
-      if (card.isFileOpen()) {
94
-        if (IS_SD_PRINTING())
95
-          MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
96
-        else
97
-          MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
98
-
99
-        MENU_ITEM(submenu, MSG_STOP_PRINT, menu_sdcard_abort_confirm);
100
-      }
101
-      else {
102
-        MENU_ITEM(submenu, MSG_CARD_MENU, menu_sdcard);
103
-        #if !PIN_EXISTS(SD_DETECT)
104
-          MENU_ITEM(gcode, MSG_CHANGE_SDCARD, PSTR("M21"));  // SD-card changed by user
105
-        #endif
106
-      }
107
-    }
108
-    else {
109
-      MENU_ITEM(function, MSG_NO_CARD, NULL);
110
-      #if !PIN_EXISTS(SD_DETECT)
111
-        MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
112
-      #endif
113
-    }
114
-  #endif // SDSUPPORT
115
-
116 96
   const bool busy = printer_busy();
117
-  if (busy)
97
+
98
+  if (busy) {
99
+    MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_pause);
118 100
     MENU_ITEM(submenu, MSG_TUNE, menu_tune);
101
+  }
119 102
   else {
103
+    MENU_ITEM(function, MSG_RESUME_PRINT, lcd_resume);
104
+    #if ENABLED(SDSUPPORT)
105
+      if (card.isFileOpen())
106
+        MENU_ITEM(submenu, MSG_STOP_PRINT, menu_sdcard_abort_confirm);
107
+    #endif
120 108
     MENU_ITEM(submenu, MSG_MOTION, menu_motion);
121 109
     MENU_ITEM(submenu, MSG_TEMPERATURE, menu_temperature);
122 110
   }
@@ -164,6 +152,20 @@ void menu_main() {
164 152
       MENU_ITEM(function, MSG_AUTOSTART, card.beginautostart);
165 153
   #endif
166 154
 
155
+#if ENABLED(SDSUPPORT)
156
+    if (card.isDetected() && !card.isFileOpen()) {
157
+      MENU_ITEM(submenu, MSG_CARD_MENU, menu_sdcard);
158
+      #if !PIN_EXISTS(SD_DETECT)
159
+        MENU_ITEM(gcode, MSG_CHANGE_SDCARD, PSTR("M21"));  // SD-card changed by user
160
+      #endif
161
+    }
162
+    else {
163
+      MENU_ITEM(function, MSG_NO_CARD, NULL);
164
+      #if !PIN_EXISTS(SD_DETECT)
165
+        MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
166
+      #endif
167
+    }
168
+  #endif
167 169
   END_MENU();
168 170
 }
169 171
 

+ 1
- 1
Marlin/src/lcd/menu/menu_sdcard.cpp View File

@@ -111,7 +111,7 @@ void menu_sdcard() {
111 111
       MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
112 112
     #endif
113 113
   }
114
-  else if (card.flag.cardOK)
114
+  else if (card.isDetected())
115 115
     MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
116 116
 
117 117
   if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {

+ 11
- 11
Marlin/src/sd/cardreader.cpp View File

@@ -124,7 +124,7 @@ CardReader::CardReader() {
124 124
       //sort_reverse = false;
125 125
     #endif
126 126
   #endif
127
-  flag.sdprinting = flag.cardOK = flag.saving = flag.logging = false;
127
+  flag.sdprinting = flag.detected = flag.saving = flag.logging = false;
128 128
   filesize = sdpos = 0;
129 129
   file_subcall_ctr = 0;
130 130
 
@@ -360,7 +360,7 @@ void CardReader::printFilename(
360 360
 }
361 361
 
362 362
 void CardReader::initsd() {
363
-  flag.cardOK = false;
363
+  flag.detected = false;
364 364
   if (root.isOpen()) root.close();
365 365
 
366 366
   #ifndef SPI_SPEED
@@ -380,7 +380,7 @@ void CardReader::initsd() {
380 380
   else if (!root.openRoot(&volume))
381 381
     SERIAL_ERROR_MSG(MSG_SD_OPENROOT_FAIL);
382 382
   else {
383
-    flag.cardOK = true;
383
+    flag.detected = true;
384 384
     SERIAL_ECHO_MSG(MSG_SD_CARD_OK);
385 385
   }
386 386
   setroot();
@@ -390,7 +390,7 @@ void CardReader::initsd() {
390 390
 
391 391
 void CardReader::release() {
392 392
   stopSDPrint();
393
-  flag.cardOK = false;
393
+  flag.detected = false;
394 394
 }
395 395
 
396 396
 void CardReader::openAndPrintFile(const char *name) {
@@ -402,7 +402,7 @@ void CardReader::openAndPrintFile(const char *name) {
402 402
 }
403 403
 
404 404
 void CardReader::startFileprint() {
405
-  if (flag.cardOK) {
405
+  if (isDetected()) {
406 406
     flag.sdprinting = true;
407 407
     #if SD_RESORT
408 408
       flush_presort();
@@ -452,7 +452,7 @@ void CardReader::getAbsFilename(char *t) {
452 452
 
453 453
 void CardReader::openFile(char * const path, const bool read, const bool subcall/*=false*/) {
454 454
 
455
-  if (!flag.cardOK) return;
455
+  if (!isDetected()) return;
456 456
 
457 457
   uint8_t doing = 0;
458 458
   if (isFileOpen()) {                     // Replacing current file or doing a subroutine
@@ -535,7 +535,7 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall
535 535
 }
536 536
 
537 537
 void CardReader::removeFile(const char * const name) {
538
-  if (!flag.cardOK) return;
538
+  if (!isDetected()) return;
539 539
 
540 540
   //stopSDPrint();
541 541
 
@@ -561,7 +561,7 @@ void CardReader::report_status(
561 561
     const int8_t port/*= -1*/
562 562
   #endif
563 563
 ) {
564
-  if (flag.cardOK && flag.sdprinting) {
564
+  if (isPrinting()) {
565 565
     SERIAL_ECHOPGM_P(port, MSG_SD_PRINTING_BYTE);
566 566
     SERIAL_ECHO_P(port, sdpos);
567 567
     SERIAL_CHAR_P(port, '/');
@@ -600,9 +600,9 @@ void CardReader::checkautostart() {
600 600
 
601 601
   if (autostart_index < 0 || flag.sdprinting) return;
602 602
 
603
-  if (!flag.cardOK) initsd();
603
+  if (!isDetected()) initsd();
604 604
 
605
-  if (flag.cardOK
605
+  if (isDetected()
606 606
     #if ENABLED(POWER_LOSS_RECOVERY)
607 607
       && !recovery.valid() // Don't run auto#.g when a resume file exists
608 608
     #endif
@@ -1065,7 +1065,7 @@ void CardReader::printingHasFinished() {
1065 1065
   }
1066 1066
 
1067 1067
   void CardReader::openJobRecoveryFile(const bool read) {
1068
-    if (!flag.cardOK) return;
1068
+    if (!isDetected()) return;
1069 1069
     if (recovery.file.isOpen()) return;
1070 1070
     if (!recovery.file.open(&root, job_recovery_file_name, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) {
1071 1071
       SERIAL_ECHOPAIR(MSG_SD_OPEN_FILE_FAIL, job_recovery_file_name);

+ 5
- 2
Marlin/src/sd/cardreader.h View File

@@ -39,7 +39,7 @@ typedef struct {
39 39
   bool saving:1,
40 40
        logging:1,
41 41
        sdprinting:1,
42
-       cardOK:1,
42
+       detected:1,
43 43
        filenameIsDir:1,
44 44
        abort_sd_printing:1
45 45
        #if ENABLED(FAST_FILE_TRANSFER)
@@ -127,7 +127,10 @@ public:
127 127
   #endif
128 128
 
129 129
   static inline void pauseSDPrint() { flag.sdprinting = false; }
130
-  static inline bool isFileOpen() { return file.isOpen(); }
130
+  static inline bool isDetected() { return flag.detected; }
131
+  static inline bool isFileOpen() { return isDetected() && file.isOpen(); }
132
+  static inline bool isPaused() { return isFileOpen() && !flag.sdprinting; }
133
+  static inline bool isPrinting() { return flag.sdprinting; }
131 134
   static inline bool eof() { return sdpos >= filesize; }
132 135
   static inline int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
133 136
   static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }

Loading…
Cancel
Save