Selaa lähdekoodia

Merge pull request #10055 from TheSFReader/getFilename

[2.0.x] Add 'C' to M27 to echo filename (plus long name, if any)
Scott Lahteine 7 vuotta sitten
vanhempi
commit
899b4df7a3
No account linked to committer's email address

+ 3
- 1
Marlin/src/gcode/gcode.h Näytä tiedosto

@@ -85,7 +85,9 @@
85 85
  * M24  - Start/resume SD print. (Requires SDSUPPORT)
86 86
  * M25  - Pause SD print. (Requires SDSUPPORT)
87 87
  * M26  - Set SD position in bytes: "M26 S12345". (Requires SDSUPPORT)
88
- * M27  - Report SD print status. (Requires SDSUPPORT) Or, with 'S<seconds>' set the SD status auto-report interval. (Requires AUTO_REPORT_SD_STATUS)
88
+ * M27  - Report SD print status. (Requires SDSUPPORT)
89
+ *        OR, with 'S<seconds>' set the SD status auto-report interval. (Requires AUTO_REPORT_SD_STATUS)
90
+ *        OR, with 'C' get the current filename.
89 91
  * M28  - Start SD write: "M28 /path/file.gco". (Requires SDSUPPORT)
90 92
  * M29  - Stop SD write. (Requires SDSUPPORT)
91 93
  * M30  - Delete file from SD: "M30 /path/file.gco"

+ 21
- 10
Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp Näytä tiedosto

@@ -107,24 +107,35 @@ void GcodeSuite::M26() {
107 107
 }
108 108
 
109 109
 /**
110
- * M27: Get SD Card status or set the SD status auto-report interval.
110
+ * M27: Get SD Card status
111
+ *      OR, with 'S<seconds>' set the SD status auto-report interval. (Requires AUTO_REPORT_SD_STATUS)
112
+ *      OR, with 'C' get the current filename.
111 113
  */
112 114
 void GcodeSuite::M27() {
115
+  #if NUM_SERIAL > 1
116
+    const int16_t port = command_queue_port[cmd_queue_index_r];
117
+  #endif
118
+
119
+  if (parser.seen('C')) {
120
+    SERIAL_ECHOPGM_P(port, "Current file: ");
121
+    card.printFilename();
122
+  }
123
+
113 124
   #if ENABLED(AUTO_REPORT_SD_STATUS)
114
-    if (parser.seenval('S')) {
125
+    else if (parser.seenval('S'))
115 126
       card.set_auto_report_interval(parser.value_byte()
116 127
         #if NUM_SERIAL > 1
117
-          , command_queue_port[cmd_queue_index_r]
128
+          , port
118 129
         #endif
119 130
       );
120
-    }
121
-    else
122 131
   #endif
123
-      card.getStatus(
124
-        #if NUM_SERIAL > 1
125
-          command_queue_port[cmd_queue_index_r]
126
-        #endif
127
-      );
132
+
133
+  else
134
+    card.getStatus(
135
+      #if NUM_SERIAL > 1
136
+        port
137
+      #endif
138
+    );
128 139
 }
129 140
 
