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

gcode: Add gcode M27 auto report support #3739

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions lib/Marlin/Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@

enum AxisRelative : uint8_t { REL_X, REL_Y, REL_Z, REL_E, E_MODE_ABS, E_MODE_REL };

#if ENABLED(SDSUPPORT) || ENABLED(SDCARD_GCODES)
namespace M27_handler {
extern uint32_t sd_auto_report_delay;
void print_sd_status();
} // namespace M27_handler
#endif

class GcodeSuite {
public:

Expand Down
13 changes: 13 additions & 0 deletions src/common/marlin_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,15 @@ void safely_unload_filament_from_nozzle_to_mmu() {
}
#endif

void print_sd_report() {
static uint32_t last_sd_report = 0;
uint32_t current_time = ticks_s();
if (M27_handler::sd_auto_report_delay && (current_time - last_sd_report) >= M27_handler::sd_auto_report_delay) {
M27_handler::print_sd_status();
last_sd_report = current_time;
}
}

#ifdef MINDA_BROKEN_CABLE_DETECTION
static void print_Z_probe_cnt() {
if (DEBUGGING(INFO)) {
Expand Down Expand Up @@ -641,6 +650,10 @@ static void cycle() {

print_fan_spd();

#if ENABLED(SDSUPPORT) || ENABLED(SDCARD_GCODES)
print_sd_report();
#endif

#ifdef MINDA_BROKEN_CABLE_DETECTION
print_Z_probe_cnt();
#endif
Expand Down
24 changes: 16 additions & 8 deletions src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ void GcodeSuite::M26() {
}
}

uint32_t M27_handler::sd_auto_report_delay = 0;

void M27_handler::print_sd_status() {
if (media_print_get_state() != media_print_state_NONE) {
SERIAL_ECHOPGM(MSG_SD_PRINTING_BYTE);
SERIAL_ECHO(media_print_get_position());
SERIAL_CHAR('/');
SERIAL_ECHOLN(media_print_get_size());
} else {
SERIAL_ECHOLNPGM(MSG_SD_NOT_PRINTING);
}
}

/**
* M27 - Report SD print status on serial port
*
Expand All @@ -93,15 +106,10 @@ void GcodeSuite::M27() {
if (parser.seen('C')) {
SERIAL_ECHOPGM("Current file: ");
SERIAL_ECHOLN(marlin_vars()->media_SFN_path.get_ptr());
} else if (parser.seen('S')) {
M27_handler::sd_auto_report_delay = parser.byteval('S');
} else {
if (media_print_get_state() != media_print_state_NONE) {
SERIAL_ECHOPGM(MSG_SD_PRINTING_BYTE);
SERIAL_ECHO(media_print_get_position());
SERIAL_CHAR('/');
SERIAL_ECHOLN(media_print_get_size());
} else {
SERIAL_ECHOLNPGM(MSG_SD_NOT_PRINTING);
}
M27_handler::print_sd_status();
}
}

Expand Down