|
|
@ -61,7 +61,8 @@ |
|
|
|
|
|
|
|
card_flags_t CardReader::flag; |
|
|
|
char CardReader::filename[FILENAME_LENGTH], CardReader::longFilename[LONG_FILENAME_LENGTH]; |
|
|
|
int8_t CardReader::autostart_index; |
|
|
|
|
|
|
|
IF_DISABLED(NO_SD_AUTOSTART, uint8_t CardReader::autofile_index); // = 0
|
|
|
|
|
|
|
|
#if BOTH(HAS_MULTI_SERIAL, BINARY_FILE_TRANSFER) |
|
|
|
int8_t CardReader::transfer_port_index; |
|
|
@ -135,17 +136,17 @@ CardReader::CardReader() { |
|
|
|
//sort_reverse = false;
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
flag.sdprinting = flag.mounted = flag.saving = flag.logging = false; |
|
|
|
filesize = sdpos = 0; |
|
|
|
|
|
|
|
TERN_(HAS_MEDIA_SUBCALLS, file_subcall_ctr = 0); |
|
|
|
|
|
|
|
IF_DISABLED(NO_SD_AUTOSTART, autofile_cancel()); |
|
|
|
|
|
|
|
workDirDepth = 0; |
|
|
|
ZERO(workDirParents); |
|
|
|
|
|
|
|
// Disable autostart until card is initialized
|
|
|
|
autostart_index = -1; |
|
|
|
|
|
|
|
#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) |
|
|
|
SET_INPUT_PULLUP(SD_DETECT_PIN); |
|
|
|
#endif |
|
|
@ -442,12 +443,14 @@ void CardReader::manage_media() { |
|
|
|
|
|
|
|
if (stat) { |
|
|
|
TERN_(SDCARD_EEPROM_EMULATION, settings.first_load()); |
|
|
|
if (old_stat == 2) // First mount?
|
|
|
|
if (old_stat == 2) { // First mount?
|
|
|
|
DEBUG_ECHOLNPGM("First mount."); |
|
|
|
TERN(POWER_LOSS_RECOVERY, |
|
|
|
recovery.check(), // Check for PLR file. (If not there it will beginautostart)
|
|
|
|
beginautostart() // Look for auto0.g on the next loop
|
|
|
|
); |
|
|
|
#if ENABLED(POWER_LOSS_RECOVERY) |
|
|
|
recovery.check(); // Check for PLR file. (If not there then call autofile_begin)
|
|
|
|
#elif DISABLED(NO_SD_AUTOSTART) |
|
|
|
autofile_begin(); // Look for auto0.g on the next loop
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
@ -477,12 +480,12 @@ void CardReader::release() { |
|
|
|
* Enqueues M23 and M24 commands to initiate a media print. |
|
|
|
*/ |
|
|
|
void CardReader::openAndPrintFile(const char *name) { |
|
|
|
char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
|
|
|
|
char cmd[4 + strlen(name) + 1 + 3 + 1]; // Room for "M23 ", filename, "\n", "M24", and null
|
|
|
|
extern const char M23_STR[]; |
|
|
|
sprintf_P(cmd, M23_STR, name); |
|
|
|
for (char *c = &cmd[4]; *c; c++) *c = tolower(*c); |
|
|
|
queue.enqueue_one_now(cmd); |
|
|
|
queue.enqueue_now_P(M24_STR); |
|
|
|
strcat_P(cmd, PSTR("\nM24")); |
|
|
|
queue.inject(cmd); |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
@ -511,7 +514,7 @@ void CardReader::endFilePrint(TERN_(SD_RESORT, const bool re_sort/*=false*/)) { |
|
|
|
|
|
|
|
void CardReader::openLogFile(char * const path) { |
|
|
|
flag.logging = DISABLED(SDCARD_READONLY); |
|
|
|
TERN(SDCARD_READONLY,,openFileWrite(path)); |
|
|
|
IF_DISABLED(SDCARD_READONLY, openFileWrite(path)); |
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
@ -735,42 +738,48 @@ void CardReader::write_command(char * const buf) { |
|
|
|
if (file.writeError) SERIAL_ERROR_MSG(STR_SD_ERR_WRITE_TO_FILE); |
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
|
// Run the next autostart file. Called:
|
|
|
|
// - On boot after successful card init
|
|
|
|
// - After finishing the previous autostart file
|
|
|
|
// - From the LCD command to run the autostart file
|
|
|
|
//
|
|
|
|
|
|
|
|
void CardReader::checkautostart() { |
|
|
|
|
|
|
|
if (autostart_index < 0 || flag.sdprinting) return; |
|
|
|
|
|
|
|
if (!isMounted()) mount(); |
|
|
|
TERN_(SDCARD_EEPROM_EMULATION, else settings.first_load()); |
|
|
|
#if DISABLED(NO_SD_AUTOSTART) |
|
|
|
/**
|
|
|
|
* Run all the auto#.g files. Called: |
|
|
|
* - On boot after successful card init. |
|
|
|
* - From the LCD command to Run Auto Files |
|
|
|
*/ |
|
|
|
void CardReader::autofile_begin() { |
|
|
|
autofile_index = 1; |
|
|
|
(void)autofile_check(); |
|
|
|
} |
|
|
|
|
|
|
|
// Don't run auto#.g when a PLR file exists
|
|
|
|
if (isMounted() && TERN1(POWER_LOSS_RECOVERY, !recovery.valid())) { |
|
|
|
char autoname[8]; |
|
|
|
sprintf_P(autoname, PSTR("auto%c.g"), autostart_index + '0'); |
|
|
|
dir_t p; |
|
|
|
root.rewind(); |
|
|
|
while (root.readDir(&p, nullptr) > 0) { |
|
|
|
for (int8_t i = (int8_t)strlen((char*)p.name); i--;) p.name[i] = tolower(p.name[i]); |
|
|
|
if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) { |
|
|
|
/**
|
|
|
|
* Run the next auto#.g file. Called: |
|
|
|
* - On boot after successful card init |
|
|
|
* - After finishing the previous auto#.g file |
|
|
|
* - From the LCD command to begin the auto#.g files |
|
|
|
* |
|
|
|
* Return 'true' if there was nothing to do |
|
|
|
*/ |
|
|
|
bool CardReader::autofile_check() { |
|
|
|
if (!autofile_index) return true; |
|
|
|
|
|
|
|
if (!isMounted()) |
|
|
|
mount(); |
|
|
|
else if (ENABLED(SDCARD_EEPROM_EMULATION)) |
|
|
|
settings.first_load(); |
|
|
|
|
|
|
|
// Don't run auto#.g when a PLR file exists
|
|
|
|
if (isMounted() && TERN1(POWER_LOSS_RECOVERY, !recovery.valid())) { |
|
|
|
char autoname[10]; |
|
|
|
sprintf_P(autoname, PSTR("/auto%c.g"), '0' + autofile_index - 1); |
|
|
|
if (fileExists(autoname)) { |
|
|
|
cdroot(); |
|
|
|
openAndPrintFile(autoname); |
|
|
|
autostart_index++; |
|
|
|
return; |
|
|
|
autofile_index++; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
autofile_cancel(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
autostart_index = -1; |
|
|
|
} |
|
|
|
|
|
|
|
void CardReader::beginautostart() { |
|
|
|
autostart_index = 0; |
|
|
|
cdroot(); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
void CardReader::closefile(const bool store_location/*=false*/) { |
|
|
|
file.sync(); |
|
|
|