Browse Source

Add card.longest_filename method

Scott Lahteine 7 years ago
parent
commit
065e9c3d66

+ 13
- 15
Marlin/src/lcd/ultralcd.cpp View File

277
 
277
 
278
   #if ENABLED(SDSUPPORT)
278
   #if ENABLED(SDSUPPORT)
279
     void lcd_sdcard_menu();
279
     void lcd_sdcard_menu();
280
-    void menu_action_sdfile(const char* filename, char* longFilename);
281
-    void menu_action_sddirectory(const char* filename, char* longFilename);
280
+    void menu_action_sdfile(CardReader &theCard);
281
+    void menu_action_sddirectory(CardReader &theCard);
282
   #endif
282
   #endif
283
 
283
 
284
   ////////////////////////////////////////////
284
   ////////////////////////////////////////////
768
     msg = paused;
768
     msg = paused;
769
   #if ENABLED(SDSUPPORT)
769
   #if ENABLED(SDSUPPORT)
770
     else if (card.sdprinting)
770
     else if (card.sdprinting)
771
-      return lcd_setstatus(card.longFilename[0] ? card.longFilename : card.filename, true);
771
+      return lcd_setstatus(card.longest_filename(), true);
772
   #endif
772
   #endif
773
   else if (print_job_timer.isRunning())
773
   else if (print_job_timer.isRunning())
774
     msg = printing;
774
     msg = printing;
1002
       bar_percent = constrain(bar_percent, 0, 100);
1002
       bar_percent = constrain(bar_percent, 0, 100);
1003
       encoderPosition = 0;
1003
       encoderPosition = 0;
1004
       lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
1004
       lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
