Skip to content
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
2 changes: 1 addition & 1 deletion src/common/gcode/gcode_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GCodeInfo {
public:
static constexpr uint32_t gcode_level = GCODE_LEVEL;

static constexpr auto supported_features = std::to_array({ "Input shaper" });
static constexpr auto supported_features = std::to_array({ "Input shaper", "Phase stepping" });

// search this many g-code at the beginning of the file for the various g-codes (M862.x nozzle size, bed heating, nozzle heating)
static constexpr size_t search_first_x_gcodes = 200;
Expand Down
34 changes: 24 additions & 10 deletions src/marlin_stubs/M862_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,42 @@
* - `F` - High-Flow nozzle
*/
void PrusaGcodeSuite::M862_1() {
// Handle only Q
// P is ignored when printing (it is handled before printing by GCodeInfo.*)
if (!parser.boolval('Q')) {
return;
}

// Get for which tool
#if HAS_TOOLCHANGER()
const uint8_t default_tool = active_extruder;
#else /*HAS_TOOLCHANGER()*/
const uint8_t default_tool = 0;
#endif /*HAS_TOOLCHANGER()*/

SERIAL_ECHO_START();
uint8_t tool = parser.byteval('T', default_tool);
if (tool >= config_store_ns::max_tool_count) {
SERIAL_ECHOPAIR("Tool ", tool, " isn't available\n");
return;
}
auto nozzle_diameter = static_cast<double>(config_store().get_nozzle_diameter(tool));

// Fetch diameter from EEPROM
if (tool < config_store_ns::max_tool_count) {
SERIAL_ECHO_START();
if (parser.boolval('Q')) {
// Fetch diameter from EEPROM
ArrayStringBuilder<64> sb;
sb.append_printf(" M862.1 T%u P%.2f A%i F%i", tool, static_cast<double>(config_store().get_nozzle_diameter(tool)), config_store().nozzle_is_hardened.get().test(tool), config_store().nozzle_is_high_flow.get().test(tool));
sb.append_printf(" M862.1 T%u P%.2f A%i F%i", tool, nozzle_diameter, config_store().nozzle_is_hardened.get().test(tool), config_store().nozzle_is_high_flow.get().test(tool));
SERIAL_ECHO(sb.str());
SERIAL_EOL();
}

if (parser.floatval('P')) {
double requested_nozzle_diameter = (double)parser.floatval('P');
if (requested_nozzle_diameter < 0) {
SERIAL_ECHO("Requested nozzle diameter cannot be negative.");
} else if (requested_nozzle_diameter != nozzle_diameter) {
ArrayStringBuilder<71> sb;
sb.append_printf("Current nozzle diameter %.2f doesn't match requested diameter of %.2f.", nozzle_diameter, requested_nozzle_diameter);
SERIAL_ECHO(sb.str());
} else {
SERIAL_ECHO("Requested nozzle diameter matches current nozzle diameter.");
}
}
SERIAL_EOL();
}

/** @}*/
Expand Down
25 changes: 22 additions & 3 deletions src/marlin_stubs/M862_2_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace buddy;
static void setup_gcode_compatibility(const PrinterModelInfo *gcode_printer) {
// Failed to identify the printer -> do nothing
if (!gcode_printer) {
return;
return PrinterGCodeCompatibilityReport();
}

gcode.compatibility = PrinterModelInfo::current().gcode_compatibility_report(*gcode_printer);
Expand Down Expand Up @@ -70,6 +70,7 @@ static void setup_gcode_compatibility(const PrinterModelInfo *gcode_printer) {
chamber().set_target_temperature(params.chamber_target_temperature);
}
#endif
return compatibility;
}

/** \addtogroup G-Codes
Expand Down Expand Up @@ -103,6 +104,24 @@ static void setup_gcode_compatibility(const PrinterModelInfo *gcode_printer) {
* - `170` - XL
* - `160` - iX
*/

static void print_compatibility(PrinterGCodeCompatibilityReport compatibility) {
SERIAL_ECHO("Printer is ");
if (!compatibility.is_compatible) {
SERIAL_ECHO("in");
}
SERIAL_ECHOLN("compatible.");
if (compatibility.is_compatible) {
SERIAL_ECHO("Compatibility mode: ");
if (compatibility.mk3_compatibility_mode) {
SERIAL_ECHOLN("MK3");
}
if (compatibility.mk4s_fan_compatibility_mode) {
SERIAL_ECHOLN("MK4S_FAN");
}
}
}

void PrusaGcodeSuite::M862_2() {
// Handle only Q
// P is ignored when printing (it is handled before printing by GCodeInfo.*)
Expand All @@ -115,7 +134,7 @@ void PrusaGcodeSuite::M862_2() {
}

if (parser.boolval('P')) {
setup_gcode_compatibility(PrinterModelInfo::from_gcode_check_code(parser.value_int()));
print_compatibility(setup_gcode_compatibility(PrinterModelInfo::from_gcode_check_code(parser.value_int())));
}
}

Expand Down Expand Up @@ -168,7 +187,7 @@ void PrusaGcodeSuite::M862_3() {
arg_end++;
}

setup_gcode_compatibility(PrinterModelInfo::from_id_str(std::string_view(arg, arg_end)));
print_compatibility(setup_gcode_compatibility(PrinterModelInfo::from_id_str(std::string_view(arg, arg_end))));
}
}

