Prusa MINI Firmware overview
|
Go to the documentation of this file.
24 #include "../inc/MarlinConfig.h"
26 #if ENABLED(SDSUPPORT)
28 #define SD_RESORT BOTH(SDCARD_SORT_ALPHA, SDSORT_DYNAMIC_RAM)
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"
44 #if ENABLED(BINARY_FILE_TRANSFER)
52 static card_flags_t flag;
57 #if ENABLED(BINARY_FILE_TRANSFER)
59 static int8_t transfer_port_index;
61 static constexpr int8_t transfer_port_index = 0;
69 static SdFile getroot() {
return root; }
72 static void release();
73 static inline bool isMounted() {
return flag.mounted; }
77 static void openLogFile(
char *
const path);
78 static void write_command(
char *
const buf);
81 static int8_t autostart_index;
82 static void beginautostart();
83 static void checkautostart();
86 static void openFile(
char *
const path,
const bool read,
const bool subcall=
false);
87 static void closefile(
const bool store_location=
false);
88 static void removeFile(
const char *
const name);
90 static inline char* longest_filename() {
return longFilename[0] ? longFilename : filename; }
91 #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
92 static void printLongPath(
char *
const path);
97 static void cd(
const char *relpath);
99 static uint16_t countFilesInWorkDir();
100 static uint16_t get_num_Files();
103 static void selectFileByIndex(
const uint16_t nr);
104 static void selectFileByName(
const char*
const match);
107 static void openAndPrintFile(
const char *name);
108 static void printingHasFinished();
109 static void getAbsFilename(
char *dst);
110 static void startFileprint();
111 static void printFilename();
112 static void stopSDPrint(
114 const bool re_sort=
false
117 static void report_status();
118 static inline void pauseSDPrint() { flag.sdprinting =
false; }
119 static inline bool isPaused() {
return isFileOpen() && !flag.sdprinting; }
120 static inline bool isPrinting() {
return flag.sdprinting; }
121 #if HAS_PRINT_PROGRESS_PERMYRIAD
122 static inline uint16_t permyriadDone() {
return (isFileOpen() && filesize) ? sdpos / ((filesize + 9999) / 10000) : 0; }
124 static inline uint8_t percentDone() {
return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
127 static const char* diveToFile(
SdFile*& curDir,
const char *
const path,
const bool echo=
false);
129 #if ENABLED(SDCARD_SORT_ALPHA)
130 static void presort();
131 static void getfilename_sorted(
const uint16_t nr);
132 #if ENABLED(SDSORT_GCODE)
133 FORCE_INLINE static void setSortOn(
bool b) { sort_alpha =
b; presort(); }
134 FORCE_INLINE static void setSortFolders(
int i) { sort_folders =
i; presort(); }
138 FORCE_INLINE static void getfilename_sorted(
const uint16_t nr) { selectFileByIndex(nr); }
141 #if ENABLED(POWER_LOSS_RECOVERY)
142 static bool jobRecoverFileExists();
143 static void openJobRecoveryFile(
const bool read);
144 static void removeJobRecoveryFile();
147 static inline bool isFileOpen() {
return isMounted() && file.isOpen(); }
148 static inline uint32_t getIndex() {
return sdpos; }
149 static inline bool eof() {
return sdpos >= filesize; }
150 static inline void setIndex(
const uint32_t index) { sdpos = index; file.seekSet(index); }
151 static inline char* getWorkDirName() { workDir.getDosName(filename);
return filename; }
152 static inline int16_t get() { sdpos = file.curPosition();
return (int16_t)file.read(); }
153 static inline int16_t
read(
void* buf, uint16_t nbyte) {
return file.isOpen() ? file.read(buf, nbyte) : -1; }
154 static inline int16_t
write(
void* buf, uint16_t nbyte) {
return file.isOpen() ? file.write(buf, nbyte) : -1; }
156 static Sd2Card& getSd2Card() {
return sd2card; }
158 #if ENABLED(AUTO_REPORT_SD_STATUS)
159 static void auto_report_sd_status();
160 static inline void set_auto_report_interval(
uint8_t v) {
162 auto_report_port = serial_port_index;
165 auto_report_sd_interval = v;
166 next_sd_report_ms =
millis() + 1000UL * v;
180 #if ENABLED(SDCARD_SORT_ALPHA)
181 static uint16_t sort_count;
182 #if ENABLED(SDSORT_GCODE)
183 static bool sort_alpha;
184 static int sort_folders;
189 #if ENABLED(SDSORT_DYNAMIC_RAM)
195 #if BOTH(SDSORT_USES_RAM, SDSORT_CACHE_NAMES) && DISABLED(SDSORT_DYNAMIC_RAM)
196 #define SORTED_LONGNAME_MAXLEN (SDSORT_CACHE_VFATS) * (FILENAME_LENGTH)
197 #define SORTED_LONGNAME_STORAGE (SORTED_LONGNAME_MAXLEN + 1)
199 #define SORTED_LONGNAME_MAXLEN LONG_FILENAME_LENGTH
200 #define SORTED_LONGNAME_STORAGE SORTED_LONGNAME_MAXLEN
204 #if ENABLED(SDSORT_USES_RAM)
207 #if ENABLED(SDSORT_CACHE_NAMES)
208 static uint16_t nrFiles;
209 #if ENABLED(SDSORT_DYNAMIC_RAM)
210 static char **sortshort, **sortnames;
216 #if (ENABLED(SDSORT_CACHE_NAMES) && DISABLED(SDSORT_DYNAMIC_RAM)) || NONE(SDSORT_CACHE_NAMES, SDSORT_USES_STACK)
217 static char sortnames[
SDSORT_LIMIT][SORTED_LONGNAME_STORAGE];
221 #if HAS_FOLDER_SORTING
222 #if ENABLED(SDSORT_DYNAMIC_RAM)
224 #elif ENABLED(SDSORT_CACHE_NAMES) || DISABLED(SDSORT_USES_STACK)
229 #endif // SDSORT_USES_RAM
231 #endif // SDCARD_SORT_ALPHA
237 static uint32_t filesize, sdpos;
242 #ifndef SD_PROCEDURE_DEPTH
243 #define SD_PROCEDURE_DEPTH 1
245 static uint8_t file_subcall_ctr;
246 static uint32_t filespos[SD_PROCEDURE_DEPTH];
252 #if ENABLED(AUTO_REPORT_SD_STATUS)
253 static uint8_t auto_report_sd_interval;
256 static int8_t auto_report_port;
263 static bool is_dir_or_gcode(
const dir_t &p);
264 static int countItems(
SdFile dir);
266 static void selectByName(
SdFile dir,
const char *
const match);
267 static void printListing(
SdFile parent,
const char *
const prepend=
nullptr);
269 #if ENABLED(SDCARD_SORT_ALPHA)
270 static void flush_presort();
274 #if ENABLED(USB_FLASH_DRIVE_SUPPORT)
275 #define IS_SD_INSERTED() Sd2Card::isInserted()
276 #elif PIN_EXISTS(SD_DETECT)
277 #if ENABLED(SD_DETECT_INVERTED)
278 #define IS_SD_INSERTED() READ(SD_DETECT_PIN)
280 #define IS_SD_INSERTED() !READ(SD_DETECT_PIN)
284 #define IS_SD_INSERTED() true
287 #define IS_SD_PRINTING() card.flag.sdprinting
288 #define IS_SD_PAUSED() card.isPaused()
289 #define IS_SD_FILE_OPEN() card.isFileOpen()
291 extern CardReader card;
295 #define IS_SD_PRINTING() false
296 #define IS_SD_PAUSED() false
297 #define IS_SD_FILE_OPEN() false
299 #define LONG_FILENAME_LENGTH 0
int8_t readDir(dir_t *dir, char *longFilename)
Definition: Marlin_CardReader.cpp:459
#define SERIAL_CHAR(x)
Definition: serial.h:69
const uint8_t O_APPEND
Definition: SdBaseFile.h:59
#define PORT_REDIRECT(p)
Definition: serial.h:66
static void synchronize()
Definition: planner.cpp:1556
const uint8_t DIR_ATT_HIDDEN
Definition: SdFatStructs.h:564
#define SERIAL_ECHO(x)
Definition: serial.h:70
#define OUT_WRITE(IO, V)
Definition: fastio.h:108
static void enqueue_now_P(PGM_P const cmd)
Definition: queue.cpp:218
Access FAT16 and FAT32 volumes on SD and SDHC cards.
Definition: SdVolume.h:71
GCodeQueue queue
Definition: queue.cpp:28
MarlinSettings settings
Definition: configuration_store.cpp:344
static FORCE_INLINE void first_load()
Definition: configuration_store.h:81
#define MSG_SD_OPENROOT_FAIL
Definition: language.h:226
static SdFile newDir2
Definition: Marlin_CardReader.cpp:27
Stopwatch print_job_timer
Definition: printcounter.cpp:63
#define SDPOWER_PIN
Definition: pins.h:789
#define SERIAL_ECHOPAIR(V...)
Definition: serial.h:114
#define MSG_SD_NOT_PRINTING
Definition: language.h:235
#define LONG_FILENAME_LENGTH
Definition: cardreader.h:299
bool close()
Definition: Marlin_CardReader.cpp:535
const uint8_t DIR_NAME_DELETED
Definition: SdFatStructs.h:561
uint8_t i
Definition: screen_test_graph.c:72
#define STRINGIFY(M)
Definition: macros.h:73
#define SPI_SPEED
Definition: Conditionals_LCD.h:572
void kill(PGM_P const lcd_error, PGM_P const lcd_component, const bool steppers_off)
Definition: Marlin.cpp:718
uint32_t millis(void)
Definition: wiring_time.c:29
#define LCD_SDSS
Definition: pins_AZSMZ_MINI.h:89
static SdFile file
Definition: power_loss_recovery.h:110
#define FILENAME_LENGTH
Definition: SdFatConfig.h:103
const uint8_t O_WRITE
Definition: SdBaseFile.h:55
bool isOpen() const
Definition: SdBaseFile.h:277
PrintJobRecovery recovery
#define SERIAL_ECHO_START()
Definition: serial.h:179
static bool stop()
Stop the stopwatch.
Definition: stopwatch.cpp:36
#define SERIAL_ECHOLN(x)
Definition: serial.h:72
#define sprintf_P(s,...)
Definition: pgmspace.h:72
#define MAX_DIR_DEPTH
Definition: window_file_list.h:35
void rewind()
Definition: SdBaseFile.h:311
static const char filename[5]
Definition: power_loss_recovery.h:108
EmergencyParser emergency_parser
#define NOMORE(v, n)
Definition: macros.h:133
end
Definition: createSpeedLookupTable.py:33
#define MSG_SD_VOL_INIT_FAIL
Definition: language.h:225
#define ZERO(a)
Definition: macros.h:201
static bool valid()
Definition: power_loss_recovery.h:167
#define FORCE_INLINE
Definition: macros.h:40
static void finish_and_disable()
Definition: planner.cpp:1517
#define SERIAL_ECHO_MSG(S)
Definition: serial.h:183
#define PSTR(str)
Definition: pgmspace.h:31
#define MSG_SD_CANT_ENTER_SUBDIR
Definition: language.h:238
static SdFile newDir1
Definition: Marlin_CardReader.cpp:27
static FORCE_INLINE void enable()
Definition: emergency_parser.h:73
static millis_t duration()
Get the running time.
Definition: stopwatch.cpp:108
uint8_t name[11]
Definition: SdFatStructs.h:486
static FORCE_INLINE void disable()
Definition: emergency_parser.h:75
#define SDSORT_LIMIT
Definition: window_file_list.h:27
#define MSG_SD_PRINTING_BYTE
Definition: language.h:234
#define MSG_SD_CANT_OPEN_SUBDIR
Definition: language.h:223
#define SERIAL_ECHOPGM(S)
Definition: serial.h:173
#define MSG_SD_OPEN_FILE_FAIL
Definition: language.h:229
SdBaseFile with Print.
Definition: SdFile.h:45
const uint8_t O_TRUNC
Definition: SdBaseFile.h:61
#define SERIAL_ECHOLNPAIR(V...)
Definition: serial.h:144
#define SDSS
Definition: spi_pins.h:53
uint8_t attributes
Definition: SdFatStructs.h:494
#define FOLDER_SORTING
Definition: window_file_list.h:31
#define ELAPSED(NOW, SOON)
Definition: millis_t.h:29
#define MSG_SD_FILE_SELECTED
Definition: language.h:232
const uint8_t[]
Definition: 404_html.c:3
static void enqueue_one_now(const char *cmd)
Definition: queue.cpp:212
Raw access to SD and SDHC flash memory cards.
Definition: Sd2Card.h:93
#define _BV(bit)
Definition: wiring_constants.h:99
#define SERIAL_ERROR_MSG(S)
Definition: serial.h:184
static uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t *dir)
Definition: SdFatStructs.h:612
static int read(struct _reent *_r, void *pv, char *pc, int n)
Definition: gcode_file.cpp:9
#define MSG_SD_ERR_WRITE_TO_FILE
Definition: language.h:236
#define MAXPATHNAMELENGTH
Definition: screen_filebrowser.cpp:26
static char * createFilename(char *const buffer, const dir_t &p)
Get a DOS 8.3 filename in its useful form.
Definition: Marlin_CardReader.cpp:92
#define HIGH
Definition: wiring_constants.h:71
#define SERIAL_EOL()
Definition: serial.h:181
uint32_t fileSize
Definition: SdFatStructs.h:525
#define MSG_SD_WRITE_TO_FILE
Definition: language.h:233
bool open(SdBaseFile *dirFile, uint16_t index, uint8_t oflag)
FAT short directory entry.
Definition: SdFatStructs.h:479
static uint8_t DIR_IS_SUBDIR(const dir_t *dir)
Definition: SdFatStructs.h:602
void serialprintPGM(PGM_P str)
Definition: serial.cpp:35
#define MSG_SD_FILE_OPENED
Definition: language.h:230
#define SERIAL_ECHOLNPGM(S)
Definition: serial.h:174
#define MSG_SD_SIZE
Definition: language.h:231
const uint8_t O_READ
Definition: SdBaseFile.h:53
list b
Definition: createSpeedLookupTable.py:30
#define MSG_SD_INIT_FAIL
Definition: language.h:224
#define MSG_SD_CARD_OK
Definition: language.h:227
const uint8_t O_SYNC
Definition: SdBaseFile.h:60
const uint8_t DIR_NAME_FREE
Definition: SdFatStructs.h:562
static int write(struct _reent *_r, void *pv, const char *pc, int n)
Definition: gcode_file.cpp:17
uint32_t millis_t
Definition: millis_t.h:26
#define ENABLED(V...)
Definition: macros.h:177
Planner planner
Definition: planner.cpp:111
#define bit(b)
Definition: wiring_constants.h:96
const uint8_t O_CREAT
Definition: SdBaseFile.h:63