Browse Source

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 years ago
parent
commit
899b4df7a3
No account linked to committer's email address

+ 3
- 1
Marlin/src/gcode/gcode.h View File

85
  * M24  - Start/resume SD print. (Requires SDSUPPORT)
85
  * M24  - Start/resume SD print. (Requires SDSUPPORT)
86
  * M25  - Pause SD print. (Requires SDSUPPORT)
86
  * M25  - Pause SD print. (Requires SDSUPPORT)
87
  * M26  - Set SD position in bytes: "M26 S12345". (Requires SDSUPPORT)
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
  * M28  - Start SD write: "M28 /path/file.gco". (Requires SDSUPPORT)
91
  * M28  - Start SD write: "M28 /path/file.gco". (Requires SDSUPPORT)
90
  * M29  - Stop SD write. (Requires SDSUPPORT)
92
  * M29  - Stop SD write. (Requires SDSUPPORT)
91
  * M30  - Delete file from SD: "M30 /path/file.gco"
93
  * M30  - Delete file from SD: "M30 /path/file.gco"

+ 21
- 10
Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp View File

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
 void GcodeSuite::M27() {
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
   #if ENABLED(AUTO_REPORT_SD_STATUS)
124
   #if ENABLED(AUTO_REPORT_SD_STATUS)
114
-    if (parser.seenval('S')) {
125
+    else if (parser.seenval('S'))
115
       card.set_auto_report_interval(parser.value_byte()
126
       card.set_auto_report_interval(parser.value_byte()
116
         #if NUM_SERIAL > 1
127
         #if NUM_SERIAL > 1
117
-          , command_queue_port[cmd_queue_index_r]
128
+          , port
118
         #endif
129
         #endif
119
       );
130
       );
120
-    }
121
-    else
122
   #endif
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 View File

157
 
157
 
158
         case LS_SerialPrint:
158
         case LS_SerialPrint:
159
           createFilename(filename, p);
159
           createFilename(filename, p);
160
-          SERIAL_PROTOCOL_P(port, prepend);
160
+          if (prepend) SERIAL_PROTOCOL_P(port, prepend);
161
           SERIAL_PROTOCOL_P(port, filename);
161
           SERIAL_PROTOCOL_P(port, filename);
162
           SERIAL_PROTOCOLCHAR_P(port, ' ');
162
           SERIAL_PROTOCOLCHAR_P(port, ' ');
163
           SERIAL_PROTOCOLLN_P(port, p.fileSize);
163
           SERIAL_PROTOCOLLN_P(port, p.fileSize);
184
 ) {
184
 ) {
185
   lsAction = LS_SerialPrint;
185
   lsAction = LS_SerialPrint;
186
   root.rewind();
186
   root.rewind();
187
-  lsDive("", root
187
+  lsDive(NULL, root
188
     #if NUM_SERIAL > 1
188
     #if NUM_SERIAL > 1
189
       , NULL, port
189
       , NULL, port
190
     #endif
190
     #endif
227
 
227
 
228
       // Find the item, setting the long filename
228
       // Find the item, setting the long filename
229
       diveDir.rewind();
229
       diveDir.rewind();
230
-      lsDive("", diveDir, segment
230
+      lsDive(NULL, diveDir, segment
231
         #if NUM_SERIAL > 1
231
         #if NUM_SERIAL > 1
232
           , port
232
           , port
233
         #endif
233
         #endif
262
 
262
 
263
 #endif // LONG_FILENAME_HOST_SUPPORT
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
 void CardReader::initsd() {
291
 void CardReader::initsd() {
266
   cardOK = false;
292
   cardOK = false;
267
   if (root.isOpen()) root.close();
293
   if (root.isOpen()) root.close();
322
 void CardReader::startFileprint() {
348
 void CardReader::startFileprint() {
323
   if (cardOK) {
349
   if (cardOK) {
324
     sdprinting = true;
350
     sdprinting = true;
325
-    #if ENABLED(SDCARD_SORT_ALPHA)
351
+    #if SD_RESORT
326
       flush_presort();
352
       flush_presort();
327
     #endif
353
     #endif
328
   }
354
   }
460
       SERIAL_PROTOCOLPAIR(MSG_SD_FILE_OPENED, fname);
486
       SERIAL_PROTOCOLPAIR(MSG_SD_FILE_OPENED, fname);
461
       SERIAL_PROTOCOLLNPAIR(MSG_SD_SIZE, filesize);
487
       SERIAL_PROTOCOLLNPAIR(MSG_SD_SIZE, filesize);
462
       SERIAL_PROTOCOLLNPGM(MSG_SD_FILE_SELECTED);
488
       SERIAL_PROTOCOLLNPGM(MSG_SD_FILE_SELECTED);
489
+
463
       getfilename(0, fname);
490
       getfilename(0, fname);
464
       lcd_setstatus(longFilename[0] ? longFilename : fname);
491
       lcd_setstatus(longFilename[0] ? longFilename : fname);
492
+      //if (longFilename[0]) {
493
+      //  SERIAL_PROTOCOLPAIR(MSG_SD_FILE_LONG_NAME, longFilename);
494
+      //}
465
     }
495
     }
466
     else {
496
     else {
467
       SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, fname);
497
       SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, fname);
639
   lsAction = LS_GetFilename;
669
   lsAction = LS_GetFilename;
640
   nrFile_index = nr;
670
   nrFile_index = nr;
641
   curDir->rewind();
671
   curDir->rewind();
642
-  lsDive("", *curDir, match);
672
+  lsDive(NULL, *curDir, match);
643
 }
673
 }
644
 
674
 
645
 uint16_t CardReader::getnrfilenames() {
675
 uint16_t CardReader::getnrfilenames() {
647
   lsAction = LS_Count;
677
   lsAction = LS_Count;
648
   nrFiles = 0;
678
   nrFiles = 0;
649
   curDir->rewind();
679
   curDir->rewind();
650
-  lsDive("", *curDir);
680
+  lsDive(NULL, *curDir);
651
   //SERIAL_ECHOLN(nrFiles);
681
   //SERIAL_ECHOLN(nrFiles);
652
   return nrFiles;
682
   return nrFiles;
653
 }
683
 }

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

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

Loading…
Cancel
Save