|
@@ -29,6 +29,7 @@
|
29
|
29
|
#include "cardreader.h"
|
30
|
30
|
|
31
|
31
|
#include "../MarlinCore.h"
|
|
32
|
+#include "../libs/hex_print.h"
|
32
|
33
|
#include "../lcd/marlinui.h"
|
33
|
34
|
|
34
|
35
|
#if ENABLED(DWIN_CREALITY_LCD)
|
|
@@ -197,7 +198,7 @@ char *createFilename(char * const buffer, const dir_t &p) {
|
197
|
198
|
//
|
198
|
199
|
// Return 'true' if the item is a folder, G-code file or Binary file
|
199
|
200
|
//
|
200
|
|
-bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, bool onlyBin/*=false*/)) {
|
|
201
|
+bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin/*=false*/)) {
|
201
|
202
|
//uint8_t pn0 = p.name[0];
|
202
|
203
|
|
203
|
204
|
#if DISABLED(CUSTOM_FIRMWARE_UPLOAD)
|
|
@@ -279,12 +280,17 @@ void CardReader::selectByName(SdFile dir, const char * const match) {
|
279
|
280
|
* this can blow up the stack, so a 'depth' parameter would be a
|
280
|
281
|
* good addition.
|
281
|
282
|
*/
|
282
|
|
-void CardReader::printListing(
|
283
|
|
- SdFile parent, const char * const prepend
|
284
|
|
- OPTARG(CUSTOM_FIRMWARE_UPLOAD, bool onlyBin/*=false*/)
|
285
|
|
- OPTARG(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames/*=false*/)
|
|
283
|
+void CardReader::printListing(SdFile parent, const char * const prepend, const uint8_t lsflags
|
286
|
284
|
OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/)
|
287
|
285
|
) {
|
|
286
|
+ const bool includeTime = TERN0(M20_TIMESTAMP_SUPPORT, TEST(lsflags, LS_TIMESTAMP));
|
|
287
|
+ #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
|
|
288
|
+ const bool includeLong = TEST(lsflags, LS_LONG_FILENAME);
|
|
289
|
+ #endif
|
|
290
|
+ #if ENABLED(CUSTOM_FIRMWARE_UPLOAD)
|
|
291
|
+ const bool onlyBin = TEST(lsflags, LS_ONLY_BIN);
|
|
292
|
+ #endif
|
|
293
|
+ UNUSED(lsflags);
|
288
|
294
|
dir_t p;
|
289
|
295
|
while (parent.readDir(&p, longFilename) > 0) {
|
290
|
296
|
if (DIR_IS_SUBDIR(&p)) {
|
|
@@ -301,19 +307,17 @@ void CardReader::printListing(
|
301
|
307
|
SdFile child; // child.close() in destructor
|
302
|
308
|
if (child.open(&parent, dosFilename, O_READ)) {
|
303
|
309
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
|
304
|
|
- if (includeLongNames) {
|
305
|
|
- size_t lenPrependLong = prependLong ? strlen(prependLong) + 1 : 0;
|
|
310
|
+ if (includeLong) {
|
|
311
|
+ const size_t lenPrependLong = prependLong ? strlen(prependLong) + 1 : 0;
|
306
|
312
|
// Allocate enough stack space for the full long path including / separator
|
307
|
313
|
char pathLong[lenPrependLong + strlen(longFilename) + 1];
|
308
|
314
|
if (prependLong) { strcpy(pathLong, prependLong); pathLong[lenPrependLong - 1] = '/'; }
|
309
|
315
|
strcpy(pathLong + lenPrependLong, longFilename);
|
310
|
|
- printListing(child, path OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin), true, pathLong);
|
|
316
|
+ printListing(child, path, lsflags, pathLong);
|
|
317
|
+ continue;
|
311
|
318
|
}
|
312
|
|
- else
|
313
|
|
- printListing(child, path OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin));
|
314
|
|
- #else
|
315
|
|
- printListing(child, path OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin));
|
316
|
319
|
#endif
|
|
320
|
+ printListing(child, path, lsflags);
|
317
|
321
|
}
|
318
|
322
|
else {
|
319
|
323
|
SERIAL_ECHO_MSG(STR_SD_CANT_OPEN_SUBDIR, dosFilename);
|
|
@@ -325,8 +329,18 @@ void CardReader::printListing(
|
325
|
329
|
SERIAL_ECHO(createFilename(filename, p));
|
326
|
330
|
SERIAL_CHAR(' ');
|
327
|
331
|
SERIAL_ECHO(p.fileSize);
|
|
332
|
+ if (includeTime) {
|
|
333
|
+ SERIAL_CHAR(' ');
|
|
334
|
+ uint16_t crmodDate = p.lastWriteDate, crmodTime = p.lastWriteTime;
|
|
335
|
+ if (crmodDate < p.creationDate || (crmodDate == p.creationDate && crmodTime < p.creationTime)) {
|
|
336
|
+ crmodDate = p.creationDate;
|
|
337
|
+ crmodTime = p.creationTime;
|
|
338
|
+ }
|
|
339
|
+ SERIAL_ECHOPGM("0x", hex_word(crmodDate));
|
|
340
|
+ print_hex_word(crmodTime);
|
|
341
|
+ }
|
328
|
342
|
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
|
329
|
|
- if (includeLongNames) {
|
|
343
|
+ if (includeLong) {
|
330
|
344
|
SERIAL_CHAR(' ');
|
331
|
345
|
if (prependLong) { SERIAL_ECHO(prependLong); SERIAL_CHAR('/'); }
|
332
|
346
|
SERIAL_ECHO(longFilename[0] ? longFilename : filename);
|
|
@@ -340,16 +354,10 @@ void CardReader::printListing(
|
340
|
354
|
//
|
341
|
355
|
// List all files on the SD card
|
342
|
356
|
//
|
343
|
|
-void CardReader::ls(
|
344
|
|
- TERN_(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin/*=false*/)
|
345
|
|
- #if BOTH(CUSTOM_FIRMWARE_UPLOAD, LONG_FILENAME_HOST_SUPPORT)
|
346
|
|
- ,
|
347
|
|
- #endif
|
348
|
|
- TERN_(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames/*=false*/)
|
349
|
|
-) {
|
|
357
|
+void CardReader::ls(const uint8_t lsflags) {
|
350
|
358
|
if (flag.mounted) {
|
351
|
359
|
root.rewind();
|
352
|
|
- printListing(root, nullptr OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin) OPTARG(LONG_FILENAME_HOST_SUPPORT, includeLongNames));
|
|
360
|
+ printListing(root, nullptr, lsflags);
|
353
|
361
|
}
|
354
|
362
|
}
|
355
|
363
|
|