From 0f2c9bacfd436f1d77d00e7948073083bbff22d7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 17 May 2015 17:36:32 -0700 Subject: [PATCH] M33 LONG_FILENAME_HOST_SUPPORT --- Marlin/Configuration_adv.h | 3 + Marlin/Marlin_main.cpp | 30 +++++++++ Marlin/cardreader.cpp | 67 ++++++++++++++++++- Marlin/cardreader.h | 4 ++ .../configurator/config/Configuration_adv.h | 3 + .../Felix/Configuration_adv.h | 3 + .../Hephestos/Configuration_adv.h | 3 + .../K8200/Configuration_adv.h | 3 + .../SCARA/Configuration_adv.h | 3 + .../WITBOX/Configuration_adv.h | 3 + .../delta/biv2.5/Configuration_adv.h | 3 + .../delta/generic/Configuration_adv.h | 3 + .../delta/kossel_mini/Configuration_adv.h | 3 + .../makibox/Configuration_adv.h | 3 + .../tvrrug/Round2/Configuration_adv.h | 3 + 15 files changed, 135 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index fd41e9d0dc..e7f61d0b91 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -313,6 +313,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 18911474c1..677758aeb0 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -120,6 +120,7 @@ * syntax "M32 /path/filename#", or "M32 S !filename#" * Call gcode file : "M32 P !filename#" and return to caller file after finishing (similar to #include). * The '#' is necessary when calling from within sd files, as it stops buffer prereading + * M33 - Get the longname version of a path * M42 - Change pin status via gcode Use M42 Px Sy to set pin x to value y, when omitting Px the onboard led will be used. * M48 - Measure Z_Probe repeatability. M48 [P # of points] [X position] [Y position] [V_erboseness #] [E_ngage Probe] [L # of legs of travel] * M80 - Turn on Power Supply @@ -3051,6 +3052,29 @@ inline void gcode_M31() { } } + #ifdef LONG_FILENAME_HOST_SUPPORT + + /** + * M33: Get the long full path of a file or folder + * + * Parameters: + * Case-insensitive DOS-style path to a file or folder + * + * Example: + * M33 miscel~1/armchair/armcha~1.gco + * + * Output: + * /Miscellaneous/Armchair/Armchair.gcode + */ + inline void gcode_M33() { + char *args = strchr_pointer + 4; + while (*args == ' ') ++args; + clear_asterisk(args); + card.printLongPath(args); + } + + #endif + /** * M928: Start SD Write */ @@ -5307,6 +5331,12 @@ void process_next_command() { gcode_M30(); break; case 32: //M32 - Select file and start SD print gcode_M32(); break; + + #ifdef LONG_FILENAME_HOST_SUPPORT + case 33: //M33 - Get the long full path to a file or folder + gcode_M33(); break; + #endif // LONG_FILENAME_HOST_SUPPORT + case 928: //M928 - Start SD write gcode_M928(); break; diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index a2a6d8eb51..7040f0a4b6 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -129,6 +129,69 @@ void CardReader::ls() { lsDive("", root); } +#ifdef LONG_FILENAME_HOST_SUPPORT + + /** + * Get a long pretty path based on a DOS 8.3 path + */ + void CardReader::printLongPath(char *path) { + lsAction = LS_GetFilename; + + int i, pathLen = strlen(path); + + // SERIAL_ECHOPGM("Full Path: "); SERIAL_ECHOLN(path); + + // Zero out slashes to make segments + for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0'; + + SdFile diveDir = root; // start from the root for segment 1 + for (i = 0; i < pathLen;) { + + if (path[i] == '\0') i++; // move past a single nul + + char *segment = &path[i]; // The segment after most slashes + + // If a segment is empty (extra-slash) then exit + if (!*segment) break; + + // Go to the next segment + while (path[++i]) { } + + // SERIAL_ECHOPGM("Looking for segment: "); SERIAL_ECHOLN(segment); + + // Find the item, setting the long filename + diveDir.rewind(); + lsDive("", diveDir, segment); + + // Print /LongNamePart to serial output + SERIAL_PROTOCOLCHAR('/'); + SERIAL_PROTOCOL(longFilename[0] ? longFilename : "???"); + + // If the filename was printed then that's it + if (!filenameIsDir) break; + + // SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment); + + // Open the sub-item as the new dive parent + SdFile dir; + if (!dir.open(diveDir, segment, O_READ)) { + SERIAL_EOL; + SERIAL_ECHO_START; + SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR); + SERIAL_ECHO(segment); + break; + } + + diveDir.close(); + diveDir = dir; + + } // while i 0) { for (int8_t i = 0; i < (int8_t)strlen((char*)p.name); i++) p.name[i] = tolower(p.name[i]); if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) { - char cmd[30]; + char cmd[4 + (FILENAME_LENGTH + 1) * MAX_DIR_DEPTH + 2]; sprintf_P(cmd, PSTR("M23 %s"), autoname); enqueuecommand(cmd); enqueuecommands_P(PSTR("M24")); diff --git a/Marlin/cardreader.h b/Marlin/cardreader.h index 03d4303e30..4b0b6e44cc 100644 --- a/Marlin/cardreader.h +++ b/Marlin/cardreader.h @@ -28,6 +28,10 @@ public: void getStatus(); void printingHasFinished(); + #ifdef LONG_FILENAME_HOST_SUPPORT + void printLongPath(char *path); + #endif + void getfilename(uint16_t nr, const char* const match=NULL); uint16_t getnrfilenames(); diff --git a/Marlin/configurator/config/Configuration_adv.h b/Marlin/configurator/config/Configuration_adv.h index 1119e51814..ad282a2d71 100644 --- a/Marlin/configurator/config/Configuration_adv.h +++ b/Marlin/configurator/config/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/Felix/Configuration_adv.h b/Marlin/example_configurations/Felix/Configuration_adv.h index 678ebbe083..98ba122a8d 100644 --- a/Marlin/example_configurations/Felix/Configuration_adv.h +++ b/Marlin/example_configurations/Felix/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/Hephestos/Configuration_adv.h b/Marlin/example_configurations/Hephestos/Configuration_adv.h index e1ec3fa6a7..c4caeacd94 100644 --- a/Marlin/example_configurations/Hephestos/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/K8200/Configuration_adv.h b/Marlin/example_configurations/K8200/Configuration_adv.h index 678ebbe083..98ba122a8d 100644 --- a/Marlin/example_configurations/K8200/Configuration_adv.h +++ b/Marlin/example_configurations/K8200/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/SCARA/Configuration_adv.h b/Marlin/example_configurations/SCARA/Configuration_adv.h index af4429b7e6..dc1a2a4802 100644 --- a/Marlin/example_configurations/SCARA/Configuration_adv.h +++ b/Marlin/example_configurations/SCARA/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/WITBOX/Configuration_adv.h b/Marlin/example_configurations/WITBOX/Configuration_adv.h index da2281eaf8..23edfc75e3 100644 --- a/Marlin/example_configurations/WITBOX/Configuration_adv.h +++ b/Marlin/example_configurations/WITBOX/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h b/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h index e193015cc3..688b1c2042 100644 --- a/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h +++ b/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h @@ -322,6 +322,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/delta/generic/Configuration_adv.h b/Marlin/example_configurations/delta/generic/Configuration_adv.h index a003186d81..13a5232987 100644 --- a/Marlin/example_configurations/delta/generic/Configuration_adv.h +++ b/Marlin/example_configurations/delta/generic/Configuration_adv.h @@ -322,6 +322,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h index c8ac659c32..fca0f0a4b1 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/makibox/Configuration_adv.h b/Marlin/example_configurations/makibox/Configuration_adv.h index b08e8bc2ff..1f4943544e 100644 --- a/Marlin/example_configurations/makibox/Configuration_adv.h +++ b/Marlin/example_configurations/makibox/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h index a86b3279d4..8f8fc59e60 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h @@ -321,6 +321,9 @@ //#define PROGRESS_MSG_ONCE #endif + // This allows hosts to request long names for files and folders with M33 + //#define LONG_FILENAME_HOST_SUPPORT + #endif // SDSUPPORT // @section more