Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧑‍💻 CardReader::isStillPrinting #27392

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ void sd_mmc_spi_mem_init() {
}

inline bool media_ready() {
return IS_SD_INSERTED() && !IS_SD_PRINTING() && !IS_SD_FILE_OPEN() && card.isMounted();
return DISABLED(DISABLE_DUE_SD_MMC)
&& IS_SD_MOUNTED() && IS_SD_INSERTED()
&& !IS_SD_FILE_OPEN() && !IS_SD_PRINTING();
}

bool sd_mmc_spi_unload(bool) { return true; }
Expand All @@ -29,17 +31,14 @@ bool sd_mmc_spi_wr_protect() { return false; }
bool sd_mmc_spi_removal() { return !media_ready(); }

Ctrl_status sd_mmc_spi_test_unit_ready() {
#ifdef DISABLE_DUE_SD_MMC
return CTRL_NO_PRESENT;
#endif
if (!media_ready()) return CTRL_NO_PRESENT;
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
return CTRL_GOOD;
}

// 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 (!media_ready()) return CTRL_NO_PRESENT;
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
*nb_sector = card.diskIODriver()->cardSize() - 1;
return CTRL_GOOD;
}
Expand All @@ -58,10 +57,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) {
#ifdef DISABLE_DUE_SD_MMC
return CTRL_NO_PRESENT;
#endif
if (!media_ready()) return CTRL_NO_PRESENT;
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;

#ifdef DEBUG_MMC
{
Expand Down Expand Up @@ -97,10 +93,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) {
#ifdef DISABLE_DUE_SD_MMC
return CTRL_NO_PRESENT;
#endif
if (!media_ready()) return CTRL_NO_PRESENT;
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;

#ifdef DEBUG_MMC
{
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/feature/pause/M125.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void GcodeSuite::M125() {
park_point += hotend_offset[active_extruder];
#endif

const bool sd_printing = TERN0(HAS_MEDIA, IS_SD_PRINTING());
const bool sd_printing = IS_SD_PRINTING();

ui.pause_show_message(PAUSE_MESSAGE_PARKING, PAUSE_MODE_PAUSE_PRINT);

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,10 +1178,10 @@ namespace ExtUI {
}

bool isPrintingFromMediaPaused() {
return TERN0(HAS_MEDIA, IS_SD_PAUSED());
return IS_SD_PAUSED();
}

bool isPrintingFromMedia() { return TERN0(HAS_MEDIA, IS_SD_PRINTING() || IS_SD_PAUSED()); }
bool isPrintingFromMedia() { return IS_SD_PRINTING() || IS_SD_PAUSED(); }

bool isPrinting() {
return commandsInQueue() || isPrintingFromMedia() || printJobOngoing() || printingIsPaused();
Expand Down
18 changes: 10 additions & 8 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ CardReader::CardReader() {
}

//
// Get a DOS 8.3 filename in its useful form
// Get a DOS 8.3 filename in its useful form, e.g., "MYFILE EXT" => "MYFILE.EXT"
//
char *createFilename(char * const buffer, const dir_t &p) {
char *pos = buffer;
Expand All @@ -193,10 +193,14 @@ char *createFilename(char * const buffer, const dir_t &p) {
if (i == 8) *pos++ = '.';
*pos++ = p.name[i];
}
*pos++ = 0;
*pos++ = '\0';
return buffer;
}

inline bool extIsBIN(char *ext) {
return ext[0] == 'B' && ext[1] == 'I' && ext[2] == 'N';
}

//
// Return 'true' if the item is a folder, G-code file or Binary file
//
Expand All @@ -215,9 +219,7 @@ bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD,
) return false;

flag.filenameIsDir = DIR_IS_SUBDIR(&p); // We know it's a File or Folder
setBinFlag(p.name[8] == 'B' && // List .bin files (a firmware file for flashing)
p.name[9] == 'I' &&
p.name[10]== 'N');
setBinFlag(extIsBIN((char *)&p.name[8])); // List .bin files (a firmware file for flashing)

return (
flag.filenameIsDir // All Directories are ok
Expand Down Expand Up @@ -576,7 +578,7 @@ void CardReader::manage_media() {
*/
void CardReader::release() {
// Card removed while printing? Abort!
if (IS_SD_PRINTING())
if (isStillPrinting())
abortFilePrintSoon();
else
endFilePrintNow();
Expand Down Expand Up @@ -993,7 +995,7 @@ void CardReader::selectFileByIndex(const int16_t nr) {
strcpy(filename, sortshort[nr]);
strcpy(longFilename, sortnames[nr]);
TERN_(HAS_FOLDER_SORTING, flag.filenameIsDir = IS_DIR(nr));
setBinFlag(strcmp_P(strrchr(filename, '.'), PSTR(".BIN")) == 0);
setBinFlag(extIsBIN(strrchr(filename, '.') + 1));
return;
}
#endif
Expand All @@ -1011,7 +1013,7 @@ void CardReader::selectFileByName(const char * const match) {
strcpy(filename, sortshort[nr]);
strcpy(longFilename, sortnames[nr]);
TERN_(HAS_FOLDER_SORTING, flag.filenameIsDir = IS_DIR(nr));
setBinFlag(strcmp_P(strrchr(filename, '.'), PSTR(".BIN")) == 0);
setBinFlag(extIsBIN(strrchr(filename, '.') + 1));
return;
}
#endif
Expand Down
27 changes: 15 additions & 12 deletions Marlin/src/sd/cardreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ extern const char M23_STR[], M24_STR[];
#endif

typedef struct {
bool saving:1,
logging:1,
sdprinting:1,
sdprintdone:1,
mounted:1,
filenameIsDir:1,
workDirIsRoot:1,
abort_sd_printing:1
bool saving:1, // Receiving a G-code file or logging commands during a print
logging:1, // Log enqueued commands to the open file. See GCodeQueue::advance()
sdprinting:1, // Actively printing from the open file
sdprintdone:1, // The active job has reached the end, 100%
mounted:1, // The card or flash drive is mounted and ready to read/write
filenameIsDir:1, // The working item is a directory
workDirIsRoot:1, // The working directory is / so there's no parent
abort_sd_printing:1 // Abort by calling abortSDPrinting() at the main loop()
#if DO_LIST_BIN_FILES
, filenameIsBin:1
, filenameIsBin:1 // The working item is a BIN file
#endif
#if ENABLED(BINARY_FILE_TRANSFER)
, binary_mode:1
, binary_mode:1 // Use the serial line buffer as BinaryStream input
#endif
;
} card_flags_t;
Expand Down Expand Up @@ -173,6 +173,7 @@ class CardReader {
static void abortFilePrintSoon() { flag.abort_sd_printing = isFileOpen(); }
static void pauseSDPrint() { flag.sdprinting = false; }
static bool isPrinting() { return flag.sdprinting; }
static bool isStillPrinting() { return flag.sdprinting && !flag.abort_sd_printing; }
static bool isPaused() { return isFileOpen() && !isPrinting(); }
#if HAS_PRINT_PROGRESS_PERMYRIAD
static uint16_t permyriadDone() {
Expand Down Expand Up @@ -367,15 +368,17 @@ class CardReader {
#define IS_SD_INSERTED() true
#endif

#define IS_SD_PRINTING() (card.flag.sdprinting && !card.flag.abort_sd_printing)
#define IS_SD_FETCHING() (!card.flag.sdprintdone && IS_SD_PRINTING())
#define IS_SD_MOUNTED() card.isMounted()
#define IS_SD_PRINTING() card.isStillPrinting()
#define IS_SD_FETCHING() (!card.flag.sdprintdone && card.isStillPrinting())
#define IS_SD_PAUSED() card.isPaused()
#define IS_SD_FILE_OPEN() card.isFileOpen()

extern CardReader card;

#else // !HAS_MEDIA

#define IS_SD_MOUNTED() false
#define IS_SD_PRINTING() false
#define IS_SD_FETCHING() false
#define IS_SD_PAUSED() false
Expand Down
Loading