1005
-      lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
1006
-      lcd.print(itostr3(bar_percent)); lcd.write('%');
1007
-      lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
1005
+      lcd_moveto((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
1006
+      lcd_put_u8str(int(bar_percent)); lcd_put_wchar('%');
1007
+      lcd_moveto(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
1008
     }
1008
     }
1009
 
1009
 
1010
     void _progress_bar_test() {
1010
     void _progress_bar_test() {
2938
         destination[manual_move_axis] += manual_move_offset;
2938
         destination[manual_move_axis] += manual_move_offset;
2939
 
2939
 
2940
         // Reset for the next move
2940
         // Reset for the next move
2941
-        manual_move_offset = 0.0;
2941
+        manual_move_offset = 0;
2942
         manual_move_axis = (int8_t)NO_AXIS;
2942
         manual_move_axis = (int8_t)NO_AXIS;
2943
 
2943
 
2944
         // DELTA and SCARA machines use segmented moves, which could fill the planner during the call to
2944
         // DELTA and SCARA machines use segmented moves, which could fill the planner during the call to
4042
           #endif
4042
           #endif
4043
 
4043
 
4044
           if (card.filenameIsDir)
4044
           if (card.filenameIsDir)
4045
-            MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
4045
+            MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
4046
           else
4046
           else
4047
-            MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
4047
+            MENU_ITEM(sdfile, MSG_CARD_MENU, card);
4048
         }
4048
         }
4049
         else {
4049
         else {
4050
           MENU_ITEM_DUMMY();
4050
           MENU_ITEM_DUMMY();
4965
 
4965
 
4966
   #if ENABLED(SDSUPPORT)
4966
   #if ENABLED(SDSUPPORT)
4967
 
4967
 
4968
-    void menu_action_sdfile(const char* filename, char* longFilename) {
4968
+    void menu_action_sdfile(CardReader &theCard) {
4969
       #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
4969
       #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
4970
         last_sdfile_encoderPosition = encoderPosition;  // Save which file was selected for later use
4970
         last_sdfile_encoderPosition = encoderPosition;  // Save which file was selected for later use
4971
       #endif
4971
       #endif
4972
-      UNUSED(longFilename);
4973
-      card.openAndPrintFile(filename);
4972
+      card.openAndPrintFile(theCard.filename);
4974
       lcd_return_to_status();
4973
       lcd_return_to_status();
4975
       lcd_reset_status();
4974
       lcd_reset_status();
4976
     }
4975
     }
4977
 
4976
 
4978
-    void menu_action_sddirectory(const char* filename, char* longFilename) {
4979
-      UNUSED(longFilename);
4980
-      card.chdir(filename);
4977
+    void menu_action_sddirectory(CardReader &theCard) {
4978
+      card.chdir(theCard.filename);
4981
       encoderTopLine = 0;
4979
       encoderTopLine = 0;
4982
       encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
4980
       encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
4983
       screen_changed = true;
4981
       screen_changed = true;

+ 8
- 8
Marlin/src/lcd/ultralcd_impl_DOGM.h View File

518
 
518
 
519
   #if ENABLED(SDSUPPORT)
519
   #if ENABLED(SDSUPPORT)
520
 
520
 
521
-    static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const bool isDir) {
521
+    static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, CardReader &theCard, const bool isDir) {
522
       UNUSED(pstr);
522
       UNUSED(pstr);
523
 
523
 
524
       lcd_implementation_mark_as_selected(row, isSelected);
524
       lcd_implementation_mark_as_selected(row, isSelected);
526
       if (!PAGE_CONTAINS(row_y1, row_y2)) return;
526
       if (!PAGE_CONTAINS(row_y1, row_y2)) return;
527
 
527
 
528
       constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
528
       constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
529
-      const char *outstr = longFilename[0] ? longFilename : filename;
530
-      if (longFilename[0]) {
529
+      const char *outstr = theCard.longest_filename();
530
+      if (theCard.longFilename[0]) {
531
         #if ENABLED(SCROLL_LONG_FILENAMES)
531
         #if ENABLED(SCROLL_LONG_FILENAMES)
532
           if (isSelected) {
532
           if (isSelected) {
533
             uint8_t name_hash = row;
533
             uint8_t name_hash = row;
534
             for (uint8_t l = FILENAME_LENGTH; l--;)
534
             for (uint8_t l = FILENAME_LENGTH; l--;)
535
-              name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l];  // rotate, xor
535
+              name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l];  // rotate, xor
536
             if (filename_scroll_hash != name_hash) {                            // If the hash changed...
536
             if (filename_scroll_hash != name_hash) {                            // If the hash changed...
537
               filename_scroll_hash = name_hash;                                 // Save the new hash
537
               filename_scroll_hash = name_hash;                                 // Save the new hash
538
-              filename_scroll_max = MAX(0, utf8_strlen(longFilename) - maxlen); // Update the scroll limit
538
+              filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
539
               filename_scroll_pos = 0;                                          // Reset scroll to the start
539
               filename_scroll_pos = 0;                                          // Reset scroll to the start
540
               lcd_status_update_delay = 8;                                      // Don't scroll right away
540
               lcd_status_update_delay = 8;                                      // Don't scroll right away
541
             }
541
             }
542
             outstr += filename_scroll_pos;
542
             outstr += filename_scroll_pos;
543
           }
543
           }
544
         #else
544
         #else
545
-          longFilename[maxlen] = '\0'; // cutoff at screen edge
545
+          theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
546
         #endif
546
         #endif
547
       }
547
       }
548
 
548
 
554
       while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
554
       while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
555
     }
555
     }
556
 
556
 
557
-    #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
558
-    #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
557
+    #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, false)
558
+    #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, true)
559
 
559
 
560
   #endif // SDSUPPORT
560
   #endif // SDSUPPORT
561
 
561
 

+ 10
- 10
Marlin/src/lcd/ultralcd_impl_HD44780.h View File

926
 
926
 
927
   #if ENABLED(SDSUPPORT)
927
   #if ENABLED(SDSUPPORT)
928
 
928
 
929
-    static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const uint8_t concat, const char post_char) {
929
+    static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, CardReader &theCard, const uint8_t concat, const char post_char) {
930
       UNUSED(pstr);
930
       UNUSED(pstr);
931
       lcd_moveto(0, row);
931
       lcd_moveto(0, row);
932
       lcd_put_wchar(sel ? '>' : ' ');
932
       lcd_put_wchar(sel ? '>' : ' ');
933
 
933
 
934
       uint8_t n = LCD_WIDTH - concat;
934
       uint8_t n = LCD_WIDTH - concat;
935
-      const char *outstr = longFilename[0] ? longFilename : filename;
936
-      if (longFilename[0]) {
935
+      const char *outstr = theCard.longest_filename();
936
+      if (theCard.longFilename[0]) {
937
         #if ENABLED(SCROLL_LONG_FILENAMES)
937
         #if ENABLED(SCROLL_LONG_FILENAMES)
938
           if (sel) {
938
           if (sel) {
939
             uint8_t name_hash = row;
939
             uint8_t name_hash = row;
940
             for (uint8_t l = FILENAME_LENGTH; l--;)
940
             for (uint8_t l = FILENAME_LENGTH; l--;)
941
-              name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l];  // rotate, xor
941
+              name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l];  // rotate, xor
942
             if (filename_scroll_hash != name_hash) {                            // If the hash changed...
942
             if (filename_scroll_hash != name_hash) {                            // If the hash changed...
943
               filename_scroll_hash = name_hash;                                 // Save the new hash
943
               filename_scroll_hash = name_hash;                                 // Save the new hash
944
-              filename_scroll_max = MAX(0, utf8_strlen(longFilename) - n);  // Update the scroll limit
944
+              filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - n);  // Update the scroll limit
945
               filename_scroll_pos = 0;                                          // Reset scroll to the start
945
               filename_scroll_pos = 0;                                          // Reset scroll to the start
946
               lcd_status_update_delay = 8;                                      // Don't scroll right away
946
               lcd_status_update_delay = 8;                                      // Don't scroll right away
947
             }
947
             }
948
             outstr += filename_scroll_pos;
948
             outstr += filename_scroll_pos;
949
           }
949
           }
