Skip to content

Commit 5c0e8d5

Browse files
committed
πŸ§‘β€πŸ’» Stub CardReader, proper methods
1 parent d166678 commit 5c0e8d5

File tree

31 files changed

+85
-106
lines changed

31 files changed

+85
-106
lines changed

β€ŽMarlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void sd_mmc_spi_mem_init() {
1919
}
2020

2121
inline bool media_ready() {
22-
return IS_SD_MOUNTED() && IS_SD_INSERTED() && !IS_SD_FILE_OPEN() && !IS_SD_PRINTING();
22+
return card.isMounted() && card.isInserted() && !card.isFileOpen() && !card.isStillPrinting();
2323
}
2424

2525
bool sd_mmc_spi_unload(bool) { return true; }

β€ŽMarlin/src/HAL/LPC1768/HAL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ void MarlinHAL::idletask() {
175175
#if HAS_SHARED_MEDIA
176176
// If Marlin is using the SD card we need to lock it to prevent access from
177177
// a PC via USB.
178-
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
178+
// Other HALs use card.isStillPrinting() and card.isFileOpen() to check for access but
179179
// this will not reliably detect delete operations. To be safe we will lock
180180
// the disk if Marlin has it mounted. Unfortunately there is currently no way
181181
// to unmount the disk from the LCD menu.
182-
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
182+
// if (card.isStillPrinting() || card.isFileOpen())
183183
if (card.isMounted())
184184
MSC_Aquire_Lock();
185185
else

β€ŽMarlin/src/HAL/STM32F1/HAL.cpp

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

β€ŽMarlin/src/MarlinCore.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@
269269
#include "feature/rs485.h"
270270
#endif
271271

272+
#if !HAS_MEDIA
273+
CardReader card; // Stub instance with "no media" methods
274+
#endif
275+
272276
PGMSTR(M112_KILL_STR, "M112 Shutdown");
273277

274278
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
@@ -339,7 +343,7 @@ bool printer_busy() {
339343
/**
340344
* A Print Job exists when the timer is running or SD is printing
341345
*/
342-
bool printJobOngoing() { return print_job_timer.isRunning() || IS_SD_PRINTING(); }
346+
bool printJobOngoing() { return print_job_timer.isRunning() || card.isStillPrinting(); }
343347

344348
/**
345349
* Printing is active when a job is underway but not paused
@@ -350,7 +354,7 @@ bool printingIsActive() { return !did_pause_print && printJobOngoing(); }
350354
* Printing is paused according to SD or host indicators
351355
*/
352356
bool printingIsPaused() {
353-
return did_pause_print || print_job_timer.isPaused() || IS_SD_PAUSED();
357+
return did_pause_print || print_job_timer.isPaused() || card.isPaused();
354358
}
355359

356360
void startOrResumeJob() {
@@ -509,7 +513,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
509513
// Handle a standalone HOME button
510514
constexpr millis_t HOME_DEBOUNCE_DELAY = 1000UL;
511515
static millis_t next_home_key_ms; // = 0
512-
if (!IS_SD_PRINTING() && !READ(HOME_PIN)) { // HOME_PIN goes LOW when pressed
516+
if (!card.isStillPrinting() && !READ(HOME_PIN)) { // HOME_PIN goes LOW when pressed
513517
if (ELAPSED(ms, next_home_key_ms)) {
514518
next_home_key_ms = ms + HOME_DEBOUNCE_DELAY;
515519
LCD_MESSAGE(MSG_AUTO_HOME);
@@ -804,7 +808,7 @@ void idle(const bool no_stepper_sleep/*=false*/) {
804808

805809
// Handle Power-Loss Recovery
806810
#if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
807-
if (IS_SD_PRINTING()) recovery.outage();
811+
if (card.isStillPrinting()) recovery.outage();
808812
#endif
809813

810814
// Run StallGuard endstop checks

β€ŽMarlin/src/feature/mmu3/mmu3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ namespace MMU3 {
456456
if (slot != extruder) {
457457
if (
458458
//findaDetectsFilament()
459-
//!IS_SD_PRINTING() && !usb_timer.running()
459+
//!card.isStillPrinting() && !usb_timer.running()
460460
!marlin_printingIsActive()
461461
) {
462462
// If Tcodes are used manually through the serial

β€ŽMarlin/src/feature/pause.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool
439439

440440
// Pause the print job and timer
441441
#if HAS_MEDIA
442-
const bool was_sd_printing = IS_SD_PRINTING();
442+
const bool was_sd_printing = card.isStillPrinting();
443443
if (was_sd_printing) {
444444
card.pauseSDPrint();
445445
++did_pause_print; // Indicate SD pause also

β€ŽMarlin/src/feature/powerloss.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void PrintJobRecovery::enable(const bool onoff) {
117117
void PrintJobRecovery::changed() {
118118
if (!enabled)
119119
purge();
120-
else if (IS_SD_PRINTING())
120+
else if (card.isStillPrinting())
121121
save(true);
122122
TERN_(EXTENSIBLE_UI, ExtUI::onSetPowerLoss(enabled));
123123
}
@@ -174,7 +174,7 @@ void PrintJobRecovery::prepare() {
174174
*/
175175
void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POWER_LOSS_ZRAISE*/, const bool raised/*=false*/) {
176176

177-
// We don't check IS_SD_PRINTING here so a save may occur during a pause
177+
// We don't check isStillPrinting here so a save may occur during a pause
178178

179179
#if SAVE_INFO_INTERVAL_MS > 0
180180
static millis_t next_save_ms; // = 0
@@ -202,7 +202,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
202202

203203
// Set Head and Foot to matching non-zero values
204204
if (!++info.valid_head) ++info.valid_head; // non-zero in sequence
205-
//if (!IS_SD_PRINTING()) info.valid_head = 0;
205+
//if (!card.isStillPrinting()) info.valid_head = 0;
206206
info.valid_foot = info.valid_head;
207207

208208
// Machine state
@@ -326,7 +326,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
326326

327327
// Save the current position, distance that Z was (or should be) raised,
328328
// and a flag whether the raise was already done here.
329-
if (IS_SD_PRINTING()) save(true, zraise, ENABLED(BACKUP_POWER_SUPPLY));
329+
if (card.isStillPrinting()) save(true, zraise, ENABLED(BACKUP_POWER_SUPPLY));
330330

331331
// Tell the LCD about the outage, even though it is about to die
332332
TERN_(EXTENSIBLE_UI, ExtUI::onPowerLoss());

β€ŽMarlin/src/gcode/feature/pause/M125.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void GcodeSuite::M125() {
8888
park_point += hotend_offset[active_extruder];
8989
#endif
9090

91-
const bool sd_printing = IS_SD_PRINTING();
91+
const bool sd_printing = card.isStillPrinting();
9292

9393
ui.pause_show_message(PAUSE_MESSAGE_PARKING, PAUSE_MODE_PAUSE_PRINT);
9494

β€ŽMarlin/src/gcode/gcode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void GcodeSuite::get_destination_from_command() {
196196

197197
#if ENABLED(POWER_LOSS_RECOVERY) && !PIN_EXISTS(POWER_LOSS)
198198
// Only update power loss recovery on moves with E
199-
if (recovery.enabled && IS_SD_PRINTING() && seen.e && (seen.x || seen.y))
199+
if (recovery.enabled && card.isStillPrinting() && seen.e && (seen.x || seen.y))
200200
recovery.save();
201201
#endif
202202

β€ŽMarlin/src/gcode/lcd/M73.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void GcodeSuite::M73() {
6262
#endif
6363

6464
#if ENABLED(M73_REPORT)
65-
if (TERN1(M73_REPORT_SD_ONLY, IS_SD_PRINTING())) {
65+
if (TERN1(M73_REPORT_SD_ONLY, card.isStillPrinting())) {
6666
SERIAL_ECHO_START();
6767
SERIAL_ECHOPGM(" M73");
6868
#if ENABLED(SET_PROGRESS_PERCENT)

0 commit comments

Comments
Β (0)