Browse Source

Add C parameter to M27 to include the long filename

In answer to #10001

Add an option to retrieve the currently open file name (long filename if possible).
TheSFReader 7 years ago
parent
commit
2e43438e0c

+ 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
 /**

+ 30
- 0
Marlin/src/sd/cardreader.cpp View File

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();
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);

+ 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