mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2026-03-04 09:04:42 -07:00
📝 CardReader comments
This commit is contained in:
parent
c24ecfb6f0
commit
84113367fc
1 changed files with 51 additions and 18 deletions
|
|
@ -512,13 +512,13 @@ void CardReader::mount() {
|
|||
ui.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle SD card events
|
||||
*/
|
||||
#if MB(FYSETC_CHEETAH, FYSETC_AIO_II)
|
||||
#include "../module/stepper.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Handle SD card events
|
||||
*/
|
||||
void CardReader::manage_media() {
|
||||
static uint8_t prev_stat = 2; // At boot we don't know if media is present or not
|
||||
uint8_t stat = uint8_t(IS_SD_INSERTED());
|
||||
|
|
@ -639,6 +639,10 @@ void CardReader::abortFilePrintNow(TERN_(SD_RESORT, const bool re_sort/*=false*/
|
|||
endFilePrintNow(TERN_(SD_RESORT, re_sort));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a log file for writing, if possible.
|
||||
* Used by G-code M928 <path>.
|
||||
*/
|
||||
void CardReader::openLogFile(const char * const path) {
|
||||
flag.logging = DISABLED(SDCARD_READONLY);
|
||||
IF_DISABLED(SDCARD_READONLY, openFileWrite(path));
|
||||
|
|
@ -667,10 +671,16 @@ void CardReader::getAbsFilenameInCWD(char *dst) {
|
|||
*dst = '\0';
|
||||
}
|
||||
|
||||
//
|
||||
// Print "open failed, File: : <filename>.\n" to serial
|
||||
//
|
||||
void openFailed(const char * const fname) {
|
||||
SERIAL_ECHOLNPGM(STR_SD_OPEN_FILE_FAIL, fname, ".");
|
||||
}
|
||||
|
||||
//
|
||||
// Print "echo: Now doing/fresh file: <filepath>\n" to all serial ports
|
||||
//
|
||||
void announceOpen(const uint8_t doing, const char * const path) {
|
||||
if (doing) {
|
||||
PORT_REDIRECT(SerialMask::All);
|
||||
|
|
@ -679,14 +689,14 @@ void announceOpen(const uint8_t doing, const char * const path) {
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Open a file by DOS path for read
|
||||
// The 'subcall_type' flag indicates...
|
||||
// - 0 : Standard open from host or user interface.
|
||||
// - 1 : (file open) Opening a new sub-procedure.
|
||||
// - 1 : (no file open) Opening a macro (M98).
|
||||
// - 2 : Resuming from a sub-procedure
|
||||
//
|
||||
/**
|
||||
* Open a file by DOS path for read
|
||||
* The 'subcall_type' flag indicates...
|
||||
* - 0 : Standard open from host or user interface.
|
||||
* - 1 : (file open) Opening a new sub-procedure.
|
||||
* - 1 : (no file open) Opening a macro (M98).
|
||||
* - 2 : Resuming from a sub-procedure
|
||||
*/
|
||||
void CardReader::openFileRead(const char * const path, const uint8_t subcall_type/*=0*/) {
|
||||
if (!isMounted()) return openFailed(path);
|
||||
|
||||
|
|
@ -749,6 +759,9 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ
|
|||
openFailed(fname);
|
||||
}
|
||||
|
||||
//
|
||||
// Print "Writing to file: <filename>\n" to serial
|
||||
//
|
||||
inline void echo_write_to_file(const char * const fname) {
|
||||
SERIAL_ECHOLNPGM(STR_SD_WRITE_TO_FILE, fname);
|
||||
}
|
||||
|
|
@ -782,10 +795,10 @@ void CardReader::openFileWrite(const char * const path) {
|
|||
openFailed(fname);
|
||||
}
|
||||
|
||||
//
|
||||
// Check if a file exists by absolute or workDir-relative path
|
||||
// If the file exists, the long name can also be fetched.
|
||||
//
|
||||
/**
|
||||
* Check if a file exists by absolute or workDir-relative path
|
||||
* If the file exists, the long name can also be fetched.
|
||||
*/
|
||||
bool CardReader::fileExists(const char * const path) {
|
||||
if (!isMounted()) return false;
|
||||
|
||||
|
|
@ -852,6 +865,9 @@ void CardReader::report_status(TERN_(QUIETER_AUTO_REPORT_SD_STATUS, const bool i
|
|||
SERIAL_ECHOLNPGM(STR_SD_NOT_PRINTING);
|
||||
}
|
||||
|
||||
//
|
||||
// Write a command to the log file
|
||||
//
|
||||
void CardReader::write_command(char * const buf) {
|
||||
char *begin = buf,
|
||||
*npos = nullptr,
|
||||
|
|
@ -988,16 +1004,20 @@ void CardReader::write_command(char * const buf) {
|
|||
|
||||
#endif // ONE_CLICK_PRINT
|
||||
|
||||
//
|
||||
// Close the working file.
|
||||
//
|
||||
void CardReader::closefile(const bool store_location/*=false*/) {
|
||||
file.sync();
|
||||
file.close();
|
||||
flag.saving = flag.logging = false;
|
||||
sdpos = 0;
|
||||
|
||||
TERN_(EMERGENCY_PARSER, emergency_parser.enable());
|
||||
|
||||
if (store_location) {
|
||||
//future: store printer state, filename and position for continuing a stopped print
|
||||
// so one can unplug the printer and continue printing the next day.
|
||||
// TODO: Store printer state, filename, position
|
||||
// for continuing a stopped print.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1139,6 +1159,9 @@ const char* CardReader::diveToFile(const bool update_cwd, MediaFile* &inDirPtr,
|
|||
return atom_ptr;
|
||||
}
|
||||
|
||||
//
|
||||
// Change the working directory to the given sub-path
|
||||
//
|
||||
void CardReader::cd(const char * relpath) {
|
||||
MediaFile newDir, *parent = &getWorkDir();
|
||||
|
||||
|
|
@ -1154,6 +1177,9 @@ void CardReader::cd(const char * relpath) {
|
|||
SERIAL_ECHO_MSG(STR_SD_CANT_ENTER_SUBDIR, relpath);
|
||||
}
|
||||
|
||||
//
|
||||
// Change the working directory to its parent
|
||||
//
|
||||
int8_t CardReader::cdup() {
|
||||
if (workDirDepth > 0) { // At least 1 dir has been saved
|
||||
nrItems = -1;
|
||||
|
|
@ -1164,6 +1190,9 @@ int8_t CardReader::cdup() {
|
|||
return workDirDepth;
|
||||
}
|
||||
|
||||
//
|
||||
// Change the working directory to the volume root
|
||||
//
|
||||
void CardReader::cdroot() {
|
||||
workDir = root;
|
||||
flag.workDirIsRoot = true;
|
||||
|
|
@ -1406,6 +1435,9 @@ void CardReader::cdroot() {
|
|||
|
||||
#endif // SDCARD_SORT_ALPHA
|
||||
|
||||
//
|
||||
// Return the count of visible items in the working directory.
|
||||
//
|
||||
int16_t CardReader::get_num_items() {
|
||||
if (!isMounted()) return 0;
|
||||
if (nrItems < 0) nrItems = countVisibleItems(workDir);
|
||||
|
|
@ -1413,10 +1445,11 @@ int16_t CardReader::get_num_items() {
|
|||
}
|
||||
|
||||
//
|
||||
// Return from procedure or close out the Print Job
|
||||
// Return from procedure or close out the Print Job.
|
||||
//
|
||||
void CardReader::fileHasFinished() {
|
||||
file.close();
|
||||
|
||||
#if HAS_MEDIA_SUBCALLS
|
||||
if (file_subcall_ctr > 0) { // Resume calling file after closing procedure
|
||||
file_subcall_ctr--;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue