Skip to content

Commit 8411336

Browse files
committed
📝 CardReader comments
1 parent c24ecfb commit 8411336

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

Marlin/src/sd/cardreader.cpp

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ void CardReader::mount() {
512512
ui.refresh();
513513
}
514514

515-
/**
516-
* Handle SD card events
517-
*/
518515
#if MB(FYSETC_CHEETAH, FYSETC_AIO_II)
519516
#include "../module/stepper.h"
520517
#endif
521518

519+
/**
520+
* Handle SD card events
521+
*/
522522
void CardReader::manage_media() {
523523
static uint8_t prev_stat = 2; // At boot we don't know if media is present or not
524524
uint8_t stat = uint8_t(IS_SD_INSERTED());
@@ -639,6 +639,10 @@ void CardReader::abortFilePrintNow(TERN_(SD_RESORT, const bool re_sort/*=false*/
639639
endFilePrintNow(TERN_(SD_RESORT, re_sort));
640640
}
641641

642+
/**
643+
* Open a log file for writing, if possible.
644+
* Used by G-code M928 <path>.
645+
*/
642646
void CardReader::openLogFile(const char * const path) {
643647
flag.logging = DISABLED(SDCARD_READONLY);
644648
IF_DISABLED(SDCARD_READONLY, openFileWrite(path));
@@ -667,10 +671,16 @@ void CardReader::getAbsFilenameInCWD(char *dst) {
667671
*dst = '\0';
668672
}
669673

674+
//
675+
// Print "open failed, File: : <filename>.\n" to serial
676+
//
670677
void openFailed(const char * const fname) {
671678
SERIAL_ECHOLNPGM(STR_SD_OPEN_FILE_FAIL, fname, ".");
672679
}
673680

681+
//
682+
// Print "echo: Now doing/fresh file: <filepath>\n" to all serial ports
683+
//
674684
void announceOpen(const uint8_t doing, const char * const path) {
675685
if (doing) {
676686
PORT_REDIRECT(SerialMask::All);
@@ -679,14 +689,14 @@ void announceOpen(const uint8_t doing, const char * const path) {
679689
}
680690
}
681691

682-
//
683-
// Open a file by DOS path for read
684-
// The 'subcall_type' flag indicates...
685-
// - 0 : Standard open from host or user interface.
686-
// - 1 : (file open) Opening a new sub-procedure.
687-
// - 1 : (no file open) Opening a macro (M98).
688-
// - 2 : Resuming from a sub-procedure
689-
//
692+
/**
693+
* Open a file by DOS path for read
694+
* The 'subcall_type' flag indicates...
695+
* - 0 : Standard open from host or user interface.
696+
* - 1 : (file open) Opening a new sub-procedure.
697+
* - 1 : (no file open) Opening a macro (M98).
698+
* - 2 : Resuming from a sub-procedure
699+
*/
690700
void CardReader::openFileRead(const char * const path, const uint8_t subcall_type/*=0*/) {
691701
if (!isMounted()) return openFailed(path);
692702

@@ -749,6 +759,9 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ
749759
openFailed(fname);
750760
}
751761

762+
//
763+
// Print "Writing to file: <filename>\n" to serial
764+
//
752765
inline void echo_write_to_file(const char * const fname) {
753766
SERIAL_ECHOLNPGM(STR_SD_WRITE_TO_FILE, fname);
754767
}
@@ -782,10 +795,10 @@ void CardReader::openFileWrite(const char * const path) {
782795
openFailed(fname);
783796
}
784797

785-
//
786-
// Check if a file exists by absolute or workDir-relative path
787-
// If the file exists, the long name can also be fetched.
788-
//
798+
/**
799+
* Check if a file exists by absolute or workDir-relative path
800+
* If the file exists, the long name can also be fetched.
801+
*/
789802
bool CardReader::fileExists(const char * const path) {
790803
if (!isMounted()) return false;
791804

@@ -852,6 +865,9 @@ void CardReader::report_status(TERN_(QUIETER_AUTO_REPORT_SD_STATUS, const bool i
852865
SERIAL_ECHOLNPGM(STR_SD_NOT_PRINTING);
853866
}
854867

868+
//
869+
// Write a command to the log file
870+
//
855871
void CardReader::write_command(char * const buf) {
856872
char *begin = buf,
857873
*npos = nullptr,
@@ -988,16 +1004,20 @@ void CardReader::write_command(char * const buf) {
9881004

9891005
#endif // ONE_CLICK_PRINT
9901006

1007+
//
1008+
// Close the working file.
1009+
//
9911010
void CardReader::closefile(const bool store_location/*=false*/) {
9921011
file.sync();
9931012
file.close();
9941013
flag.saving = flag.logging = false;
9951014
sdpos = 0;
1015+
9961016
TERN_(EMERGENCY_PARSER, emergency_parser.enable());
9971017

9981018
if (store_location) {
999-
//future: store printer state, filename and position for continuing a stopped print
1000-
// so one can unplug the printer and continue printing the next day.
1019+
// TODO: Store printer state, filename, position
1020+
// for continuing a stopped print.
10011021
}
10021022
}
10031023

@@ -1139,6 +1159,9 @@ const char* CardReader::diveToFile(const bool update_cwd, MediaFile* &inDirPtr,
11391159
return atom_ptr;
11401160
}
11411161

1162+
//
1163+
// Change the working directory to the given sub-path
1164+
//
11421165
void CardReader::cd(const char * relpath) {
11431166
MediaFile newDir, *parent = &getWorkDir();
11441167

@@ -1154,6 +1177,9 @@ void CardReader::cd(const char * relpath) {
11541177
SERIAL_ECHO_MSG(STR_SD_CANT_ENTER_SUBDIR, relpath);
11551178
}
11561179

1180+
//
1181+
// Change the working directory to its parent
1182+
//
11571183
int8_t CardReader::cdup() {
11581184
if (workDirDepth > 0) { // At least 1 dir has been saved
11591185
nrItems = -1;
@@ -1164,6 +1190,9 @@ int8_t CardReader::cdup() {
11641190
return workDirDepth;
11651191
}
11661192

1193+
//
1194+
// Change the working directory to the volume root
1195+
//
11671196
void CardReader::cdroot() {
11681197
workDir = root;
11691198
flag.workDirIsRoot = true;
@@ -1406,17 +1435,21 @@ void CardReader::cdroot() {
14061435

14071436
#endif // SDCARD_SORT_ALPHA
14081437

1438+
//
1439+
// Return the count of visible items in the working directory.
1440+
//
14091441
int16_t CardReader::get_num_items() {
14101442
if (!isMounted()) return 0;
14111443
if (nrItems < 0) nrItems = countVisibleItems(workDir);
14121444
return nrItems;
14131445
}
14141446

14151447
//
1416-
// Return from procedure or close out the Print Job
1448+
// Return from procedure or close out the Print Job.
14171449
//
14181450
void CardReader::fileHasFinished() {
14191451
file.close();
1452+
14201453
#if HAS_MEDIA_SUBCALLS
14211454
if (file_subcall_ctr > 0) { // Resume calling file after closing procedure
14221455
file_subcall_ctr--;

0 commit comments

Comments
 (0)