130 141
 /**

+ 36
- 6
Marlin/src/sd/cardreader.cpp Näytä tiedosto

@@ -157,7 +157,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
157 157
 
158 158
         case LS_SerialPrint:
159 159
           createFilename(filename, p);
160
-          SERIAL_PROTOCOL_P(port, prepend);
160
+          if (prepend) SERIAL_PROTOCOL_P(port, prepend);
161 161
           SERIAL_PROTOCOL_P(port, filename);
162 162
           SERIAL_PROTOCOLCHAR_P(port, ' ');
163 163
           SERIAL_PROTOCOLLN_P(port, p.fileSize);
@@ -184,7 +184,7 @@ void CardReader::ls(
184 184
 ) {
185 185
   lsAction = LS_SerialPrint;
186 186
   root.rewind();
187
-  lsDive("", root
187
+  lsDive(NULL, root
188 188
     #if NUM_SERIAL > 1
189 189
       , NULL, port
190 190
     #endif
@@ -227,7 +227,7 @@ void CardReader::ls(
227 227
 
228 228
       // Find the item, setting the long filename
229 229
       diveDir.rewind();
230
-      lsDive("", diveDir, segment
230
+      lsDive(NULL, diveDir, segment
231 231
         #if NUM_SERIAL > 1
232 232
           , port
233 233
         #endif
@@ -262,6 +262,32 @@ void CardReader::ls(
262 262
 
263 263
 #endif // LONG_FILENAME_HOST_SUPPORT
264 264
 
265
+/**
266
+ * Echo the DOS 8.3 filename (and long filename, if any)
267
+ */
268
+void CardReader::printFilename(
269
+  #if NUM_SERIAL > 1
270
+    const int8_t port/*= -1*/
271
+  #endif
272
+) {
273
+  if (file.isOpen()) {
274
+    char lfilename[FILENAME_LENGTH];
275
+    file.getFilename(lfilename);
276
+    SERIAL_ECHO_P(port, lfilename);
277
+    #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
278
+      getfilename(0, lfilename);
279
+      if (longFilename[0]) {
280
+        SERIAL_ECHO_P(port, ' ');
281
+        SERIAL_ECHO_P(port, longFilename);
282
+      }
283
+    #endif
284
+  }
285
+  else
286
+    SERIAL_ECHOPGM_P(port, "(no file)");
287
+
288
+  SERIAL_EOL_P(port);
289
+}
290
+
265 291
 void CardReader::initsd() {
266 292
   cardOK = false;
267 293
   if (root.isOpen()) root.close();
@@ -322,7 +348,7 @@ void CardReader::openAndPrintFile(const char *name) {
322 348
 void CardReader::startFileprint() {
323 349
   if (cardOK) {
324 350
     sdprinting = true;
325
-    #if ENABLED(SDCARD_SORT_ALPHA)
351
+    #if SD_RESORT
326 352
       flush_presort();
327 353
     #endif
328 354
   }
@@ -460,8 +486,12 @@ void CardReader::openFile(char* name, const bool read, const bool subcall/*=fals
460 486
       SERIAL_PROTOCOLPAIR(MSG_SD_FILE_OPENED, fname);
461 487
       SERIAL_PROTOCOLLNPAIR(MSG_SD_SIZE, filesize);
462 488
       SERIAL_PROTOCOLLNPGM(MSG_SD_FILE_SELECTED);
489
+
463 490
       getfilename(0, fname);
464 491
       lcd_setstatus(longFilename[0] ? longFilename : fname);
492
+      //if (longFilename[0]) {
493
+      //  SERIAL_PROTOCOLPAIR(MSG_SD_FILE_LONG_NAME, longFilename);
494
+      //}
465 495
     }
466 496
     else {
467 497
       SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, fname);
@@ -639,7 +669,7 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
639 669
   lsAction = LS_GetFilename;
640 670
   nrFile_index = nr;
641 671
   curDir->rewind();
642
-  lsDive("", *curDir, match);
672
+  lsDive(NULL, *curDir, match);
643 673
 }
644 674
 
645 675
 uint16_t CardReader::getnrfilenames() {
@@ -647,7 +677,7 @@ uint16_t CardReader::getnrfilenames() {
647 677
   lsAction = LS_Count;
648 678
   nrFiles = 0;
649 679
   curDir->rewind();
650
-  lsDive("", *curDir);
680
+  lsDive(NULL, *curDir);
651 681
   //SERIAL_ECHOLN(nrFiles);
652 682
   return nrFiles;
653 683
 }

+ 5
- 0
Marlin/src/sd/cardreader.h Näytä tiedosto

@@ -63,6 +63,11 @@ public:
63 63
     #endif
64 64
   );
65 65
   void printingHasFinished();
66
+  void printFilename(
67
+    #if NUM_SERIAL > 1
68
+      const int8_t port = -1
69
+    #endif
70
+  );
66 71
 
67 72
   #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
68 73
     void printLongPath(char *path

Loading…
Peruuta
Tallenna