Browse Source

Improve menu pause / resume (#12876)

pull/1/head
InsanityAutomation 6 years ago
committed by Scott Lahteine
parent
commit
a403d9a50c
  1. 10
      Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp
  2. 2
      Marlin/src/HAL/HAL_LPC1768/main.cpp
  3. 4
      Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
  4. 4
      Marlin/src/feature/power_loss_recovery.cpp
  5. 29
      Marlin/src/gcode/sdcard/M20-M30_M32-M34_M524_M928.cpp
  6. 8
      Marlin/src/lcd/extensible_ui/ui_api.cpp
  7. 2
      Marlin/src/lcd/malyanlcd.cpp
  8. 76
      Marlin/src/lcd/menu/menu_main.cpp
  9. 2
      Marlin/src/lcd/menu/menu_sdcard.cpp
  10. 22
      Marlin/src/sd/cardreader.cpp
  11. 7
      Marlin/src/sd/cardreader.h

10
Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp

@ -19,7 +19,7 @@ void sd_mmc_spi_mem_init(void) {
} }
Ctrl_status sd_mmc_spi_test_unit_ready(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_NO_PRESENT;
return CTRL_GOOD; 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 // NOTE: This function is defined as returning the address of the last block
// in the card, which is cardSize() - 1 // in the card, which is cardSize() - 1
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) { 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; return CTRL_NO_PRESENT;
*nb_sector = card.getSd2Card().cardSize() - 1; *nb_sector = card.getSd2Card().cardSize() - 1;
return CTRL_GOOD; return CTRL_GOOD;
@ -42,7 +42,7 @@ bool sd_mmc_spi_wr_protect(void) {
} }
bool sd_mmc_spi_removal(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 true;
return false; return false;
} }
@ -61,7 +61,7 @@ uint8_t sector_buf[SD_MMC_BLOCK_SIZE];
// #define DEBUG_MMC // #define DEBUG_MMC
Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { 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; return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC #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) { 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; return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC #ifdef DEBUG_MMC

2
Marlin/src/HAL/HAL_LPC1768/main.cpp

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

4
Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp

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

4
Marlin/src/feature/power_loss_recovery.cpp

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

29
Marlin/src/gcode/sdcard/M20-M30_M32-M34_M524_M928.cpp

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

8
Marlin/src/lcd/extensible_ui/ui_api.cpp

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

2
Marlin/src/lcd/malyanlcd.cpp

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

76
Marlin/src/lcd/menu/menu_main.cpp

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

2
Marlin/src/lcd/menu/menu_sdcard.cpp

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

22
Marlin/src/sd/cardreader.cpp

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

7
Marlin/src/sd/cardreader.h

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

Loading…
Cancel
Save