🧑‍💻 Stub CardReader, proper methods

This commit is contained in:
Scott Lahteine 2025-04-21 20:00:49 -05:00
parent d16667838f
commit 5c0e8d594d
31 changed files with 85 additions and 106 deletions

View file

@ -19,7 +19,7 @@ void sd_mmc_spi_mem_init() {
}
inline bool media_ready() {
return IS_SD_MOUNTED() && IS_SD_INSERTED() && !IS_SD_FILE_OPEN() && !IS_SD_PRINTING();
return card.isMounted() && card.isInserted() && !card.isFileOpen() && !card.isStillPrinting();
}
bool sd_mmc_spi_unload(bool) { return true; }

View file

@ -175,11 +175,11 @@ void MarlinHAL::idletask() {
#if HAS_SHARED_MEDIA
// If Marlin is using the SD card we need to lock it to prevent access from
// a PC via USB.
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
// Other HALs use card.isStillPrinting() and card.isFileOpen() to check for access but
// this will not reliably detect delete operations. To be safe we will lock
// the disk if Marlin has it mounted. Unfortunately there is currently no way
// to unmount the disk from the LCD menu.
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
// if (card.isStillPrinting() || card.isFileOpen())
if (card.isMounted())
MSC_Aquire_Lock();
else

View file

@ -264,7 +264,7 @@ void MarlinHAL::idletask() {
/**
* When Marlin is using the SD card it should be locked to prevent it being
* accessed from a PC over USB.
* Other HALs use (IS_SD_PRINTING() || IS_SD_FILE_OPEN()) to check for access
* Other HALs use (card.isStillPrinting() || card.isFileOpen()) to check for access
* but this won't reliably detect other file operations. To be safe we just lock
* the drive whenever Marlin has it mounted. LCDs should include an Unmount
* command so drives can be released as needed.

View file

@ -269,6 +269,10 @@
#include "feature/rs485.h"
#endif
#if !HAS_MEDIA
CardReader card; // Stub instance with "no media" methods
#endif
PGMSTR(M112_KILL_STR, "M112 Shutdown");
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
@ -339,7 +343,7 @@ bool printer_busy() {
/**
* A Print Job exists when the timer is running or SD is printing
*/
bool printJobOngoing() { return print_job_timer.isRunning() || IS_SD_PRINTING(); }
bool printJobOngoing() { return print_job_timer.isRunning() || card.isStillPrinting(); }
/**
* Printing is active when a job is underway but not paused
@ -350,7 +354,7 @@ bool printingIsActive() { return !did_pause_print && printJobOngoing(); }
* Printing is paused according to SD or host indicators
*/
bool printingIsPaused() {
return did_pause_print || print_job_timer.isPaused() || IS_SD_PAUSED();
return did_pause_print || print_job_timer.isPaused() || card.isPaused();
}
void startOrResumeJob() {
@ -509,7 +513,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
// Handle a standalone HOME button
constexpr millis_t HOME_DEBOUNCE_DELAY = 1000UL;
static millis_t next_home_key_ms; // = 0
if (!IS_SD_PRINTING() && !READ(HOME_PIN)) { // HOME_PIN goes LOW when pressed
if (!card.isStillPrinting() && !READ(HOME_PIN)) { // HOME_PIN goes LOW when pressed
if (ELAPSED(ms, next_home_key_ms)) {
next_home_key_ms = ms + HOME_DEBOUNCE_DELAY;
LCD_MESSAGE(MSG_AUTO_HOME);
@ -804,7 +808,7 @@ void idle(const bool no_stepper_sleep/*=false*/) {
// Handle Power-Loss Recovery
#if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
if (IS_SD_PRINTING()) recovery.outage();
if (card.isStillPrinting()) recovery.outage();
#endif
// Run StallGuard endstop checks

View file

@ -456,7 +456,7 @@ namespace MMU3 {
if (slot != extruder) {
if (
//findaDetectsFilament()
//!IS_SD_PRINTING() && !usb_timer.running()
//!card.isStillPrinting() && !usb_timer.running()
!marlin_printingIsActive()
) {
// If Tcodes are used manually through the serial

View file

@ -439,7 +439,7 @@ bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool
// Pause the print job and timer
#if HAS_MEDIA
const bool was_sd_printing = IS_SD_PRINTING();
const bool was_sd_printing = card.isStillPrinting();
if (was_sd_printing) {
card.pauseSDPrint();
++did_pause_print; // Indicate SD pause also

View file

@ -117,7 +117,7 @@ void PrintJobRecovery::enable(const bool onoff) {
void PrintJobRecovery::changed() {
if (!enabled)
purge();
else if (IS_SD_PRINTING())
else if (card.isStillPrinting())
save(true);
TERN_(EXTENSIBLE_UI, ExtUI::onSetPowerLoss(enabled));
}
@ -174,7 +174,7 @@ void PrintJobRecovery::prepare() {
*/
void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POWER_LOSS_ZRAISE*/, const bool raised/*=false*/) {
// We don't check IS_SD_PRINTING here so a save may occur during a pause
// We don't check isStillPrinting here so a save may occur during a pause
#if SAVE_INFO_INTERVAL_MS > 0
static millis_t next_save_ms; // = 0
@ -202,7 +202,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
// Set Head and Foot to matching non-zero values
if (!++info.valid_head) ++info.valid_head; // non-zero in sequence
//if (!IS_SD_PRINTING()) info.valid_head = 0;
//if (!card.isStillPrinting()) info.valid_head = 0;
info.valid_foot = info.valid_head;
// Machine state
@ -326,7 +326,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
// Save the current position, distance that Z was (or should be) raised,
// and a flag whether the raise was already done here.
if (IS_SD_PRINTING()) save(true, zraise, ENABLED(BACKUP_POWER_SUPPLY));
if (card.isStillPrinting()) save(true, zraise, ENABLED(BACKUP_POWER_SUPPLY));
// Tell the LCD about the outage, even though it is about to die
TERN_(EXTENSIBLE_UI, ExtUI::onPowerLoss());

View file

@ -88,7 +88,7 @@ void GcodeSuite::M125() {
park_point += hotend_offset[active_extruder];
#endif
const bool sd_printing = IS_SD_PRINTING();
const bool sd_printing = card.isStillPrinting();
ui.pause_show_message(PAUSE_MESSAGE_PARKING, PAUSE_MODE_PAUSE_PRINT);

View file

@ -196,7 +196,7 @@ void GcodeSuite::get_destination_from_command() {
#if ENABLED(POWER_LOSS_RECOVERY) && !PIN_EXISTS(POWER_LOSS)
// Only update power loss recovery on moves with E
if (recovery.enabled && IS_SD_PRINTING() && seen.e && (seen.x || seen.y))
if (recovery.enabled && card.isStillPrinting() && seen.e && (seen.x || seen.y))
recovery.save();
#endif

View file

@ -62,7 +62,7 @@ void GcodeSuite::M73() {
#endif
#if ENABLED(M73_REPORT)
if (TERN1(M73_REPORT_SD_ONLY, IS_SD_PRINTING())) {
if (TERN1(M73_REPORT_SD_ONLY, card.isStillPrinting())) {
SERIAL_ECHO_START();
SERIAL_ECHOPGM(" M73");
#if ENABLED(SET_PROGRESS_PERCENT)

View file

@ -570,7 +570,7 @@ void GCodeQueue::get_serial_commands() {
static uint8_t sd_input_state = PS_NORMAL;
// Get commands if there are more in the file
if (!IS_SD_FETCHING()) return;
if (!card.isStillFetching()) return;
int sd_count = 0;
while (!ring_buffer.full() && !card.eof()) {

View file

@ -49,7 +49,7 @@ void GcodeSuite::M21() {
* M22: Release SD Card
*/
void GcodeSuite::M22() {
if (!IS_SD_PRINTING()) card.release();
if (!card.isStillPrinting()) card.release();
}
#endif // HAS_MEDIA

View file

@ -101,7 +101,7 @@ void GcodeSuite::M25() {
#else
// Set initial pause flag to prevent more commands from landing in the queue while we try to pause
if (IS_SD_PRINTING()) card.pauseSDPrint();
if (card.isStillPrinting()) card.pauseSDPrint();
#if ENABLED(POWER_LOSS_RECOVERY) && DISABLED(DGUS_LCD_UI_MKS)
if (recovery.enabled) recovery.save(true);

View file

@ -40,7 +40,7 @@
* M32 S60 !PATH/TO/FILE.GCO# ; Start FILE.GCO at byte 60
*/
void GcodeSuite::M32() {
if (IS_SD_PRINTING()) planner.synchronize();
if (card.isStillPrinting()) planner.synchronize();
if (card.isMounted()) {
const uint8_t call_procedure = parser.boolval('P');

View file

@ -42,7 +42,7 @@ void GcodeSuite::M524() {
#else
if (IS_SD_PRINTING())
if (card.isStillPrinting())
card.abortFilePrintSoon();
else if (card.isMounted())
card.closefile();

View file

@ -43,7 +43,7 @@ void GcodeSuite::M75() {
startOrResumeJob(); // ... ExtUI::onPrintTimerStarted()
#if ENABLED(DWIN_LCD_PROUI)
// TODO: Remove if M75 <string> is never used
if (!IS_SD_PRINTING()) dwinPrintHeader(parser.has_string() ? parser.string_arg : GET_TEXT(MSG_HOST_START_PRINT));
if (!card.isStillPrinting()) dwinPrintHeader(parser.has_string() ? parser.string_arg : GET_TEXT(MSG_HOST_START_PRINT));
#endif
}

View file

@ -841,7 +841,7 @@ void MarlinUI::draw_status_message(const bool blink) {
const uint8_t progress = get_progress_percent();
if (progress) {
lcd_moveto(pc, pr);
lcd_put_u8str(F(TERN(IS_SD_PRINTING, "SD", "P:")));
lcd_put_u8str(card.isStillPrinting() ? F("SD") : F("P:"));
lcd_put_u8str(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(get_progress_permyriad()), ui8tostr3rj(progress)));
lcd_put_u8str(F("%"));
}

View file

@ -603,7 +603,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
const uint8_t progress = ui.get_progress_percent();
if (progress) {
lcd_moveto(0, 2);
lcd_put_u8str(F(TERN(IS_SD_PRINTING, "SD", "P:")));
lcd_put_u8str(card.isStillPrinting() ? F("SD") : F("P:"));
lcd.print(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress)));
lcd.write('%');
}

View file

@ -4653,7 +4653,7 @@ void JyersDWIN::popupControl() {
#if ENABLED(PARK_HEAD_ON_PAUSE)
popupHandler(Popup_Home, true);
#if HAS_MEDIA
if (IS_SD_PRINTING()) card.pauseSDPrint();
if (card.isStillPrinting()) card.pauseSDPrint();
#endif
planner.synchronize();
queue.inject(F("M125"));

View file

@ -294,9 +294,9 @@ MenuItem *fanSpeedItem = nullptr;
MenuItem *mMeshMoveZItem = nullptr;
MenuItem *editZValueItem = nullptr;
bool isPrinting() { return printingIsActive() || printingIsPaused(); }
bool sdPrinting() { return isPrinting() && IS_SD_FILE_OPEN(); }
bool hostPrinting() { return isPrinting() && !IS_SD_FILE_OPEN(); }
bool isPrinting() { return printingIsActive() || printingIsPaused(); }
bool sdPrinting() { return isPrinting() && card.isStillPrinting(); }
bool hostPrinting() { return isPrinting() && !card.isStillPrinting(); }
#define DWIN_LANGUAGE_EEPROM_ADDRESS 0x01 // Between 0x01 and 0x63 (EEPROM_OFFSET-1)
// BL24CXX::check() uses 0x00

View file

@ -62,11 +62,11 @@ void AboutScreen::onRedraw(draw_mode_t) {
#ifdef LULZBOT_LCD_MACHINE_NAME
cmd.tag(3);
draw_text_box(cmd, BTN_POS(1,7), BTN_SIZE(4,3), F(
"Firmware:"
"Firmware:"
), OPT_CENTER, font_xlarge);
draw_text_box(cmd, BTN_POS(1,10), BTN_SIZE(4,2), F(
"" LULZBOT_M115_EXTRUDER_TYPE ""
"" LULZBOT_M115_EXTRUDER_TYPE ""
), OPT_CENTER, font_xlarge);
#endif
@ -77,7 +77,7 @@ void AboutScreen::onRedraw(draw_mode_t) {
#endif
draw_text_box(cmd, BTN_POS(1,19), BTN_SIZE(4,3), F(
"Version:"
"Version:"
), OPT_CENTER, font_xlarge);
draw_text_box(cmd, BTN_POS(1,22), BTN_SIZE(4,2), F(

View file

@ -1332,19 +1332,6 @@ void lv_screen_menu_item_onoff_update(lv_obj_t *btn, const bool curValue) {
lv_label_set_text((lv_obj_t*)btn->child_ll.head, curValue ? machine_menu.enable : machine_menu.disable);
}
#if HAS_MEDIA
void sd_detection() {
static bool last_sd_status;
const bool sd_status = IS_SD_INSERTED();
if (sd_status != last_sd_status) {
last_sd_status = sd_status;
if (sd_status) card.mount(); else card.release();
}
}
#endif
void lv_ex_line(lv_obj_t *line, lv_point_t *points) {
// Copy the previous line and apply the new style
lv_line_set_points(line, points, 2); // Set the points

View file

@ -468,7 +468,6 @@ void GUI_RefreshPage();
void clear_cur_ui();
void draw_return_ui();
void goto_previous_ui();
void sd_detection();
void gCfg_to_spiFlah();
void print_time_count();

View file

@ -88,7 +88,7 @@ void printer_state_polling() {
}
if (uiCfg.print_state == RESUMING) {
if (IS_SD_PAUSED()) {
if (card.isPaused()) {
if (gCfgItems.pausePosX != (float)-1 && gCfgItems.pausePosY != (float)-1) {
sprintf_P(public_buf_m, PSTR("G1 X%s Y%s"), dtostrf(uiCfg.current_x_position_bak, 1, 1, str_1), dtostrf(uiCfg.current_y_position_bak, 1, 1, str_1));
gcode.process_subcommands_now(public_buf_m);

View file

@ -136,7 +136,7 @@ void tft_lvgl_init() {
#if HAS_USB_FLASH_DRIVE
#if HAS_MULTI_VOLUME && !HAS_SD_HOST_DRIVE
if (IS_SD_INSERTED())
if (card.isSDCardInserted())
card.selectMediaSDCard();
else
card.selectMediaFlashDrive();

View file

@ -1064,11 +1064,8 @@ namespace ExtUI {
TERN(HAS_MEDIA, card.openAndPrintFile(filename), UNUSED(filename));
}
bool isPrintingFromMediaPaused() {
return IS_SD_PAUSED();
}
bool isPrintingFromMedia() { return IS_SD_PRINTING() || IS_SD_PAUSED(); }
bool isPrintingFromMedia() { return card.isStillPrinting() || card.isPaused(); }
bool isPrintingFromMediaPaused() { return card.isPaused(); }
bool isPrinting() {
return commandsInQueue() || isPrintingFromMedia() || printJobOngoing() || printingIsPaused();

View file

@ -1540,7 +1540,7 @@ uint8_t expand_u8str_P(char * const outstr, PGM_P const ptpl, const int8_t ind,
if (printingIsPaused())
msg = GET_TEXT_F(MSG_PRINT_PAUSED);
#if HAS_MEDIA
else if (IS_SD_PRINTING())
else if (card.isStillPrinting())
return set_status_no_expire(card.longest_filename());
#endif
else if (print_job_timer.isRunning())
@ -1743,7 +1743,7 @@ uint8_t expand_u8str_P(char * const outstr, PGM_P const ptpl, const int8_t ind,
void MarlinUI::abort_print() {
#if HAS_MEDIA
wait_for_heatup = wait_for_user = false;
if (IS_SD_PRINTING())
if (card.isStillPrinting())
card.abortFilePrintSoon();
else if (card.isMounted())
card.closefile();
@ -1810,7 +1810,7 @@ uint8_t expand_u8str_P(char * const outstr, PGM_P const ptpl, const int8_t ind,
void MarlinUI::resume_print() {
reset_status();
TERN_(PARK_HEAD_ON_PAUSE, wait_for_heatup = wait_for_user = false);
TERN_(HAS_MEDIA, if (IS_SD_PAUSED()) queue.inject_P(M24_STR));
TERN_(HAS_MEDIA, if (card.isPaused()) queue.inject_P(M24_STR));
#ifdef ACTION_ON_RESUME
hostui.resume();
#endif

View file

@ -171,7 +171,7 @@ void RTS::sdCardInit() {
// Clear the file name displayed in the print interface
sendData(0, PRINT_FILE_TEXT_VP + j);
}
lcd_sd_status = IS_SD_INSERTED();
lcd_sd_status = card.isInserted();
}
else {
// Clean all filename Icons
@ -186,7 +186,7 @@ bool RTS::sdDetected() {
static bool state = false, stable = false, was_present = false;
static millis_t stable_ms = 0;
const bool present = IS_SD_INSERTED();
const bool present = card.isInserted();
if (present != was_present)
stable = false;
else if (!stable) {
@ -1485,7 +1485,7 @@ void RTS::handleData() {
sendData(cardRec.display_filename[cardRec.recordcount], PRINT_FILE_TEXT_VP);
// Represents to update file list
if (update_sd && lcd_sd_status && IS_SD_INSERTED()) {
if (update_sd && lcd_sd_status && card.isInserted()) {
for (uint16_t i = 0; i < cardRec.Filesum; i++) {
delay(3);
sendData(cardRec.display_filename[i], cardRec.addr[i]);
@ -1654,8 +1654,8 @@ void RTS_Update() {
// Check the status of card
rts.sdCardUpdate();
sd_printing = IS_SD_PRINTING();
card_insert_st = IS_SD_INSERTED();
sd_printing = card.isStillPrinting();
card_insert_st = card.isInserted();
if (!card_insert_st && sd_printing) {
rts.gotoPage(ID_MediaFail_L, ID_MediaFail_D);

View file

@ -4772,7 +4772,7 @@ void Temperature::isr() {
dwin_heat_time = elapsed.value;
#elif ENABLED(SOVOL_SV06_RTS)
update_time_value = RTS_UPDATE_VALUE;
if (IS_SD_PRINTING()) rts.refreshTime();
if (card.isStillPrinting()) rts.refreshTime();
rts.start_print_flag = false;
#else
ui.reset_status();

View file

@ -146,7 +146,7 @@ int16_t CardReader::nrItems = -1;
DiskIODriver* CardReader::driver = nullptr;
MarlinVolume CardReader::volume;
MediaFile CardReader::file;
MediaFile CardReader::myfile;
#if HAS_MEDIA_SUBCALLS
uint8_t CardReader::file_subcall_ctr;
@ -463,9 +463,9 @@ void CardReader::ls(const uint8_t lsflags/*=0*/) {
// Echo the DOS 8.3 filename (and long filename, if any)
//
void CardReader::printSelectedFilename() {
if (file.isOpen()) {
if (myfile.isOpen()) {
char dosFilename[FILENAME_LENGTH];
file.getDosName(dosFilename);
myfile.getDosName(dosFilename);
SERIAL_ECHO(dosFilename);
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
selectFileByName(dosFilename);
@ -517,7 +517,7 @@ void CardReader::mount() {
*/
void CardReader::manage_media() {
static uint8_t prev_stat = 2; // At boot we don't know if media is present or not
uint8_t stat = uint8_t(IS_SD_INSERTED());
uint8_t stat = uint8_t(isInserted());
if (stat == prev_stat) return; // Already checked and still no change?
DEBUG_SECTION(cmm, "CardReader::manage_media()", true);
@ -626,7 +626,7 @@ void CardReader::endFilePrintNow(TERN_(SD_RESORT, const bool re_sort/*=false*/))
TERN_(ADVANCED_PAUSE_FEATURE, did_pause_print = 0);
TERN_(DWIN_CREALITY_LCD, hmiFlag.print_finish = flag.sdprinting);
flag.abort_sd_printing = false;
if (isFileOpen()) file.close();
if (isFileOpen()) myfile.close();
TERN_(SD_RESORT, if (re_sort) presort());
}
@ -661,7 +661,7 @@ void CardReader::getAbsFilenameInCWD(char *dst) {
appendAtom(workDirParents[i]);
if (cnt < MAXPATHNAMELENGTH - (FILENAME_LENGTH) - 1) { // Leave room for filename and nul
appendAtom(file);
appendAtom(myfile);
--dst;
}
*dst = '\0';
@ -738,8 +738,8 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ
const char * const fname = diveToFile(true, diveDir, path);
if (!fname) return openFailed(path);
if (file.open(diveDir, fname, O_READ)) {
filesize = file.fileSize();
if (myfile.open(diveDir, fname, O_READ)) {
filesize = myfile.fileSize();
sdpos = 0;
{ // Don't remove this block, as the PORT_REDIRECT is a RAII
@ -778,7 +778,7 @@ void CardReader::openFileWrite(const char * const path) {
if (!fname) return openFailed(path);
#if DISABLED(SDCARD_READONLY)
if (file.open(diveDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) {
if (myfile.open(diveDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) {
flag.saving = true;
selectFileByName(fname);
TERN_(EMERGENCY_PARSER, emergency_parser.disable());
@ -832,7 +832,7 @@ void CardReader::removeFile(const char * const name) {
#if ENABLED(SDCARD_READONLY)
SERIAL_ECHOLNPGM("Deletion failed (read-only), File: ", fname, ".");
#else
if (file.remove(itsDirPtr, fname)) {
if (myfile.remove(itsDirPtr, fname)) {
SERIAL_ECHOLNPGM("File deleted:", fname);
sdpos = 0;
TERN_(SDCARD_SORT_ALPHA, presort());
@ -866,7 +866,7 @@ void CardReader::write_command(char * const buf) {
*npos = nullptr,
*end = buf + strlen(buf) - 1;
file.writeError = false;
myfile.writeError = false;
if ((npos = strchr(buf, 'N'))) {
begin = strchr(npos, ' ') + 1;
end = strchr(npos, '*') - 1;
@ -874,9 +874,9 @@ void CardReader::write_command(char * const buf) {
end[1] = '\r';
end[2] = '\n';
end[3] = '\0';
file.write(begin);
myfile.write(begin);
if (file.writeError) SERIAL_ERROR_MSG(STR_SD_ERR_WRITE_TO_FILE);
if (myfile.writeError) SERIAL_ERROR_MSG(STR_SD_ERR_WRITE_TO_FILE);
}
#if DISABLED(NO_SD_AUTOSTART)
@ -1001,8 +1001,8 @@ void CardReader::write_command(char * const buf) {
// Close the working file.
//
void CardReader::closefile(const bool store_location/*=false*/) {
file.sync();
file.close();
myfile.sync();
myfile.close();
flag.saving = flag.logging = false;
sdpos = 0;
@ -1441,7 +1441,7 @@ int16_t CardReader::get_num_items() {
// Return from procedure or close out the Print Job.
//
void CardReader::fileHasFinished() {
file.close();
myfile.close();
#if HAS_MEDIA_SUBCALLS
if (file_subcall_ctr > 0) { // Resume calling file after closing procedure

View file

@ -230,6 +230,7 @@ public:
static void pauseSDPrint() { flag.sdprinting = false; }
static bool isPrinting() { return flag.sdprinting; }
static bool isStillPrinting() { return flag.sdprinting && !flag.abort_sd_printing; }
static bool isStillFetching() { return isStillPrinting() && !flag.sdprintdone; }
static bool isPaused() { return isFileOpen() && !isPrinting(); }
#if HAS_PRINT_PROGRESS_PERMYRIAD
static uint16_t permyriadDone() {
@ -289,14 +290,14 @@ public:
// Print File stats
static uint32_t getFileSize() { return filesize; }
static uint32_t getIndex() { return sdpos; }
static bool isFileOpen() { return isMounted() && file.isOpen(); }
static bool isFileOpen() { return isMounted() && myfile.isOpen(); }
static bool eof() { return getIndex() >= getFileSize(); }
// File data operations
static int16_t get() { int16_t out = (int16_t)file.read(); sdpos = file.curPosition(); return out; }
static int16_t read(void *buf, uint16_t nbyte) { return file.isOpen() ? file.read(buf, nbyte) : -1; }
static int16_t write(void *buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; }
static void setIndex(const uint32_t index) { file.seekSet((sdpos = index)); }
static int16_t get() { int16_t out = (int16_t)myfile.read(); sdpos = myfile.curPosition(); return out; }
static int16_t read(void *buf, uint16_t nbyte) { return myfile.isOpen() ? myfile.read(buf, nbyte) : -1; }
static int16_t write(void *buf, uint16_t nbyte) { return myfile.isOpen() ? myfile.write(buf, nbyte) : -1; }
static void setIndex(const uint32_t index) { myfile.seekSet((sdpos = index)); }
#if ENABLED(AUTO_REPORT_SD_STATUS)
//
@ -313,7 +314,7 @@ private:
static DiskIODriver *driver;
static MarlinVolume volume;
static MediaFile file;
static MediaFile myfile;
static uint32_t filesize, // Total size of the current file, in bytes
sdpos; // Index most recently read (one behind file.getPos)
@ -405,31 +406,22 @@ private:
#endif
};
#if HAS_USB_FLASH_DRIVE
#define IS_SD_INSERTED() DiskIODriver_USBFlash::isInserted()
#elif HAS_SD_DETECT
#define IS_SD_INSERTED() (READ(SD_DETECT_PIN) == SD_DETECT_STATE)
#else
// No card detect line? Assume the card is inserted.
#define IS_SD_INSERTED() true
#endif
#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
#define IS_SD_FILE_OPEN() false
class CardReader {
public:
static constexpr bool isFlashDriveInserted() { return false; }
static constexpr bool isSDCardInserted() { return false; }
static constexpr bool isInserted() { return false; }
static constexpr bool isMounted() { return false; }
static constexpr bool isStillPrinting() { return false; }
static constexpr bool isStillFetching() { return false; }
static constexpr bool isPaused() { return false; }
static constexpr bool isFileOpen() { return false; }
};
#define LONG_FILENAME_LENGTH 0
#endif // !HAS_MEDIA
extern CardReader card;