Expand Down
19 changes: 13 additions & 6 deletions src/marlin_stubs/M862_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@
* - `P "<string>"` - Check current firmware version
*/
void PrusaGcodeSuite::M862_4() {
// Handle only Q
// P is ignored when printing (it is handled before printing by GCodeInfo.*)
char version_buffer[8] {};
version::fill_project_version_no_dots(version_buffer, sizeof(version_buffer));
if (parser.boolval('Q')) {
SERIAL_ECHO_START();
char temp_buf[sizeof(" M862.4 P0123456789")];
char version_buffer[8] {};
version::fill_project_version_no_dots(version_buffer, sizeof(version_buffer));
snprintf(temp_buf, sizeof(temp_buf), PSTR(" M862.4 P%s"), version_buffer);
SERIAL_ECHO(temp_buf);
SERIAL_EOL();
SERIAL_ECHOLN(temp_buf);
}
if (parser.boolval('P')) {
auto req_version = parser.value_int();
SERIAL_ECHO("Firmware version ");
if (atoi(version_buffer) == req_version) {
SERIAL_ECHO("matches");
} else {
SERIAL_ECHO("mismatch");
}
SERIAL_ECHOLN(".");
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/marlin_stubs/M862_5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* - `P` - Gcode level
*/
void PrusaGcodeSuite::M862_5() {
// Handle only Q
// P is ignored when printing (it is handled before printing by GCodeInfo.*)
if (parser.boolval('Q')) {
SERIAL_ECHO_START();
Expand All @@ -37,6 +36,15 @@ void PrusaGcodeSuite::M862_5() {
SERIAL_ECHO(temp_buf);
SERIAL_EOL();
}
if (parser.boolval('P')) {
SERIAL_ECHO("Gcode level ");
if (parser.ulongval('P') == GCodeInfo::gcode_level) {
SERIAL_ECHO("matches");
} else {
SERIAL_ECHO("mismatches");
}
SERIAL_ECHOLN(".");
}
}

/** @}*/
Expand Down
42 changes: 33 additions & 9 deletions src/marlin_stubs/M862_6.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @file
*/
#include "../common/sound.hpp"
#include "PrusaGcodeSuite.hpp"
#include "../../lib/Marlin/Marlin/src/gcode/parser.h"
#include "feature/prusa/MMU2/mmu2_mk4.h"
#include "gcode_info.hpp"

#ifdef PRINT_CHECKING_Q_CMDS
Expand All @@ -24,17 +24,41 @@
* - `Q` - Print current supported features
* - `P "<string>"` - Check for feature
*/

void PrusaGcodeSuite::M862_6() {
// Handle only Q
// P is ignored when printing (it is handled before printing by GCodeInfo.*)
std::vector<std::string_view> supported_features;
for (auto &feature : GCodeInfo::supported_features) {
supported_features.push_back(feature);
}
#if ENABLED(PRUSA_MMU2)
if (MMU2::mmu2.Enabled()) {
supported_features.push_back("MMU3");
}
#endif
if (parser.boolval('Q')) {
char temp_buf[sizeof(" M862.6 P\"01234567890123456789\"")];
for (auto &feature : GCodeInfo::supported_features) {
SERIAL_ECHO_START();
snprintf(temp_buf, sizeof(temp_buf), PSTR(" M862.6 P\"%s\""), feature);
SERIAL_ECHO(temp_buf);
SERIAL_EOL();
for (auto &feature : supported_features) {
SERIAL_ECHOLNPAIR(" M862 P\"", feature.data(), "\"");
}
}

if (parser.boolval('P')) {
char *arg = parser.string_arg + 1;
while (*arg == ' ' || *arg == '\"') {
arg++;
}

char *arg_end = arg;
while (isalnum(*arg_end) || *arg_end != '\"') {
arg_end++;
}
*arg_end = 0;

auto str_arg = std::string_view(arg, arg_end);
SERIAL_ECHOPAIR("\"", str_arg.data(), "\"");
if (!count(supported_features.begin(), supported_features.end(), str_arg)) {
SERIAL_ECHO(" NOT");
}
SERIAL_ECHOLN(" supported.");
}
}

Expand Down