Add G10 temperature G-code support for the RepRapFirmware flavour.
This commit is contained in:
parent
f326352ceb
commit
e275197518
2 changed files with 52 additions and 11 deletions
|
@ -1574,9 +1574,9 @@ std::string GCode::placeholder_parser_process(const std::string &name, const std
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the custom G-code, try to find mcode_set_temp_dont_wait and mcode_set_temp_and_wait inside the custom G-code.
|
// Parse the custom G-code, try to find mcode_set_temp_dont_wait and mcode_set_temp_and_wait or optionally G10 with temperature inside the custom G-code.
|
||||||
// Returns true if one of the temp commands are found, and try to parse the target temperature value into temp_out.
|
// Returns true if one of the temp commands are found, and try to parse the target temperature value into temp_out.
|
||||||
static bool custom_gcode_sets_temperature(const std::string &gcode, const int mcode_set_temp_dont_wait, const int mcode_set_temp_and_wait, int &temp_out)
|
static bool custom_gcode_sets_temperature(const std::string &gcode, const int mcode_set_temp_dont_wait, const int mcode_set_temp_and_wait, const bool include_g10, int &temp_out)
|
||||||
{
|
{
|
||||||
temp_out = -1;
|
temp_out = -1;
|
||||||
if (gcode.empty())
|
if (gcode.empty())
|
||||||
|
@ -1619,6 +1619,40 @@ static bool custom_gcode_sets_temperature(const std::string &gcode, const int mc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (*ptr == 'G' && include_g10) { // Only check for G10 if requested
|
||||||
|
// Line starts with 'G'.
|
||||||
|
++ ptr;
|
||||||
|
// Parse the G code value.
|
||||||
|
char *endptr = nullptr;
|
||||||
|
int gcode = int(strtol(ptr, &endptr, 10));
|
||||||
|
if (endptr != nullptr && endptr != ptr && gcode == 10 /* G10 */) {
|
||||||
|
// G10 code found
|
||||||
|
ptr = endptr;
|
||||||
|
// Now try to parse the temperature value.
|
||||||
|
// While not at the end of the line:
|
||||||
|
while (strchr(";\r\n\0", *ptr) == nullptr) {
|
||||||
|
// Skip whitespaces.
|
||||||
|
for (; *ptr == ' ' || *ptr == '\t'; ++ ptr);
|
||||||
|
if (*ptr == 'S') {
|
||||||
|
// Skip whitespaces.
|
||||||
|
for (++ ptr; *ptr == ' ' || *ptr == '\t'; ++ ptr);
|
||||||
|
// Parse an int.
|
||||||
|
endptr = nullptr;
|
||||||
|
long temp_parsed = strtol(ptr, &endptr, 10);
|
||||||
|
if (endptr > ptr) {
|
||||||
|
ptr = endptr;
|
||||||
|
temp_out = temp_parsed;
|
||||||
|
// Let the caller know that the custom G-code sets the temperature
|
||||||
|
// Only do this after successfully parsing temperature since G10
|
||||||
|
// can be used for other reasons
|
||||||
|
temp_set_by_gcode = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Skip this word.
|
||||||
|
for (; strchr(" \t;\r\n\0", *ptr) == nullptr; ++ ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Skip the rest of the line.
|
// Skip the rest of the line.
|
||||||
for (; *ptr != 0 && *ptr != '\r' && *ptr != '\n'; ++ ptr);
|
for (; *ptr != 0 && *ptr != '\r' && *ptr != '\n'; ++ ptr);
|
||||||
|
@ -1668,7 +1702,7 @@ void GCode::_print_first_layer_bed_temperature(FILE *file, Print &print, const s
|
||||||
int temp = print.config().first_layer_bed_temperature.get_at(first_printing_extruder_id);
|
int temp = print.config().first_layer_bed_temperature.get_at(first_printing_extruder_id);
|
||||||
// Is the bed temperature set by the provided custom G-code?
|
// Is the bed temperature set by the provided custom G-code?
|
||||||
int temp_by_gcode = -1;
|
int temp_by_gcode = -1;
|
||||||
bool temp_set_by_gcode = custom_gcode_sets_temperature(gcode, 140, 190, temp_by_gcode);
|
bool temp_set_by_gcode = custom_gcode_sets_temperature(gcode, 140, 190, false, temp_by_gcode);
|
||||||
if (temp_set_by_gcode && temp_by_gcode >= 0 && temp_by_gcode < 1000)
|
if (temp_set_by_gcode && temp_by_gcode >= 0 && temp_by_gcode < 1000)
|
||||||
temp = temp_by_gcode;
|
temp = temp_by_gcode;
|
||||||
// Always call m_writer.set_bed_temperature() so it will set the internal "current" state of the bed temp as if
|
// Always call m_writer.set_bed_temperature() so it will set the internal "current" state of the bed temp as if
|
||||||
|
@ -1686,7 +1720,7 @@ void GCode::_print_first_layer_extruder_temperatures(FILE *file, Print &print, c
|
||||||
{
|
{
|
||||||
// Is the bed temperature set by the provided custom G-code?
|
// Is the bed temperature set by the provided custom G-code?
|
||||||
int temp_by_gcode = -1;
|
int temp_by_gcode = -1;
|
||||||
if (custom_gcode_sets_temperature(gcode, 104, 109, temp_by_gcode)) {
|
if (custom_gcode_sets_temperature(gcode, 104, 109, true, temp_by_gcode)) {
|
||||||
// Set the extruder temperature at m_writer, but throw away the generated G-code as it will be written with the custom G-code.
|
// Set the extruder temperature at m_writer, but throw away the generated G-code as it will be written with the custom G-code.
|
||||||
int temp = print.config().first_layer_temperature.get_at(first_printing_extruder_id);
|
int temp = print.config().first_layer_temperature.get_at(first_printing_extruder_id);
|
||||||
if (temp_by_gcode >= 0 && temp_by_gcode < 1000)
|
if (temp_by_gcode >= 0 && temp_by_gcode < 1000)
|
||||||
|
|
|
@ -72,11 +72,15 @@ std::string GCodeWriter::set_temperature(unsigned int temperature, bool wait, in
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::string code, comment;
|
std::string code, comment;
|
||||||
if (wait && FLAVOR_IS_NOT(gcfTeacup)) {
|
if (wait && FLAVOR_IS_NOT(gcfTeacup) && FLAVOR_IS_NOT(gcfRepRap)) {
|
||||||
code = "M109";
|
code = "M109";
|
||||||
comment = "set temperature and wait for it to be reached";
|
comment = "set temperature and wait for it to be reached";
|
||||||
} else {
|
} else {
|
||||||
code = "M104";
|
if (FLAVOR_IS(gcfRepRap)) { // M104 is deprecated on RepRapFirmware
|
||||||
|
code = "G10";
|
||||||
|
} else {
|
||||||
|
code = "M104";
|
||||||
|
}
|
||||||
comment = "set temperature";
|
comment = "set temperature";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,14 +92,17 @@ std::string GCodeWriter::set_temperature(unsigned int temperature, bool wait, in
|
||||||
gcode << "S";
|
gcode << "S";
|
||||||
}
|
}
|
||||||
gcode << temperature;
|
gcode << temperature;
|
||||||
if (tool != -1 &&
|
bool multiple_tools = this->multiple_extruders && ! m_single_extruder_multi_material;
|
||||||
( (this->multiple_extruders && ! m_single_extruder_multi_material) ||
|
if (tool != -1 && (multiple_tools || FLAVOR_IS(gcfMakerWare) || FLAVOR_IS(gcfSailfish)) ) {
|
||||||
FLAVOR_IS(gcfMakerWare) || FLAVOR_IS(gcfSailfish)) ) {
|
if (FLAVOR_IS(gcfRepRap)) {
|
||||||
gcode << " T" << tool;
|
gcode << " P" << tool;
|
||||||
|
} else {
|
||||||
|
gcode << " T" << tool;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gcode << " ; " << comment << "\n";
|
gcode << " ; " << comment << "\n";
|
||||||
|
|
||||||
if (FLAVOR_IS(gcfTeacup) && wait)
|
if ((FLAVOR_IS(gcfTeacup) || FLAVOR_IS(gcfRepRap)) && wait)
|
||||||
gcode << "M116 ; wait for temperature to be reached\n";
|
gcode << "M116 ; wait for temperature to be reached\n";
|
||||||
|
|
||||||
return gcode.str();
|
return gcode.str();
|
||||||
|
|
Loading…
Add table
Reference in a new issue