Przeglądaj źródła

Add card.longest_filename method

Scott Lahteine 7 lat temu
rodzic
commit
065e9c3d66

+ 13
- 15
Marlin/src/lcd/ultralcd.cpp Wyświetl plik

@@ -277,8 +277,8 @@ uint16_t max_display_update_time = 0;
277 277
 
278 278
   #if ENABLED(SDSUPPORT)
279 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 282
   #endif
283 283
 
284 284
   ////////////////////////////////////////////
@@ -768,7 +768,7 @@ void lcd_reset_status() {
768 768
     msg = paused;
769 769
   #if ENABLED(SDSUPPORT)
770 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 772
   #endif
773 773
   else if (print_job_timer.isRunning())
774 774
     msg = printing;
@@ -1002,9 +1002,9 @@ void lcd_quick_feedback(const bool clear_buttons) {
1002 1002
       bar_percent = constrain(bar_percent, 0, 100);
1003 1003
       encoderPosition = 0;
1004 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 1010
     void _progress_bar_test() {
@@ -2938,7 +2938,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2938 2938
         destination[manual_move_axis] += manual_move_offset;
2939 2939
 
2940 2940
         // Reset for the next move
2941
-        manual_move_offset = 0.0;
2941
+        manual_move_offset = 0;
2942 2942
         manual_move_axis = (int8_t)NO_AXIS;
2943 2943
 
2944 2944
         // DELTA and SCARA machines use segmented moves, which could fill the planner during the call to
@@ -4042,9 +4042,9 @@ void lcd_quick_feedback(const bool clear_buttons) {
4042 4042
           #endif
4043 4043
 
4044 4044
           if (card.filenameIsDir)
4045
-            MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
4045
+            MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
4046 4046
           else
4047
-            MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
4047
+            MENU_ITEM(sdfile, MSG_CARD_MENU, card);
4048 4048
         }
4049 4049
         else {
4050 4050
           MENU_ITEM_DUMMY();
@@ -4965,19 +4965,17 @@ void lcd_quick_feedback(const bool clear_buttons) {
4965 4965
 
4966 4966
   #if ENABLED(SDSUPPORT)
4967 4967
 
4968
-    void menu_action_sdfile(const char* filename, char* longFilename) {
4968
+    void menu_action_sdfile(CardReader &theCard) {
4969 4969
       #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
4970 4970
         last_sdfile_encoderPosition = encoderPosition;  // Save which file was selected for later use
4971 4971
       #endif
4972
-      UNUSED(longFilename);
4973
-      card.openAndPrintFile(filename);
4972
+      card.openAndPrintFile(theCard.filename);
4974 4973
       lcd_return_to_status();
4975 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 4979
       encoderTopLine = 0;
4982 4980
       encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
4983 4981
       screen_changed = true;

+ 8
- 8
Marlin/src/lcd/ultralcd_impl_DOGM.h Wyświetl plik

@@ -518,7 +518,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
518 518
 
519 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 522
       UNUSED(pstr);
523 523
 
524 524
       lcd_implementation_mark_as_selected(row, isSelected);
@@ -526,23 +526,23 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
526 526
       if (!PAGE_CONTAINS(row_y1, row_y2)) return;
527 527
 
528 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 531
         #if ENABLED(SCROLL_LONG_FILENAMES)
532 532
           if (isSelected) {
533 533
             uint8_t name_hash = row;
534 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 536
             if (filename_scroll_hash != name_hash) {                            // If the hash changed...
537 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 539
               filename_scroll_pos = 0;                                          // Reset scroll to the start
540 540
               lcd_status_update_delay = 8;                                      // Don't scroll right away
541 541
             }
542 542
             outstr += filename_scroll_pos;
543 543
           }
544 544
         #else
545
-          longFilename[maxlen] = '\0'; // cutoff at screen edge
545
+          theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
546 546
         #endif
547 547
       }
548 548
 
@@ -554,8 +554,8 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
554 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 560
   #endif // SDSUPPORT
561 561
 

+ 10
- 10
Marlin/src/lcd/ultralcd_impl_HD44780.h Wyświetl plik

@@ -926,29 +926,29 @@ static void lcd_implementation_status_screen() {
926 926
 
927 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 930
       UNUSED(pstr);
931 931
       lcd_moveto(0, row);
932 932
       lcd_put_wchar(sel ? '>' : ' ');
933 933
 
934 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 937
         #if ENABLED(SCROLL_LONG_FILENAMES)
938 938
           if (sel) {
939 939
             uint8_t name_hash = row;
940 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 942
             if (filename_scroll_hash != name_hash) {                            // If the hash changed...
943 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 945
               filename_scroll_pos = 0;                                          // Reset scroll to the start
946 946
               lcd_status_update_delay = 8;                                      // Don't scroll right away
947 947
             }
948 948
             outstr += filename_scroll_pos;
949 949
           }
950 950
         #else
951
-          longFilename[n] = '\0'; // cutoff at screen edge
951
+          theCard.longFilename[n] = '\0'; // cutoff at screen edge
952 952
         #endif
953 953
       }
954 954
 
@@ -960,12 +960,12 @@ static void lcd_implementation_status_screen() {
960 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 971
   #endif // SDSUPPORT

+ 8
- 10
Marlin/src/sd/cardreader.cpp Wyświetl plik

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

+ 2
- 0
Marlin/src/sd/cardreader.h Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz