Improve menu pause / resume (#12876)

This commit is contained in:
InsanityAutomation
2019-01-11 21:42:11 -05:00
committed by Scott Lahteine
parent 432c21456f
commit a403d9a50c
11 changed files with 108 additions and 88 deletions

View File

@ -124,7 +124,7 @@ CardReader::CardReader() {
//sort_reverse = false;
#endif
#endif
flag.sdprinting = flag.cardOK = flag.saving = flag.logging = false;
flag.sdprinting = flag.detected = flag.saving = flag.logging = false;
filesize = sdpos = 0;
file_subcall_ctr = 0;
@ -360,7 +360,7 @@ void CardReader::printFilename(
}
void CardReader::initsd() {
flag.cardOK = false;
flag.detected = false;
if (root.isOpen()) root.close();
#ifndef SPI_SPEED
@ -380,7 +380,7 @@ void CardReader::initsd() {
else if (!root.openRoot(&volume))
SERIAL_ERROR_MSG(MSG_SD_OPENROOT_FAIL);
else {
flag.cardOK = true;
flag.detected = true;
SERIAL_ECHO_MSG(MSG_SD_CARD_OK);
}
setroot();
@ -390,7 +390,7 @@ void CardReader::initsd() {
void CardReader::release() {
stopSDPrint();
flag.cardOK = false;
flag.detected = false;
}
void CardReader::openAndPrintFile(const char *name) {
@ -402,7 +402,7 @@ void CardReader::openAndPrintFile(const char *name) {
}
void CardReader::startFileprint() {
if (flag.cardOK) {
if (isDetected()) {
flag.sdprinting = true;
#if SD_RESORT
flush_presort();
@ -452,7 +452,7 @@ void CardReader::getAbsFilename(char *t) {
void CardReader::openFile(char * const path, const bool read, const bool subcall/*=false*/) {
if (!flag.cardOK) return;
if (!isDetected()) return;
uint8_t doing = 0;
if (isFileOpen()) { // Replacing current file or doing a subroutine
@ -535,7 +535,7 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall
}
void CardReader::removeFile(const char * const name) {
if (!flag.cardOK) return;
if (!isDetected()) return;
//stopSDPrint();
@ -561,7 +561,7 @@ void CardReader::report_status(
const int8_t port/*= -1*/
#endif
) {
if (flag.cardOK && flag.sdprinting) {
if (isPrinting()) {
SERIAL_ECHOPGM_P(port, MSG_SD_PRINTING_BYTE);
SERIAL_ECHO_P(port, sdpos);
SERIAL_CHAR_P(port, '/');
@ -600,9 +600,9 @@ void CardReader::checkautostart() {
if (autostart_index < 0 || flag.sdprinting) return;
if (!flag.cardOK) initsd();
if (!isDetected()) initsd();
if (flag.cardOK
if (isDetected()
#if ENABLED(POWER_LOSS_RECOVERY)
&& !recovery.valid() // Don't run auto#.g when a resume file exists
#endif
@ -1065,7 +1065,7 @@ void CardReader::printingHasFinished() {
}
void CardReader::openJobRecoveryFile(const bool read) {
if (!flag.cardOK) return;
if (!isDetected()) return;
if (recovery.file.isOpen()) return;
if (!recovery.file.open(&root, job_recovery_file_name, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) {
SERIAL_ECHOPAIR(MSG_SD_OPEN_FILE_FAIL, job_recovery_file_name);

View File

@ -39,7 +39,7 @@ typedef struct {
bool saving:1,
logging:1,
sdprinting:1,
cardOK:1,
detected:1,
filenameIsDir:1,
abort_sd_printing:1
#if ENABLED(FAST_FILE_TRANSFER)
@ -127,7 +127,10 @@ public:
#endif
static inline void pauseSDPrint() { flag.sdprinting = false; }
static inline bool isFileOpen() { return file.isOpen(); }
static inline bool isDetected() { return flag.detected; }
static inline bool isFileOpen() { return isDetected() && file.isOpen(); }
static inline bool isPaused() { return isFileOpen() && !flag.sdprinting; }
static inline bool isPrinting() { return flag.sdprinting; }
static inline bool eof() { return sdpos >= filesize; }
static inline int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }