Creality3D Power-Loss Recovery
This commit is contained in:
@ -33,6 +33,10 @@
|
||||
#include "../core/language.h"
|
||||
#include "../gcode/queue.h"
|
||||
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
#include "../feature/power_loss_recovery.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
||||
#include "../feature/pause.h"
|
||||
#endif
|
||||
@ -968,6 +972,15 @@ void CardReader::printingHasFinished() {
|
||||
}
|
||||
else {
|
||||
sdprinting = false;
|
||||
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
openJobRecoveryFile(false);
|
||||
job_recovery_info.valid_head = job_recovery_info.valid_foot = 0;
|
||||
(void)saveJobRecoveryInfo();
|
||||
closeJobRecoveryFile();
|
||||
job_recovery_commands_count = 0;
|
||||
#endif
|
||||
|
||||
#if ENABLED(SD_FINISHED_STEPPERRELEASE) && defined(SD_FINISHED_RELEASECOMMAND)
|
||||
stepper.cleaning_buffer_counter = 1; // The command will fire from the Stepper ISR
|
||||
#endif
|
||||
@ -1006,4 +1019,46 @@ void CardReader::printingHasFinished() {
|
||||
}
|
||||
#endif // AUTO_REPORT_SD_STATUS
|
||||
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
|
||||
char job_recovery_file_name[4] = "bin";
|
||||
|
||||
void CardReader::openJobRecoveryFile(const bool read) {
|
||||
if (!cardOK) return;
|
||||
if (jobRecoveryFile.isOpen()) return;
|
||||
if (!jobRecoveryFile.open(&root, job_recovery_file_name, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) {
|
||||
SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, job_recovery_file_name);
|
||||
SERIAL_PROTOCOLCHAR('.');
|
||||
SERIAL_EOL();
|
||||
}
|
||||
else
|
||||
SERIAL_PROTOCOLLNPAIR(MSG_SD_WRITE_TO_FILE, job_recovery_file_name);
|
||||
}
|
||||
|
||||
void CardReader::closeJobRecoveryFile() { jobRecoveryFile.close(); }
|
||||
|
||||
bool CardReader::jobRecoverFileExists() {
|
||||
return jobRecoveryFile.open(&root, job_recovery_file_name, O_READ);
|
||||
}
|
||||
|
||||
int16_t CardReader::saveJobRecoveryInfo() {
|
||||
jobRecoveryFile.seekSet(0);
|
||||
const int16_t ret = jobRecoveryFile.write(&job_recovery_info, sizeof(job_recovery_info));
|
||||
if (ret == -1) SERIAL_PROTOCOLLNPGM("Power-loss file write failed.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int16_t CardReader::loadJobRecoveryInfo() {
|
||||
return jobRecoveryFile.read(&job_recovery_info, sizeof(job_recovery_info));
|
||||
}
|
||||
|
||||
void CardReader::removeJobRecoveryFile() {
|
||||
if (jobRecoveryFile.remove(&root, job_recovery_file_name))
|
||||
SERIAL_PROTOCOLLNPGM("Power-loss file deleted.");
|
||||
else
|
||||
SERIAL_PROTOCOLLNPGM("Power-loss file delete failed.");
|
||||
}
|
||||
|
||||
#endif // POWER_LOSS_RECOVERY
|
||||
|
||||
#endif // SDSUPPORT
|
||||
|
@ -103,11 +103,21 @@ public:
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
void openJobRecoveryFile(const bool read);
|
||||
void closeJobRecoveryFile();
|
||||
bool jobRecoverFileExists();
|
||||
int16_t saveJobRecoveryInfo();
|
||||
int16_t loadJobRecoveryInfo();
|
||||
void removeJobRecoveryFile();
|
||||
#endif
|
||||
|
||||
FORCE_INLINE void pauseSDPrint() { sdprinting = false; }
|
||||
FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
|
||||
FORCE_INLINE bool eof() { return sdpos >= filesize; }
|
||||
FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
|
||||
FORCE_INLINE void setIndex(long index) { sdpos = index; file.seekSet(index); }
|
||||
FORCE_INLINE void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }
|
||||
FORCE_INLINE uint32_t getIndex() { return sdpos; }
|
||||
FORCE_INLINE uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
|
||||
FORCE_INLINE char* getWorkDirName() { workDir.getFilename(filename); return filename; }
|
||||
|
||||
@ -191,6 +201,10 @@ private:
|
||||
SdVolume volume;
|
||||
SdFile file;
|
||||
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
SdFile jobRecoveryFile;
|
||||
#endif
|
||||
|
||||
#define SD_PROCEDURE_DEPTH 1
|
||||
#define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
|
||||
uint8_t file_subcall_ctr;
|
||||
|
Reference in New Issue
Block a user