ソースを参照

Make CardReader class static (#12451)

* Make CardReader a static class
* Make CardReader flags into bitfields
Scott Lahteine 6年前
コミット
66580f32c2
コミッターのメールアドレスに関連付けられたアカウントが存在しません

+ 5
- 5
Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp ファイルの表示

@@ -19,7 +19,7 @@ void sd_mmc_spi_mem_init(void) {
19 19
 }
20 20
 
21 21
 Ctrl_status sd_mmc_spi_test_unit_ready(void) {
22
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.cardOK)
22
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
23 23
     return CTRL_NO_PRESENT;
24 24
   return CTRL_GOOD;
25 25
 }
@@ -27,7 +27,7 @@ Ctrl_status sd_mmc_spi_test_unit_ready(void) {
27 27
 // NOTE: This function is defined as returning the address of the last block
28 28
 // in the card, which is cardSize() - 1
29 29
 Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
30
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.cardOK)
30
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
31 31
     return CTRL_NO_PRESENT;
32 32
   *nb_sector = card.getSd2Card().cardSize() - 1;
33 33
   return CTRL_GOOD;
@@ -42,7 +42,7 @@ bool sd_mmc_spi_wr_protect(void) {
42 42
 }
43 43
 
44 44
 bool sd_mmc_spi_removal(void) {
45
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.cardOK)
45
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
46 46
     return true;
47 47
   return false;
48 48
 }
@@ -61,7 +61,7 @@ uint8_t sector_buf[SD_MMC_BLOCK_SIZE];
61 61
 // #define DEBUG_MMC
62 62
 
63 63
 Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
64
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.cardOK)
64
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
65 65
     return CTRL_NO_PRESENT;
66 66
 
67 67
   #ifdef DEBUG_MMC
@@ -95,7 +95,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
95 95
 }
96 96
 
97 97
 Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
98
-  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.cardOK)
98
+  if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
99 99
     return CTRL_NO_PRESENT;
100 100
 
101 101
   #ifdef DEBUG_MMC

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/main.cpp ファイルの表示

