Skip to content

Commit

Permalink
Add gcode M27 auto report support
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler committed Feb 10, 2024
1 parent 1c6ce37 commit 729a4da
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
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 @@ -298,6 +298,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 @@ -401,6 +401,15 @@ void print_fan_spd() {
}
}

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 @@ -464,6 +473,10 @@ int cycle(void) {

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 @@ -58,20 +58,28 @@ 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
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

0 comments on commit 729a4da

Please sign in to comment.