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

@ -19,7 +19,7 @@ void sd_mmc_spi_mem_init(void) {
}
Ctrl_status sd_mmc_spi_test_unit_ready(void) {
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
return CTRL_NO_PRESENT;
return CTRL_GOOD;
}
@ -27,7 +27,7 @@ Ctrl_status sd_mmc_spi_test_unit_ready(void) {
// NOTE: This function is defined as returning the address of the last block
// in the card, which is cardSize() - 1
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
return CTRL_NO_PRESENT;
*nb_sector = card.getSd2Card().cardSize() - 1;
return CTRL_GOOD;
@ -42,7 +42,7 @@ bool sd_mmc_spi_wr_protect(void) {
}
bool sd_mmc_spi_removal(void) {
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
return true;
return false;
}
@ -61,7 +61,7 @@ uint8_t sector_buf[SD_MMC_BLOCK_SIZE];
// #define DEBUG_MMC
Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC
@ -95,7 +95,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
}
Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.flag.cardOK)
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC

View File

@ -106,7 +106,7 @@ void HAL_idletask(void) {
// the disk if Marlin has it mounted. Unfortuately there is currently no way
// to unmount the disk from the LCD menu.
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
if (card.flag.cardOK)
if (card.isDetected())
MSC_Aquire_Lock();
else
MSC_Release_Lock();

View File

@ -41,7 +41,7 @@ char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
char eeprom_filename[] = "eeprom.dat";
bool PersistentStore::access_start() {
if (!card.flag.cardOK) return false;
if (!card.isDetected()) return false;
int16_t bytes_read = 0;
constexpr char eeprom_zero = 0xFF;
card.openFile(eeprom_filename, true);
@ -54,7 +54,7 @@ bool PersistentStore::access_start() {
}
bool PersistentStore::access_finish() {
if (!card.flag.cardOK) return false;
if (!card.isDetected()) return false;
card.openFile(eeprom_filename, true);
int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
card.closefile();

View File

@ -84,8 +84,8 @@ void PrintJobRecovery::changed() {
*/
void PrintJobRecovery::check() {
if (enabled) {
if (!card.flag.cardOK) card.initsd();
if (card.flag.cardOK) {
if (!card.isDetected()) card.initsd();
if (card.isDetected()) {
load();
if (!valid()) return purge();
enqueue_and_echo_commands_P(PSTR("M1000 S"));

View File

@ -85,18 +85,26 @@ void GcodeSuite::M23() {
* M24: Start or Resume SD Print
*/
void GcodeSuite::M24() {
#if ENABLED(PARK_HEAD_ON_PAUSE)
resume_print();
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
if (parser.seenval('S')) card.setIndex(parser.value_long());
if (parser.seenval('T')) print_job_timer.resume(parser.value_long());
#endif
card.startFileprint();
print_job_timer.start();
ui.reset_status();
#if ENABLED(PARK_HEAD_ON_PAUSE)
resume_print();
#else
if (card.isFileOpen()) {
card.startFileprint();
print_job_timer.start();
}
ui.reset_status();
#ifdef ACTION_ON_RESUME
SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
#endif
#endif
}
/**
@ -106,9 +114,16 @@ void GcodeSuite::M25() {
#if ENABLED(PARK_HEAD_ON_PAUSE)
M125();
#else
card.pauseSDPrint();
#if ENABLED(SDSUPPORT)
if (IS_SD_PRINTING()) card.pauseSDPrint();
#endif
print_job_timer.pause();
ui.reset_status();
#ifdef ACTION_ON_PAUSE
SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
#endif
#endif
}
@ -116,7 +131,7 @@ void GcodeSuite::M25() {
* M26: Set SD Card file index
*/
void GcodeSuite::M26() {
if (card.flag.cardOK && parser.seenval('S'))
if (card.isDetected() && parser.seenval('S'))
card.setIndex(parser.value_long());
}
@ -207,7 +222,7 @@ void GcodeSuite::M29() {
* M30 <filename>: Delete SD Card file
*/
void GcodeSuite::M30() {
if (card.flag.cardOK) {
if (card.isDetected()) {
card.closefile();
card.removeFile(parser.string_arg);
}
@ -226,7 +241,7 @@ void GcodeSuite::M30() {
void GcodeSuite::M32() {
if (IS_SD_PRINTING()) planner.synchronize();
if (card.flag.cardOK) {
if (card.isDetected()) {
const bool call_procedure = parser.boolval('P');
card.openFile(parser.string_arg, true, call_procedure);

View File

@ -578,7 +578,7 @@ namespace ExtUI {
}
bool isPrintingFromMedia() {
return IFSD(card.flag.cardOK && card.isFileOpen(), false);
return IFSD(card.isFileOpen(), false);
}
bool isPrinting() {
@ -586,7 +586,7 @@ namespace ExtUI {
}
bool isMediaInserted() {
return IFSD(IS_SD_INSERTED() && card.flag.cardOK, false);
return IFSD(IS_SD_INSERTED() && card.isDetected(), false);
}
void pausePrint() {
@ -703,13 +703,13 @@ void MarlinUI::update() {
last_sd_status = sd_status;
if (sd_status) {
card.initsd();
if (card.flag.cardOK)
if (card.isDetected())
ExtUI::onMediaInserted();
else
ExtUI::onMediaError();
}
else {
const bool ok = card.flag.cardOK;
const bool ok = card.isDetected();
card.release();
if (ok) ExtUI::onMediaRemoved();
}

View File

@ -330,7 +330,7 @@ void process_lcd_s_command(const char* command) {
case 'L': {
#if ENABLED(SDSUPPORT)
if (!card.flag.cardOK) card.initsd();
if (!card.isDetected()) card.initsd();
// A more efficient way to do this would be to
// implement a callback in the ls_SerialPrint code, but

View File

@ -30,33 +30,38 @@
#include "menu.h"
#include "../../module/temperature.h"
#include "../../gcode/queue.h"
#include "../../module/printcounter.h"
#if ENABLED(POWER_LOSS_RECOVERY)
#include "../../feature/power_loss_recovery.h"
#endif
void lcd_pause() {
#if ENABLED(POWER_LOSS_RECOVERY)
if (recovery.enabled) recovery.save(true, false);
#endif
#if ENABLED(PARK_HEAD_ON_PAUSE)
pause_print(PAUSE_PARK_RETRACT_LENGTH, NOZZLE_PARK_POINT, 0, true);
#elif ENABLED(SDSUPPORT)
enqueue_and_echo_commands_P(PSTR("M25"));
#elif defined(ACTION_ON_PAUSE)
SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
#endif
}
void lcd_resume() {
#if ENABLED(SDSUPPORT)
if (card.isPaused()) enqueue_and_echo_commands_P(PSTR("M24"));
#elif ENABLED(ACTION_ON_RESUME)
SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
#endif
}
#if ENABLED(SDSUPPORT)
#include "../../sd/cardreader.h"
#include "../../gcode/queue.h"
#include "../../module/printcounter.h"
#if ENABLED(POWER_LOSS_RECOVERY)
#include "../../feature/power_loss_recovery.h"
#endif
void lcd_sdcard_pause() {
#if ENABLED(POWER_LOSS_RECOVERY)
if (recovery.enabled) recovery.save(true, false);
#endif
enqueue_and_echo_commands_P(PSTR("M25"));
}
void lcd_sdcard_resume() {
#if ENABLED(PARK_HEAD_ON_PAUSE)
enqueue_and_echo_commands_P(PSTR("M24"));
#else
card.startFileprint();
print_job_timer.start();
ui.reset_status();
#endif
}
void lcd_sdcard_stop() {
wait_for_heatup = wait_for_user = false;
@ -88,35 +93,18 @@ void menu_main() {
START_MENU();
MENU_BACK(MSG_WATCH);
#if ENABLED(SDSUPPORT)
if (card.flag.cardOK) {
if (card.isFileOpen()) {
if (IS_SD_PRINTING())
MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
else
MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
MENU_ITEM(submenu, MSG_STOP_PRINT, menu_sdcard_abort_confirm);
}
else {
MENU_ITEM(submenu, MSG_CARD_MENU, menu_sdcard);
#if !PIN_EXISTS(SD_DETECT)
MENU_ITEM(gcode, MSG_CHANGE_SDCARD, PSTR("M21")); // SD-card changed by user
#endif
}
}
else {
MENU_ITEM(function, MSG_NO_CARD, NULL);
#if !PIN_EXISTS(SD_DETECT)
MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
#endif
}
#endif // SDSUPPORT
const bool busy = printer_busy();
if (busy)
if (busy) {
MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_pause);
MENU_ITEM(submenu, MSG_TUNE, menu_tune);
}
else {
MENU_ITEM(function, MSG_RESUME_PRINT, lcd_resume);
#if ENABLED(SDSUPPORT)
if (card.isFileOpen())
MENU_ITEM(submenu, MSG_STOP_PRINT, menu_sdcard_abort_confirm);
#endif
MENU_ITEM(submenu, MSG_MOTION, menu_motion);
MENU_ITEM(submenu, MSG_TEMPERATURE, menu_temperature);
}
@ -164,6 +152,20 @@ void menu_main() {
MENU_ITEM(function, MSG_AUTOSTART, card.beginautostart);
#endif
#if ENABLED(SDSUPPORT)
if (card.isDetected() && !card.isFileOpen()) {
MENU_ITEM(submenu, MSG_CARD_MENU, menu_sdcard);
#if !PIN_EXISTS(SD_DETECT)
MENU_ITEM(gcode, MSG_CHANGE_SDCARD, PSTR("M21")); // SD-card changed by user
#endif
}
else {
MENU_ITEM(function, MSG_NO_CARD, NULL);
#if !PIN_EXISTS(SD_DETECT)
MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
#endif
}
#endif
END_MENU();
}

View File

@ -111,7 +111,7 @@ void menu_sdcard() {
MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
#endif
}
else if (card.flag.cardOK)
else if (card.isDetected())
MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {

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); }