gcode: Add serial information for M862.x for P and Q parameters#4777
gcode: Add serial information for M862.x for P and Q parameters#4777bkerler wants to merge 5 commits intoprusa3d:masterfrom
Conversation
70369de to
3b6daf7
Compare
a3ea7f4 to
55acc03
Compare
26a748c to
cc2ffeb
Compare
cc2ffeb to
2fdd7f0
Compare
CZDanol
left a comment
There was a problem hiding this comment.
Still not a full review, sorry, not much time and this PR is on the bigger side.
Besides from nitpick/comments in the review, there is also a higher-level problem that we're duplicating here what GCodeInfo does. And GCodeInfo does it in a completely different way, so we could end up with a situation where the gcode outputs are telling us one thing and the GCodeInfo is reporting something else.
The way things are implemented in GCodeInfo currently is terrible, because it basically parses the gcodes "by hand". But to allow this extension of the gcodes, we might first need to clean up the GCodeInfo to make things consistent (which would be a big task).
I am not sure.
src/marlin_stubs/M862_2_3.cpp
Outdated
| if (compatibility.is_compatible) { | ||
| SERIAL_ECHO("Compatibility mode: "); | ||
| if (compatibility.mk3_compatibility_mode) { | ||
| SERIAL_ECHOLN("MK3"); |
There was a problem hiding this comment.
I feel like by putting this on separate lines, these will be rather hard to parse by a machine
src/marlin_stubs/M862_2_3.cpp
Outdated
| return; | ||
| } | ||
|
|
||
| if (p.option<bool>('Q').value_or(false)) { |
There was a problem hiding this comment.
Nitpick/tip: == true would work as well (but value_or is also fine)
src/marlin_stubs/M862_2_3.cpp
Outdated
|
|
||
| if (parser.boolval('P')) { | ||
| setup_gcode_compatibility(PrinterModelInfo::from_gcode_check_code(parser.value_int())); | ||
| if (const auto gcode = p.option<int>('P').value_or(0)) { |
There was a problem hiding this comment.
Here, value_or is not fine. Technically speaking, 0 could also be a valid printer model. The point of the parser returning std::optional is to avoid these double meanings.
if (const auto gcode = p.option<int>('P')) {
print_compatibility(setup_gcode_compatibility(PrinterModelInfo::from_gcode_check_code(*gcode)));
}
There was a problem hiding this comment.
Changed that as well, good point.
src/marlin_stubs/M862_2_3.cpp
Outdated
|
|
||
| setup_gcode_compatibility(PrinterModelInfo::from_id_str(std::string_view(arg, arg_end))); | ||
| std::array<char, 64> id_str; | ||
| if (const auto opt = p.option<std::string_view>('P', id_str)) { |
src/marlin_stubs/M862_2_3.cpp
Outdated
| setup_gcode_compatibility(PrinterModelInfo::from_id_str(std::string_view(arg, arg_end))); | ||
| std::array<char, 64> id_str; | ||
| if (const auto opt = p.option<std::string_view>('P', id_str)) { | ||
| print_compatibility(setup_gcode_compatibility(PrinterModelInfo::from_id_str(opt->data()))); |
There was a problem hiding this comment.
std::string_view does not guarantee null termination, you cannot just pass the data from it.
from_id_str already takes std::string_view, so there is no need to take the const char* pointer from the view and cast it back to std::string_view. You can just do print_compatibility(setup_gcode_compatibility(PrinterModelInfo::from_id_str(*opt))));
src/marlin_stubs/M862_6.cpp
Outdated
| found = true; | ||
| break; | ||
| } | ||
| #if ENABLED(PRUSA_MMU2) |
There was a problem hiding this comment.
Yep, sorry, this is way too much code duplication. This MMU3/Phase stepping conditioning should all be implemented on a single place.
src/marlin_stubs/M862_6.cpp
Outdated
| bool found = false; | ||
| SERIAL_ECHOPAIR("\"", opt->data(), "\""); | ||
| for (auto &feature : GCodeInfo::supported_features) { | ||
| if (opt->find(feature) != std::string_view::npos) { |
There was a problem hiding this comment.
Find? Find is finding a substring. The match should either be 1:1 or there should be some clearly documented separators.
src/marlin_stubs/M862_1.cpp
Outdated
| } | ||
|
|
||
| if (const std::optional<double> requested_nozzle_diameter = p.option<float>('P')) { | ||
| if (requested_nozzle_diameter.value() < 0) { |
There was a problem hiding this comment.
This can be auto-checked by passing a min value to p.option. Also, what is the point of even checking this? If the user enters a negative value, he would get a mismatch anyway.
There was a problem hiding this comment.
Done, you're right, negative testing doesn't make sense as we force it to be bigger than 0.1
src/marlin_stubs/M862_5.cpp
Outdated
| SERIAL_EOL(); | ||
| } | ||
|
|
||
| if (const std::optional<int> req_gcode_level = p.option<int>('P')) { |
There was a problem hiding this comment.
nitpick: auto would be nicer
src/marlin_stubs/M862_5.cpp
Outdated
|
|
||
| if (const std::optional<int> req_gcode_level = p.option<int>('P')) { | ||
| SERIAL_ECHO("Gcode level "); | ||
| if (req_gcode_level == (int)GCodeInfo::gcode_level) { |
There was a problem hiding this comment.
Nitpick: Why cast to int here? Would it be better to take the P option as the same type as gcode_level?
39b9106 to
f7583f2
Compare
|
I think you are right regarding the redesign and also not happy about the way the mmu3 and feature output/check is happening in M862_6. In order to allow the other fixes to happen, I decided that M862_6 isn't put in this PR, but instead in a separate PR (either with proper changes or after full gcodeinfo patches happened). |
f7583f2 to
c5422d5
Compare
This partly solves #4157.
M862.3 P "MK3S"andM862.3 P"MK3S"both should work, but didn't. This behaviour was fixed as well.