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 authored and danopernis committed Aug 19, 2024
1 parent f5a498a commit 01c90c9
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 @@ -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

0 comments on commit 01c90c9

Please sign in to comment.