950
         #else
950
         #else
951
-          longFilename[n] = '\0'; // cutoff at screen edge
951
+          theCard.longFilename[n] = '\0'; // cutoff at screen edge
952
         #endif
952
         #endif
953
       }
953
       }
954
 
954
 
960
       lcd_put_wchar(post_char);
960
       lcd_put_wchar(post_char);
961
     }
961
     }
962
 
962
 
963
-    static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
964
-      lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, ' ');
963
+    static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, CardReader &theCard) {
964
+      lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, ' ');
965
     }
965
     }
966
 
966
 
967
-    static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
968
-      lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, LCD_STR_FOLDER[0]);
967
+    static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, CardReader &theCard) {
968
+      lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, LCD_STR_FOLDER[0]);
969
     }
969
     }
970
 
970
 
971
   #endif // SDSUPPORT
971
   #endif // SDSUPPORT

+ 8
- 10
Marlin/src/sd/cardreader.cpp View File

43
 
43
 
44
 #include <ctype.h>
44
 #include <ctype.h>
45
 
45
 
46
-#define LONGEST_FILENAME (longFilename[0] ? longFilename : filename)
47
-
48
 CardReader::CardReader() {
46
 CardReader::CardReader() {
49
   #if ENABLED(SDCARD_SORT_ALPHA)
47
   #if ENABLED(SDCARD_SORT_ALPHA)
50
     sort_count = 0;
48
     sort_count = 0;
771
             getfilename(i);
769
             getfilename(i);
772
             #if ENABLED(SDSORT_DYNAMIC_RAM)
770
             #if ENABLED(SDSORT_DYNAMIC_RAM)
773
               // Use dynamic method to copy long filename
771
               // Use dynamic method to copy long filename
774
-              sortnames[i] = strdup(LONGEST_FILENAME);
772
+              sortnames[i] = strdup(longest_filename());
775
               #if ENABLED(SDSORT_CACHE_NAMES)
773
               #if ENABLED(SDSORT_CACHE_NAMES)
776
                 // When caching also store the short name, since
774
                 // When caching also store the short name, since
777
                 // we're replacing the getfilename() behavior.
775
                 // we're replacing the getfilename() behavior.
780
             #else
778
             #else
781
               // Copy filenames into the static array
779
               // Copy filenames into the static array
782
               #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
780
               #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
783
-                strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
781
+                strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
784
                 sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
782
                 sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
785
               #else
783
               #else
786
-                strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
784
+                strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
787
               #endif
785
               #endif
788
               #if ENABLED(SDSORT_CACHE_NAMES)
786
               #if ENABLED(SDSORT_CACHE_NAMES)
789
                 strcpy(sortshort[i], filename);
787
                 strcpy(sortshort[i], filename);
831
             // throughout the loop. Slow if there are many.
829
             // throughout the loop. Slow if there are many.
832
             #if DISABLED(SDSORT_USES_RAM)
830
             #if DISABLED(SDSORT_USES_RAM)
833
               getfilename(o1);
831
               getfilename(o1);
834
-              strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
832
+              strcpy(name1, longest_filename()); // save (or getfilename below will trounce it)
835
               #if HAS_FOLDER_SORTING
833
               #if HAS_FOLDER_SORTING
836
                 bool dir1 = filenameIsDir;
834
                 bool dir1 = filenameIsDir;
837
               #endif
835
               #endif
838
               getfilename(o2);
836
               getfilename(o2);
839
-              char *name2 = LONGEST_FILENAME; // use the string in-place
837
+              char *name2 = longest_filename(); // use the string in-place
840
             #endif // !SDSORT_USES_RAM
838
             #endif // !SDSORT_USES_RAM
841
 
839
 
842
             // Sort the current pair according to settings.
840
             // Sort the current pair according to settings.
874
           getfilename(0);
872
           getfilename(0);
875
           #if ENABLED(SDSORT_DYNAMIC_RAM)
873
           #if ENABLED(SDSORT_DYNAMIC_RAM)
876
             sortnames = new char*[1];
874
             sortnames = new char*[1];
877
-            sortnames[0] = strdup(LONGEST_FILENAME); // malloc
875
+            sortnames[0] = strdup(longest_filename()); // malloc
878
             #if ENABLED(SDSORT_CACHE_NAMES)
876
             #if ENABLED(SDSORT_CACHE_NAMES)
879
               sortshort = new char*[1];
877
               sortshort = new char*[1];
880
               sortshort[0] = strdup(filename);       // malloc
878
               sortshort[0] = strdup(filename);       // malloc
882
             isDir = new uint8_t[1];
880
             isDir = new uint8_t[1];
883
           #else
881
           #else
884
             #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
882
             #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
885
-              strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
883
+              strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
886
               sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
884
               sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
887
             #else
885
             #else
888
-              strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
886
+              strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
889
             #endif
887
             #endif
890
             #if ENABLED(SDSORT_CACHE_NAMES)
888
             #if ENABLED(SDSORT_CACHE_NAMES)
891
               strcpy(sortshort[0], filename);
889
               strcpy(sortshort[0], filename);

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

144
     }
144
     }
145
   #endif
145
   #endif
146
 
146
 
147
+  FORCE_INLINE char* longest_filename() { return longFilename[0] ? longFilename : filename; }
148
+
147
 public:
149
 public:
148
   bool saving, logging, sdprinting, cardOK, filenameIsDir;
150
   bool saving, logging, sdprinting, cardOK, filenameIsDir;
149
   char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];
151
   char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];

Loading…
Cancel
Save