@@ -106,7 +106,7 @@ void HAL_idletask(void) {
106 106
     // the disk if Marlin has it mounted. Unfortuately there is currently no way
107 107
     // to unmount the disk from the LCD menu.
108 108
     // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
109
-    if (card.cardOK)
109
+    if (card.flag.cardOK)
110 110
       MSC_Aquire_Lock();
111 111
     else
112 112
       MSC_Release_Lock();

+ 2
- 2
Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp ファイルの表示

@@ -41,7 +41,7 @@ char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
41 41
 char eeprom_filename[] = "eeprom.dat";
42 42
 
43 43
 bool PersistentStore::access_start() {
44
-  if (!card.cardOK) return false;
44
+  if (!card.flag.cardOK) return false;
45 45
   int16_t bytes_read = 0;
46 46
   constexpr char eeprom_zero = 0xFF;
47 47
   card.openFile(eeprom_filename, true);
@@ -54,7 +54,7 @@ bool PersistentStore::access_start() {
54 54
 }
55 55
 
56 56
 bool PersistentStore::access_finish() {
57
-  if (!card.cardOK) return false;
57
+  if (!card.flag.cardOK) return false;
58 58
   card.openFile(eeprom_filename, true);
59 59
   int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
60 60
   card.closefile();

+ 1
- 1
Marlin/src/Marlin.cpp ファイルの表示

@@ -967,7 +967,7 @@ void loop() {
967 967
     #if ENABLED(SDSUPPORT)
968 968
       card.checkautostart();
969 969
 
970
-      if (card.abort_sd_printing) {
970
+      if (card.flag.abort_sd_printing) {
971 971
         card.stopSDPrint(
972 972
           #if SD_RESORT
973 973
             true

+ 2
- 2
Marlin/src/feature/power_loss_recovery.cpp ファイルの表示

@@ -84,8 +84,8 @@ void PrintJobRecovery::changed() {
84 84
  */
85 85
 void PrintJobRecovery::check() {
86 86
   if (enabled) {
87
-    if (!card.cardOK) card.initsd();
88
-    if (card.cardOK) {
87
+    if (!card.flag.cardOK) card.initsd();
88
+    if (card.flag.cardOK) {
89 89
       load();
90 90
       if (!valid()) return purge();
91 91
       enqueue_and_echo_commands_P(PSTR("M1000 S"));

+ 1
- 1
Marlin/src/feature/power_loss_recovery.h ファイルの表示

@@ -68,7 +68,7 @@ typedef struct {
68 68
   char command_queue[BUFSIZE][MAX_CMD_SIZE];
69 69
 
70 70
   // SD Filename and position
71
-  char sd_filename[MAXPATHNAMELENGTH];
71
+  char sd_filename[MAXPATHNAMELENGTH + 1];
72 72
   uint32_t sdpos;
73 73
 
74 74
   // Job elapsed time

+ 6
- 6
Marlin/src/gcode/queue.cpp ファイルの表示

@@ -503,7 +503,7 @@ static int read_serial(const uint8_t index) {
503 503
             break;
504 504
           case StreamState::STREAM_COMPLETE:
505 505
             stream_state = StreamState::STREAM_RESET;
506
-            card.binary_mode = false;
506
+            card.flag.binary_mode = false;
507 507
             card.closefile();
508 508
             CARD_ECHO_P("echo: ");
509 509
             CARD_ECHO_P(card.filename);
@@ -514,7 +514,7 @@ static int read_serial(const uint8_t index) {
514 514
             return;
515 515
           case StreamState::STREAM_FAILED:
516 516
             stream_state = StreamState::STREAM_RESET;
517
-            card.binary_mode = false;
517
+            card.flag.binary_mode = false;
518 518
             card.closefile();
519 519
             card.removeFile(card.filename);
520 520
             CARD_ECHOLN_P("echo: File transfer failed");
@@ -549,7 +549,7 @@ inline void get_serial_commands() {
549 549
             ;
550 550
 
551 551
   #if ENABLED(FAST_FILE_TRANSFER)
552
-    if (card.saving && card.binary_mode) {
552
+    if (card.flag.saving && card.flag.binary_mode) {
553 553
       /**
554 554
        * For binary stream file transfer, use serial_line_buffer as the working
555 555
        * receive buffer (which limits the packet size to MAX_CMD_SIZE).
@@ -630,7 +630,7 @@ inline void get_serial_commands() {
630 630
           gcode_LastN = gcode_N;
631 631
         }
632 632
         #if ENABLED(SDSUPPORT)
633
-          else if (card.saving && strcmp(command, "M29") != 0) // No line number with M29 in Pronterface
633
+          else if (card.flag.saving && strcmp(command, "M29") != 0) // No line number with M29 in Pronterface
634 634
             return gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM), i);
635 635
         #endif
636 636
 
@@ -838,7 +838,7 @@ void advance_command_queue() {
838 838
 
839 839
   #if ENABLED(SDSUPPORT)
840 840
 
841
-    if (card.saving) {
841
+    if (card.flag.saving) {
842 842
       char* command = command_queue[cmd_queue_index_r];
843 843
       if (strstr_P(command, PSTR("M29"))) {
844 844
         // M29 closes the file
@@ -860,7 +860,7 @@ void advance_command_queue() {
860 860
       else {
861 861
         // Write the string from the read buffer to SD
862 862
         card.write_command(command);
863
-        if (card.logging)
863
+        if (card.flag.logging)
864 864
           gcode.process_next_command(); // The card is saving because it's logging
865 865
         else
866 866
           ok_to_send();

+ 6
- 6
Marlin/src/gcode/sdcard/M20-M30_M32-M34_M524_M928.cpp ファイルの表示

@@ -118,7 +118,7 @@ void GcodeSuite::M25() {
118 118
  * M26: Set SD Card file index
119 119
  */
120 120
 void GcodeSuite::M26() {
121
-  if (card.cardOK && parser.seenval('S'))
121
+  if (card.flag.cardOK && parser.seenval('S'))
122 122
     card.setIndex(parser.value_long());
123 123
 }
124 124
 
@@ -178,7 +178,7 @@ void GcodeSuite::M28() {
178 178
     }
179 179
 
180 180
     // Binary transfer mode
181
-    if ((card.binary_mode = binary_mode)) {
181
+    if ((card.flag.binary_mode = binary_mode)) {
182 182
       SERIAL_ECHO_START_P(port);
183 183
       SERIAL_ECHO_P(port, " preparing to receive: ");
184 184
       SERIAL_ECHOLN_P(port, p);
@@ -202,14 +202,14 @@ void GcodeSuite::M28() {
202 202
  * Processed in write to file routine
203 203
  */
204 204
 void GcodeSuite::M29() {
205
-  // card.saving = false;
205
+  // card.flag.saving = false;
206 206
 }
207 207
 
208 208
 /**
209 209
  * M30 <filename>: Delete SD Card file
210 210
  */
211 211
 void GcodeSuite::M30() {
212
-  if (card.cardOK) {
212
+  if (card.flag.cardOK) {
213 213
     card.closefile();
214 214
     card.removeFile(parser.string_arg);
215 215
   }
@@ -228,7 +228,7 @@ void GcodeSuite::M30() {
228 228
 void GcodeSuite::M32() {
229 229
   if (IS_SD_PRINTING()) planner.synchronize();
230 230
 
231
-  if (card.cardOK) {
231
+  if (card.flag.cardOK) {
232 232
     const bool call_procedure = parser.boolval('P');
233 233
 
234 234
     card.openFile(parser.string_arg, true, call_procedure);
@@ -286,7 +286,7 @@ void GcodeSuite::M32() {
286 286
  * M524: Abort the current SD print job (started with M24)
287 287
  */
288 288
 void GcodeSuite::M524() {
289
-  if (IS_SD_PRINTING()) card.abort_sd_printing = true;
289
+  if (IS_SD_PRINTING()) card.flag.abort_sd_printing = true;
290 290
 }
291 291
 
292 292
 /**

+ 6
- 6
Marlin/src/lcd/extensible_ui/ui_api.cpp ファイルの表示

@@ -575,7 +575,7 @@ namespace ExtUI {
575 575
   }
576 576
 
577 577
   bool isPrintingFromMedia() {
578
-    return IFSD(card.cardOK && card.isFileOpen(), false);
578
+    return IFSD(card.flag.cardOK && card.isFileOpen(), false);
579 579
   }
580 580
 
581 581
   bool isPrinting() {
@@ -583,7 +583,7 @@ namespace ExtUI {
583 583
   }
584 584
 
585 585
   bool isMediaInserted() {
586
-    return IFSD(IS_SD_INSERTED() && card.cardOK, false);
586
+    return IFSD(IS_SD_INSERTED() && card.flag.cardOK, false);
587 587
   }
588 588
 
589 589
   void pausePrint() {
@@ -612,7 +612,7 @@ namespace ExtUI {
612 612
   void stopPrint() {
613 613
     #if ENABLED(SDSUPPORT)
614 614
       wait_for_heatup = wait_for_user = false;
615
-      card.abort_sd_printing = true;
615
+      card.flag.abort_sd_printing = true;
616 616
       ExtUI::onStatusChanged(PSTR(MSG_PRINT_ABORTED));
617 617
     #endif
618 618
   }
@@ -648,7 +648,7 @@ namespace ExtUI {
648 648
   }
649 649
 
650 650
   bool FileList::isDir() {
651
-    return IFSD(card.filenameIsDir, false);
651
+    return IFSD(card.flag.filenameIsDir, false);
652 652
   }
653 653
 
654 654
   uint16_t FileList::count() {
@@ -697,13 +697,13 @@ void MarlinUI::update() {
697 697
       last_sd_status = sd_status;
698 698
       if (sd_status) {
699 699
         card.initsd();
700
-        if (card.cardOK)
700
+        if (card.flag.cardOK)
701 701
           ExtUI::onMediaInserted();
702 702
         else
703 703
           ExtUI::onMediaError();
704 704
       }
705 705
       else {
706
-        const bool ok = card.cardOK;
706
+        const bool ok = card.flag.cardOK;
707 707
         card.release();
708 708
         if (ok) ExtUI::onMediaRemoved();
709 709
       }

+ 3
- 3
Marlin/src/lcd/malyanlcd.cpp ファイルの表示

@@ -278,7 +278,7 @@ void process_lcd_p_command(const char* command) {
278 278
         // There may be a difference in how V1 and V2 LCDs handle subdirectory
279 279
         // prints. Investigate more. This matches the V1 motion controller actions
280 280
         // but the V2 LCD switches to "print" mode on {SYS:DIR} response.
281
-        if (card.filenameIsDir) {
281
+        if (card.flag.filenameIsDir) {
282 282
           card.chdir(card.filename);
283 283
           write_to_lcd_P(PSTR("{SYS:DIR}"));
284 284
         }
@@ -330,7 +330,7 @@ void process_lcd_s_command(const char* command) {
330 330
 
331 331
     case 'L': {
332 332
       #if ENABLED(SDSUPPORT)
333
-        if (!card.cardOK) card.initsd();
333
+        if (!card.flag.cardOK) card.initsd();
334 334
 
335 335
         // A more efficient way to do this would be to
336 336
         // implement a callback in the ls_SerialPrint code, but
@@ -342,7 +342,7 @@ void process_lcd_s_command(const char* command) {
342 342
         uint16_t file_count = card.get_num_Files();
343 343
         for (uint16_t i = 0; i < file_count; i++) {
344 344
           card.getfilename(i);
345
-          sprintf_P(message_buffer, card.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.longest_filename());
345
+          sprintf_P(message_buffer, card.flag.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.longest_filename());
346 346
           write_to_lcd(message_buffer);
347 347
         }
348 348
 

+ 2
- 2
Marlin/src/lcd/menu/menu_main.cpp ファイルの表示

@@ -58,7 +58,7 @@
58 58
 
59 59
   void lcd_sdcard_stop() {
60 60
     wait_for_heatup = wait_for_user = false;
61
-    card.abort_sd_printing = true;
61
+    card.flag.abort_sd_printing = true;
62 62
     ui.setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
63 63
     ui.return_to_status();
64 64
   }
@@ -86,7 +86,7 @@ void menu_main() {
86 86
   MENU_BACK(MSG_WATCH);
87 87
 
88 88
   #if ENABLED(SDSUPPORT)
89
-    if (card.cardOK) {
89
+    if (card.flag.cardOK) {
90 90
       if (card.isFileOpen()) {
91 91
         if (IS_SD_PRINTING())
92 92
           MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);

+ 1
- 1
Marlin/src/lcd/menu/menu_sdcard.cpp ファイルの表示

@@ -125,7 +125,7 @@ void menu_sdcard() {
125 125
 
126 126
       card.getfilename_sorted(nr);
127 127
 
128
-      if (card.filenameIsDir)
128
+      if (card.flag.filenameIsDir)
129 129
         MENU_ITEM(sdfolder, MSG_CARD_MENU, card);
130 130
       else
131 131
         MENU_ITEM(sdfile, MSG_CARD_MENU, card);

+ 2
- 2
Marlin/src/sd/SdFatConfig.h ファイルの表示

@@ -106,7 +106,7 @@
106 106
  * Defines for 8.3 and long (vfat) filenames
107 107
  */
108 108
 
109
-#define FILENAME_LENGTH 13 // Number of UTF-16 characters per entry
109
+#define FILENAME_LENGTH 12 // Number of UTF-16 characters per entry
110 110
 
111 111
 // Total bytes needed to store a single long filename
112
-#define LONG_FILENAME_LENGTH (FILENAME_LENGTH * MAX_VFAT_ENTRIES + 1)
112
+#define LONG_FILENAME_LENGTH ((FILENAME_LENGTH) * (MAX_VFAT_ENTRIES))

+ 143
- 69
Marlin/src/sd/cardreader.cpp ファイルの表示

@@ -45,7 +45,83 @@
45 45
   #include "../feature/pause.h"
46 46
 #endif
47 47
 
48
-#include <ctype.h>
48
+// public:
49
+
50
+card_flags_t CardReader::flag;
51
+char CardReader::filename[FILENAME_LENGTH + 1], CardReader::longFilename[LONG_FILENAME_LENGTH + 1];
52
+int8_t CardReader::autostart_index;
53
+
54
+#if ENABLED(FAST_FILE_TRANSFER)
55
+  #if NUM_SERIAL > 1
56
+    uint8_t CardReader::transfer_port;
57
+  #endif
58
+#endif
59
+
60
+// private:
61
+
62
+SdFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH];
63
+uint8_t CardReader::workDirDepth;
64
+
65
+#if ENABLED(SDCARD_SORT_ALPHA)
66
+  uint16_t CardReader::sort_count;
67
+  #if ENABLED(SDSORT_GCODE)
68
+    bool CardReader::sort_alpha;
69
+    int CardReader::sort_folders;
70
+    //bool CardReader::sort_reverse;
71
+  #endif
72
+
73
+  #if ENABLED(SDSORT_DYNAMIC_RAM)
74
+    uint8_t *CardReader::sort_order;
75
+  #else
76
+    uint8_t CardReader::sort_order[SDSORT_LIMIT];
77
+  #endif
78
+
79
+  #if ENABLED(SDSORT_USES_RAM)
80
+
81
+    #if ENABLED(SDSORT_CACHE_NAMES)
82
+      #if ENABLED(SDSORT_DYNAMIC_RAM)
83
+        char **CardReader::sortshort, **CardReader::sortnames;
84
+      #else
85
+        char CardReader::sortshort[SDSORT_LIMIT][FILENAME_LENGTH + 1];
86
+        char CardReader::sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN + 1];
87
+      #endif
88
+    #elif DISABLED(SDSORT_USES_STACK)
89
+      char CardReader::sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN + 1];
90
+    #endif
91
+
92
+    #if HAS_FOLDER_SORTING
93
+      #if ENABLED(SDSORT_DYNAMIC_RAM)
94
+        uint8_t *CardReader::isDir;
95
+      #elif ENABLED(SDSORT_CACHE_NAMES) || DISABLED(SDSORT_USES_STACK)
96
+        uint8_t CardReader::isDir[(SDSORT_LIMIT+7)>>3];
97
+      #endif
98
+    #endif
99
+
100
+  #endif // SDSORT_USES_RAM
101
+
102
+#endif // SDCARD_SORT_ALPHA
103
+
104
+Sd2Card CardReader::sd2card;
105
+SdVolume CardReader::volume;
106
+SdFile CardReader::file;
107
+
108
+uint8_t CardReader::file_subcall_ctr;
109
+uint32_t CardReader::filespos[SD_PROCEDURE_DEPTH];
110
+char CardReader::proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH + 1];
111
+
112
+uint32_t CardReader::filesize, CardReader::sdpos;
113
+
114
+LsAction CardReader::lsAction; //stored for recursion.
115
+uint16_t CardReader::nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
116
+char *CardReader::diveDirName;
117
+
118
+#if ENABLED(AUTO_REPORT_SD_STATUS)
119
+  uint8_t CardReader::auto_report_sd_interval;
120
+  millis_t CardReader::next_sd_report_ms;
121
+  #if NUM_SERIAL > 1
122
+    int8_t CardReader::serialport;
123
+  #endif
124
+#endif
49 125
 
50 126
 CardReader::CardReader() {
51 127
   #if ENABLED(SDCARD_SORT_ALPHA)
@@ -56,9 +132,8 @@ CardReader::CardReader() {
56 132
       //sort_reverse = false;
57 133
     #endif
58 134
   #endif
59
-  sdprinting = cardOK = saving = logging = false;
60
-  filesize = 0;
61
-  sdpos = 0;
135
+  flag.sdprinting = flag.cardOK = flag.saving = flag.logging = false;
136
+  filesize = sdpos = 0;
62 137
   file_subcall_ctr = 0;
63 138
 
64 139
   workDirDepth = 0;
@@ -73,7 +148,7 @@ CardReader::CardReader() {
73 148
   #endif
74 149
 }
75 150
 
76
-char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
151
+char *createFilename(char *buffer, const dir_t &p) {
77 152
   char *pos = buffer;
78 153
   for (uint8_t i = 0; i < 11; i++) {
79 154
     if (p.name[i] == ' ') continue;
@@ -108,7 +183,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
108 183
     if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) {
109 184
 
110 185
       // Get the short name for the item, which we know is a folder
111
-      char dosFilename[FILENAME_LENGTH];
186
+      char dosFilename[FILENAME_LENGTH + 1];
112 187
       createFilename(dosFilename, p);
113 188
 
114 189
       // Allocate enough stack space for the full path to a folder, trailing slash, and nul
@@ -120,8 +195,8 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
120 195
       // It contains the full path to the "parent" argument.
121 196
       // We now have the full path to the item in this folder.
122 197
       strcpy(path, prepend_is_empty ? "/" : prepend); // root slash if prepend is empty
123
-      strcat(path, dosFilename); // FILENAME_LENGTH-1 characters maximum
124
-      strcat(path, "/");       // 1 character
198
+      strcat(path, dosFilename);                      // FILENAME_LENGTH characters maximum
199
+      strcat(path, "/");                              // 1 character
125 200
 
126 201
       // Serial.print(path);
127 202
 
@@ -150,9 +225,9 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
150 225
 
151 226
       if (!DIR_IS_FILE_OR_SUBDIR(&p) || (p.attributes & DIR_ATT_HIDDEN)) continue;
152 227
 
153
-      filenameIsDir = DIR_IS_SUBDIR(&p);
228
+      flag.filenameIsDir = DIR_IS_SUBDIR(&p);
154 229
 
155
-      if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
230
+      if (!flag.filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
156 231
 
157 232
       switch (lsAction) {  // 1 based file count
158 233
         case LS_Count:
@@ -242,7 +317,7 @@ void CardReader::ls(
242 317
       SERIAL_PROTOCOL_P(port, longFilename[0] ? longFilename : "???");
243 318
 
244 319
       // If the filename was printed then that's it
245
-      if (!filenameIsDir) break;
320
+      if (!flag.filenameIsDir) break;
246 321
 
247 322
       // SERIAL_ECHOPGM_P(port, "Opening dir: "); SERIAL_ECHOLN_P(port, segment);
248 323
 
@@ -275,7 +350,7 @@ void CardReader::printFilename(
275 350
   #endif
276 351
 ) {
277 352
   if (file.isOpen()) {
278
-    char dosFilename[FILENAME_LENGTH];
353
+    char dosFilename[FILENAME_LENGTH + 1];
279 354
     file.getFilename(dosFilename);
280 355
     SERIAL_ECHO_P(port, dosFilename);
281 356
     #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
@@ -293,7 +368,7 @@ void CardReader::printFilename(
293 368
 }
294 369
 
295 370
 void CardReader::initsd() {
296
-  cardOK = false;
371
+  flag.cardOK = false;
297 372
   if (root.isOpen()) root.close();
298 373
 
299 374
   #ifndef SPI_SPEED
@@ -318,7 +393,7 @@ void CardReader::initsd() {
318 393
     SERIAL_ERRORLNPGM(MSG_SD_OPENROOT_FAIL);
319 394
   }
320 395
   else {
321
-    cardOK = true;
396
+    flag.cardOK = true;
322 397
     SERIAL_ECHO_START();
323 398
     SERIAL_ECHOLNPGM(MSG_SD_CARD_OK);
324 399
   }
@@ -327,7 +402,7 @@ void CardReader::initsd() {
327 402
 
328 403
 void CardReader::release() {
329 404
   stopSDPrint();
330
-  cardOK = false;
405
+  flag.cardOK = false;
331 406
 }
332 407
 
333 408
 void CardReader::openAndPrintFile(const char *name) {
@@ -339,8 +414,8 @@ void CardReader::openAndPrintFile(const char *name) {
339 414
 }
340 415
 
341 416
 void CardReader::startFileprint() {
342
-  if (cardOK) {
343
-    sdprinting = true;
417
+  if (flag.cardOK) {
418
+    flag.sdprinting = true;
344 419
     #if SD_RESORT
345 420
       flush_presort();
346 421
     #endif
@@ -355,7 +430,7 @@ void CardReader::stopSDPrint(
355 430
   #if ENABLED(ADVANCED_PAUSE_FEATURE)
356 431
     did_pause_print = 0;
357 432
   #endif
358
-  sdprinting = abort_sd_printing = false;
433
+  flag.sdprinting = flag.abort_sd_printing = false;
359 434
   if (isFileOpen()) file.close();
360 435
   #if SD_RESORT
361 436
     if (re_sort) presort();
@@ -363,7 +438,7 @@ void CardReader::stopSDPrint(
363 438
 }
364 439
 
365 440
 void CardReader::openLogFile(char * const path) {
366
-  logging = true;
441
+  flag.logging = true;
367 442
   openFile(path, false);
368 443
 }
369 444
 
@@ -380,7 +455,7 @@ void CardReader::getAbsFilename(char *t) {
380 455
   for (uint8_t i = 0; i < workDirDepth; i++)                // Loop to current work dir
381 456
     appendAtom(workDirParents[i], t, cnt);
382 457
 
383
-  if (cnt < MAXPATHNAMELENGTH - (FILENAME_LENGTH)) {
458
+  if (cnt < MAXPATHNAMELENGTH - (FILENAME_LENGTH) - 1) {    // Leave room for filename and nul
384 459
     appendAtom(file, t, cnt);
385 460
     --t;
386 461
   }
@@ -389,7 +464,7 @@ void CardReader::getAbsFilename(char *t) {
389 464
 
390 465
 void CardReader::openFile(char * const path, const bool read, const bool subcall/*=false*/) {
391 466
 
392
-  if (!cardOK) return;
467
+  if (!flag.cardOK) return;
393 468
 
394 469
   uint8_t doing = 0;
395 470
   if (isFileOpen()) {                     // Replacing current file or doing a subroutine
@@ -464,7 +539,7 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall
464 539
       SERIAL_EOL();
465 540
     }
466 541
     else {
467
-      saving = true;
542
+      flag.saving = true;
468 543
       getfilename(0, fname);
469 544
       #if ENABLED(EMERGENCY_PARSER)
470 545
         emergency_parser.disable();
@@ -476,7 +551,7 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall
476 551
 }
477 552
 
478 553
 void CardReader::removeFile(const char * const name) {
479
-  if (!cardOK) return;
554
+  if (!flag.cardOK) return;
480 555
 
481 556
   //stopSDPrint();
482 557
 
@@ -504,7 +579,7 @@ void CardReader::getStatus(
504 579
     const int8_t port/*= -1*/
505 580
   #endif
506 581
 ) {
507
-  if (cardOK && sdprinting) {
582
+  if (flag.cardOK && flag.sdprinting) {
508 583
     SERIAL_PROTOCOLPGM_P(port, MSG_SD_PRINTING_BYTE);
509 584
     SERIAL_PROTOCOL_P(port, sdpos);
510 585
     SERIAL_PROTOCOLCHAR_P(port, '/');
@@ -543,11 +618,11 @@ void CardReader::write_command(char *buf) {
543 618
 
544 619
 void CardReader::checkautostart() {
545 620
 
546
-  if (autostart_index < 0 || sdprinting) return;
621
+  if (autostart_index < 0 || flag.sdprinting) return;
547 622
 
548
-  if (!cardOK) initsd();
623
+  if (!flag.cardOK) initsd();
549 624
 
550
-  if (cardOK
625
+  if (flag.cardOK
551 626
     #if ENABLED(POWER_LOSS_RECOVERY)
552 627
       && !recovery.valid() // Don't run auto#.g when a resume file exists
553 628
     #endif
@@ -576,7 +651,7 @@ void CardReader::beginautostart() {
576 651
 void CardReader::closefile(const bool store_location) {
577 652
   file.sync();
578 653
   file.close();
579
-  saving = logging = false;
654
+  flag.saving = flag.logging = false;
580 655
   sdpos = 0;
581 656
   #if ENABLED(EMERGENCY_PARSER)
582 657
     emergency_parser.enable();
@@ -603,7 +678,7 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
603 678
     if (nr < sort_count) {
604 679
       strcpy(filename, sortshort[nr]);
605 680
       strcpy(longFilename, sortnames[nr]);
606
-      filenameIsDir = TEST(isDir[nr>>3], nr & 0x07);
681
+      flag.filenameIsDir = TEST(isDir[nr>>3], nr & 0x07);
607 682
       return;
608 683
     }
609 684
   #endif // SDSORT_CACHE_NAMES
@@ -712,6 +787,33 @@ void CardReader::setroot() {
712 787
     );
713 788
   }
714 789
 
790
+  #if ENABLED(SDSORT_USES_RAM)
791
+    #if ENABLED(SDSORT_DYNAMIC_RAM)
792
+      // Use dynamic method to copy long filename
793
+      #define SET_SORTNAME(I) (sortnames[I] = strdup(longest_filename()))
794
+      #if ENABLED(SDSORT_CACHE_NAMES)
795
+        // When caching also store the short name, since
796
+        // we're replacing the getfilename() behavior.
797
+        #define SET_SORTSHORT(I) (sortshort[I] = strdup(filename))
798
+      #else
799
+        #define SET_SORTSHORT(I) NOOP
800
+      #endif
801
+    #else
802
+      // Copy filenames into the static array
803
+      #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
804
+        #define SET_SORTNAME(I) do{ strncpy(sortnames[I], longest_filename(), SORTED_LONGNAME_MAXLEN); \
805
+                                    sortnames[I][SORTED_LONGNAME_MAXLEN] = '\0'; }while(0)
806
+      #else
807
+        #define SET_SORTNAME(I) strncpy(sortnames[I], longest_filename(), SORTED_LONGNAME_MAXLEN)
808
+      #endif
809
+      #if ENABLED(SDSORT_CACHE_NAMES)
810
+        #define SET_SORTSHORT(I) strcpy(sortshort[I], filename)
811
+      #else
812
+        #define SET_SORTSHORT(I) NOOP
813
+      #endif
814
+    #endif
815
+  #endif
816
+
715 817
   /**
716 818
    * Read all the files and produce a sort key
717 819
    *
@@ -754,7 +856,7 @@ void CardReader::setroot() {
754 856
             sortnames = new char*[fileCnt];
755 857
           #endif
756 858
         #elif ENABLED(SDSORT_USES_STACK)
757
-          char sortnames[fileCnt][SORTED_LONGNAME_MAXLEN];
859
+          char sortnames[fileCnt][SORTED_LONGNAME_MAXLEN + 1];
758 860
         #endif
759 861
 
760 862
         // Folder sorting needs 1 bit per entry for flags.
@@ -783,33 +885,15 @@ void CardReader::setroot() {
783 885
           // If using RAM then read all filenames now.
784 886
           #if ENABLED(SDSORT_USES_RAM)
785 887
             getfilename(i);
786
-            #if ENABLED(SDSORT_DYNAMIC_RAM)
787
-              // Use dynamic method to copy long filename
788
-              sortnames[i] = strdup(longest_filename());
789
-              #if ENABLED(SDSORT_CACHE_NAMES)
790
-                // When caching also store the short name, since
791
-                // we're replacing the getfilename() behavior.
792
-                sortshort[i] = strdup(filename);
793
-              #endif
794
-            #else
795
-              // Copy filenames into the static array
796
-              #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
797
-                strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
798
-                sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
799
-              #else
800
-                strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
801
-              #endif
802
-              #if ENABLED(SDSORT_CACHE_NAMES)
803
-                strcpy(sortshort[i], filename);
804
-              #endif
805
-            #endif
888
+            SET_SORTNAME(i);
889
+            SET_SORTSHORT(i);
806 890
             // char out[30];
807
-            // sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]);
891
+            // sprintf_P(out, PSTR("---- %i %s %s"), i, flag.filenameIsDir ? "D" : " ", sortnames[i]);
808 892
             // SERIAL_ECHOLN(out);
809 893
             #if HAS_FOLDER_SORTING
810 894
               const uint16_t bit = i & 0x07, ind = i >> 3;
811 895
               if (bit == 0) isDir[ind] = 0x00;
812
-              if (filenameIsDir) isDir[ind] |= _BV(bit);
896
+              if (flag.filenameIsDir) isDir[ind] |= _BV(bit);
813 897
             #endif
814 898
           #endif
815 899
         }
@@ -837,7 +921,7 @@ void CardReader::setroot() {
837 921
                     ? _SORT_CMP_NODIR() \
838 922
                     : (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0)
839 923
               #else
840
-                #define _SORT_CMP_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1))
924
+                #define _SORT_CMP_DIR(fs) ((dir1 == flag.filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1))
841 925
               #endif
842 926
             #endif
843 927
 
@@ -847,7 +931,7 @@ void CardReader::setroot() {
847 931
               getfilename(o1);
848 932
               strcpy(name1, longest_filename()); // save (or getfilename below will trounce it)
849 933
               #if HAS_FOLDER_SORTING
850
-                bool dir1 = filenameIsDir;
934
+                bool dir1 = flag.filenameIsDir;
851 935
               #endif
852 936
               getfilename(o2);
853 937
               char *name2 = longest_filename(); // use the string in-place
@@ -885,27 +969,17 @@ void CardReader::setroot() {
885 969
       else {
886 970
         sort_order[0] = 0;
887 971
         #if ENABLED(SDSORT_USES_RAM) && ENABLED(SDSORT_CACHE_NAMES)
888
-          getfilename(0);
889 972
           #if ENABLED(SDSORT_DYNAMIC_RAM)
890 973
             sortnames = new char*[1];
891
-            sortnames[0] = strdup(longest_filename()); // malloc
892 974
             #if ENABLED(SDSORT_CACHE_NAMES)
893 975
               sortshort = new char*[1];
894
-              sortshort[0] = strdup(filename);       // malloc
895 976
             #endif
896 977
             isDir = new uint8_t[1];
897
-          #else
898
-            #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
899
-              strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
900
-              sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
901
-            #else
902
-              strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
903
-            #endif
904
-            #if ENABLED(SDSORT_CACHE_NAMES)
905
-              strcpy(sortshort[0], filename);
906
-            #endif
907 978
           #endif
908
-          isDir[0] = filenameIsDir ? 0x01 : 0x00;
979
+          getfilename(0);
980
+          SET_SORTNAME(0);
981
+          SET_SORTSHORT(0);
982
+          isDir[0] = flag.filenameIsDir ? 0x01 : 0x00;
909 983
         #endif
910 984
       }
911 985
 
@@ -1007,7 +1081,7 @@ void CardReader::printingHasFinished() {
1007 1081
   }
1008 1082
 
1009 1083
   void CardReader::openJobRecoveryFile(const bool read) {
1010
-    if (!cardOK) return;
1084
+    if (!flag.cardOK) return;
1011 1085
     if (recovery.file.isOpen()) return;
1012 1086
     if (!recovery.file.open(&root, job_recovery_file_name, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) {
1013 1087
       SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, job_recovery_file_name);

+ 102
- 85
Marlin/src/sd/cardreader.h ファイルの表示

@@ -27,106 +27,121 @@
27 27
 
28 28
 #define SD_RESORT ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_DYNAMIC_RAM)
29 29
 
30
-#define MAX_DIR_DEPTH 10          // Maximum folder depth
30
+#define MAX_DIR_DEPTH     10       // Maximum folder depth
31
+#define MAXDIRNAMELENGTH   8       // DOS folder name size
32
+#define MAXPATHNAMELENGTH  (1 + (MAXDIRNAMELENGTH + 1) * (MAX_DIR_DEPTH) + 1 + FILENAME_LENGTH) // "/" + N * ("ADIRNAME/") + "filename.ext"
31 33
 
32 34
 #include "SdFile.h"
33 35
 
34 36
 enum LsAction : uint8_t { LS_SerialPrint, LS_Count, LS_GetFilename };
35 37
 
38
+typedef struct {
39
+  bool saving:1,
40
+       logging:1,
41
+       sdprinting:1,
42
+       cardOK:1,
43
+       filenameIsDir:1,
44
+       abort_sd_printing:1
45
+       #if ENABLED(FAST_FILE_TRANSFER)
46
+         , binary_mode:1
47
+       #endif
48
+    ;
49
+} card_flags_t;
50
+
36 51
 class CardReader {
37 52
 public:
38 53
   CardReader();
39 54
 
40
-  void initsd();
41
-  void write_command(char *buf);
55
+  static void initsd();
56
+  static void write_command(char *buf);
42 57
 
43
-  void beginautostart();
44
-  void checkautostart();
58
+  static void beginautostart();
59
+  static void checkautostart();
45 60
 
46
-  void openFile(char * const path, const bool read, const bool subcall=false);
47
-  void openLogFile(char * const path);
48
-  void removeFile(const char * const name);
49
-  void closefile(const bool store_location=false);
50
-  void release();
51
-  void openAndPrintFile(const char *name);
52
-  void startFileprint();
53
-  void stopSDPrint(
61
+  static void openFile(char * const path, const bool read, const bool subcall=false);
62
+  static void openLogFile(char * const path);
63
+  static void removeFile(const char * const name);
64
+  static void closefile(const bool store_location=false);
65
+  static void release();
66
+  static void openAndPrintFile(const char *name);
67
+  static void startFileprint();
68
+  static void stopSDPrint(
54 69
     #if SD_RESORT
55 70
       const bool re_sort=false
56 71
     #endif
57 72
   );
58
-  void getStatus(
73
+  static void getStatus(
59 74
     #if NUM_SERIAL > 1
60 75
       const int8_t port = -1
61 76
     #endif
62 77
   );
63
-  void printingHasFinished();
64
-  void printFilename(
78
+  static void printingHasFinished();
79
+  static void printFilename(
65 80
     #if NUM_SERIAL > 1
66 81
       const int8_t port = -1
67 82
     #endif
68 83
   );
69 84
 
70 85
   #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
71
-    void printLongPath(char *path
86
+    static void printLongPath(char *path
72 87
       #if NUM_SERIAL > 1
73 88
         , const int8_t port = -1
74 89
       #endif
75 90
     );
76 91
   #endif
77 92
 
78
-  void getfilename(uint16_t nr, const char* const match=NULL);
79
-  uint16_t getnrfilenames();
93
+  static void getfilename(uint16_t nr, const char* const match=NULL);
94
+  static uint16_t getnrfilenames();
80 95
 
81
-  void getAbsFilename(char *t);
96
+  static void getAbsFilename(char *t);
82 97
 
83
-  void ls(
98
+  static void ls(
84 99
     #if NUM_SERIAL > 1
85 100
       const int8_t port = -1
86 101
     #endif
87 102
   );
88
-  void chdir(const char *relpath);
89
-  int8_t updir();
90
-  void setroot();
103
+  static void chdir(const char *relpath);
104
+  static int8_t updir();
105
+  static void setroot();
91 106
 
92
-  const char* diveToFile(SdFile*& curDir, const char * const path, const bool echo);
107
+  static const char* diveToFile(SdFile*& curDir, const char * const path, const bool echo);
93 108
 
94
-  uint16_t get_num_Files();
109
+  static uint16_t get_num_Files();
95 110
 
96 111
   #if ENABLED(SDCARD_SORT_ALPHA)
97
-    void presort();
98
-    void getfilename_sorted(const uint16_t nr);
112
+    static void presort();
113
+    static void getfilename_sorted(const uint16_t nr);
99 114
     #if ENABLED(SDSORT_GCODE)
100
-      FORCE_INLINE void setSortOn(bool b) { sort_alpha = b; presort(); }
101
-      FORCE_INLINE void setSortFolders(int i) { sort_folders = i; presort(); }
102
-      //FORCE_INLINE void setSortReverse(bool b) { sort_reverse = b; }
115
+      FORCE_INLINE static void setSortOn(bool b) { sort_alpha = b; presort(); }
116
+      FORCE_INLINE static void setSortFolders(int i) { sort_folders = i; presort(); }
117
+      //FORCE_INLINE static void setSortReverse(bool b) { sort_reverse = b; }
103 118
     #endif
104 119
   #else
105
-    FORCE_INLINE void getfilename_sorted(const uint16_t nr) { getfilename(nr); }
120
+    FORCE_INLINE static void getfilename_sorted(const uint16_t nr) { getfilename(nr); }
106 121
   #endif
107 122
 
108 123
   #if ENABLED(POWER_LOSS_RECOVERY)
109
-    bool jobRecoverFileExists();
110
-    void openJobRecoveryFile(const bool read);
111
-    void removeJobRecoveryFile();
124
+    static bool jobRecoverFileExists();
125
+    static void openJobRecoveryFile(const bool read);
126
+    static void removeJobRecoveryFile();
112 127
   #endif
113 128
 
114
-  inline void pauseSDPrint() { sdprinting = false; }
115
-  inline bool isFileOpen() { return file.isOpen(); }
116
-  inline bool eof() { return sdpos >= filesize; }
117
-  inline int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
118
-  inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }
119
-  inline uint32_t getIndex() { return sdpos; }
120
-  inline uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
121
-  inline char* getWorkDirName() { workDir.getFilename(filename); return filename; }
122
-  inline int16_t read(void* buf, uint16_t nbyte) { return file.isOpen() ? file.read(buf, nbyte) : -1; }
123
-  inline int16_t write(void* buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; }
129
+  static inline void pauseSDPrint() { flag.sdprinting = false; }
130
+  static inline bool isFileOpen() { return file.isOpen(); }
131
+  static inline bool eof() { return sdpos >= filesize; }
132
+  static inline int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
133
+  static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }
134
+  static inline uint32_t getIndex() { return sdpos; }
135
+  static inline uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
136
+  static inline char* getWorkDirName() { workDir.getFilename(filename); return filename; }
137
+  static inline int16_t read(void* buf, uint16_t nbyte) { return file.isOpen() ? file.read(buf, nbyte) : -1; }
138
+  static inline int16_t write(void* buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; }
124 139
 
125
-  Sd2Card& getSd2Card() { return sd2card; }
140
+  static Sd2Card& getSd2Card() { return sd2card; }
126 141
 
127 142
   #if ENABLED(AUTO_REPORT_SD_STATUS)
128
-    void auto_report_sd_status(void);
129
-    inline void set_auto_report_interval(uint8_t v
143
+    static void auto_report_sd_status(void);
144
+    static inline void set_auto_report_interval(uint8_t v
130 145
       #if NUM_SERIAL > 1
131 146
         , int8_t port
132 147
       #endif
@@ -140,40 +155,39 @@ public:
140 155
     }
141 156
   #endif
142 157
 
143
-  inline char* longest_filename() { return longFilename[0] ? longFilename : filename; }
158
+  static inline char* longest_filename() { return longFilename[0] ? longFilename : filename; }
144 159
 
145 160
 public:
146
-  bool saving, logging, sdprinting, cardOK, filenameIsDir, abort_sd_printing;
147
-  char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];
148
-  int8_t autostart_index;
161
+  static card_flags_t flag;
162
+  static char filename[FILENAME_LENGTH + 1], longFilename[LONG_FILENAME_LENGTH + 1];
163
+  static int8_t autostart_index;
149 164
 
150 165
   #if ENABLED(FAST_FILE_TRANSFER)
151
-    bool binary_mode;
152 166
     #if NUM_SERIAL > 1
153
-      uint8_t transfer_port;
167
+      static uint8_t transfer_port;
154 168
     #else
155 169
       static constexpr uint8_t transfer_port = 0;
156 170
     #endif
157 171
   #endif
158 172
 
159 173
 private:
160
-  SdFile root, workDir, workDirParents[MAX_DIR_DEPTH];
161
-  uint8_t workDirDepth;
174
+  static SdFile root, workDir, workDirParents[MAX_DIR_DEPTH];
175
+  static uint8_t workDirDepth;
162 176
 
163 177
   // Sort files and folders alphabetically.
164 178
   #if ENABLED(SDCARD_SORT_ALPHA)
165
-    uint16_t sort_count;        // Count of sorted items in the current directory
179
+    static uint16_t sort_count;   // Count of sorted items in the current directory
166 180
     #if ENABLED(SDSORT_GCODE)
167
-      bool sort_alpha;          // Flag to enable / disable the feature
168
-      int sort_folders;         // Flag to enable / disable folder sorting
169
-      //bool sort_reverse;      // Flag to enable / disable reverse sorting
181
+      static bool sort_alpha;     // Flag to enable / disable the feature
182
+      static int sort_folders;    // Folder sorting before/none/after
183
+      //static bool sort_reverse; // Flag to enable / disable reverse sorting
170 184
     #endif
171 185
 
172 186
     // By default the sort index is static
173 187
     #if ENABLED(SDSORT_DYNAMIC_RAM)
174
-      uint8_t *sort_order;
188
+      static uint8_t *sort_order;
175 189
     #else
176
-      uint8_t sort_order[SDSORT_LIMIT];
190
+      static uint8_t sort_order[SDSORT_LIMIT];
177 191
     #endif
178 192
 
179 193
     #if ENABLED(SDSORT_USES_RAM) && ENABLED(SDSORT_CACHE_NAMES) && DISABLED(SDSORT_DYNAMIC_RAM)
@@ -188,21 +202,21 @@ private:
188 202
       // If using dynamic ram for names, allocate on the heap.
189 203
       #if ENABLED(SDSORT_CACHE_NAMES)
190 204
         #if ENABLED(SDSORT_DYNAMIC_RAM)
191
-          char **sortshort, **sortnames;
205
+          static char **sortshort, **sortnames;
192 206
         #else
193
-          char sortshort[SDSORT_LIMIT][FILENAME_LENGTH];
194
-          char sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN];
207
+          static char sortshort[SDSORT_LIMIT][FILENAME_LENGTH + 1];
208
+          static char sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN + 1];
195 209
         #endif
196 210
       #elif DISABLED(SDSORT_USES_STACK)
197
-        char sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN];
211
+        static char sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN + 1];
198 212
       #endif
199 213
 
200 214
       // Folder sorting uses an isDir array when caching items.
201 215
       #if HAS_FOLDER_SORTING
202 216
         #if ENABLED(SDSORT_DYNAMIC_RAM)
203
-          uint8_t *isDir;
217
+          static uint8_t *isDir;
204 218
         #elif ENABLED(SDSORT_CACHE_NAMES) || DISABLED(SDSORT_USES_STACK)
205
-          uint8_t isDir[(SDSORT_LIMIT+7)>>3];
219
+          static uint8_t isDir[(SDSORT_LIMIT+7)>>3];
206 220
         #endif
207 221
       #endif
208 222
 
@@ -210,28 +224,31 @@ private:
210 224
 
211 225
   #endif // SDCARD_SORT_ALPHA
212 226
 
213
-  Sd2Card sd2card;
214
-  SdVolume volume;
215
-  SdFile file;
216
-
217
-  #define SD_PROCEDURE_DEPTH 1
218
-  #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
219
-  uint8_t file_subcall_ctr;
220
-  uint32_t filespos[SD_PROCEDURE_DEPTH];
221
-  char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
222
-  uint32_t filesize, sdpos;
223
-
224
-  LsAction lsAction; //stored for recursion.
225
-  uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
226
-  char* diveDirName;
227
-  void lsDive(const char *prepend, SdFile parent, const char * const match=NULL
227
+  static Sd2Card sd2card;
228
+  static SdVolume volume;
229
+  static SdFile file;
230
+
231
+  #ifndef SD_PROCEDURE_DEPTH
232
+    #define SD_PROCEDURE_DEPTH 1
233
+  #endif
234
+
235
+  static uint8_t file_subcall_ctr;
236
+  static uint32_t filespos[SD_PROCEDURE_DEPTH];
237
+  static char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH + 1];
238
+
239
+  static uint32_t filesize, sdpos;
240
+
241
+  static LsAction lsAction; //stored for recursion.
242
+  static uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
243
+  static char *diveDirName;
244
+  static void lsDive(const char *prepend, SdFile parent, const char * const match=NULL
228 245
     #if NUM_SERIAL > 1
229 246
       , const int8_t port = -1
230 247
     #endif
231 248
   );
232 249
 
233 250
   #if ENABLED(SDCARD_SORT_ALPHA)
234
-    void flush_presort();
251
+    static void flush_presort();
235 252
   #endif
236 253
 
237 254
   #if ENABLED(AUTO_REPORT_SD_STATUS)
@@ -256,7 +273,7 @@ private:
256 273
   #define IS_SD_INSERTED() true
257 274
 #endif
258 275
 
259
-#define IS_SD_PRINTING()  card.sdprinting
276
+#define IS_SD_PRINTING()  card.flag.sdprinting
260 277
 #define IS_SD_FILE_OPEN() card.isFileOpen()
261 278
 
262 279
 extern CardReader card;

読み込み中…
キャンセル
保存