feat:add M1020 check for gcode checker

Change-Id: I89e75063913056c03ef4f5cfb805623038be9769
jira: none
This commit is contained in:
BBL\chuan.he 2024-06-27 11:39:05 +08:00 committed by Lane.Wei
parent 3e607854ed
commit 0d901640f2
2 changed files with 45 additions and 0 deletions

View File

@ -232,6 +232,10 @@ GCodeCheckResult GCodeChecker::parse_command(GCodeLine& gcode_line)
ret = parse_M104_M109(gcode_line);
break;
} // Set to nozzle temperature
case 1020: {
ret = parse_M1020(gcode_line);
break;
}
default: { break; }
}
break;
@ -469,6 +473,46 @@ GCodeCheckResult GCodeChecker::parse_M104_M109(const GCodeLine &gcode_line)
return GCodeCheckResult::Success;
}
GCodeCheckResult GCodeChecker::parse_M1020(const GCodeLine& gcode_line)
{
const char* c = gcode_line.m_raw.c_str();
const char* rs = strchr(c, 'S');
if (rs != nullptr) {
std::string str = rs;
str = str.substr(1);
for (int i = 0; i < str.size(); i++) {
if (str[i] == ' ')
str = str.substr(0, i);
}
try {
int value = std::stoi(str);
if (value >= 0 && value <= filament_flow_ratio.size() - 1) {
filament_id = value;
flow_ratio = filament_flow_ratio[value];
return GCodeCheckResult::Success;
}
else {
return GCodeCheckResult::ParseFailed;
}
}
catch (std::invalid_argument&) {
std::cout << "Invalid argument: not a valid integer" << std::endl;
return GCodeCheckResult::ParseFailed;
}
catch (std::out_of_range&) {
std::cout << "Out of range: number is too large" << std::endl;
return GCodeCheckResult::ParseFailed;
}
}
else
{
std::cout << "Missing 'S' character in the G-code line!" << std::endl;
return GCodeCheckResult::ParseFailed;
}
}
double GCodeChecker::calculate_G1_width(const std::array<double, 3>& source,
const std::array<double, 3>& target,
double e, double height, bool is_bridge) const

View File

@ -109,6 +109,7 @@ private:
GCodeCheckResult parse_M82(const GCodeLine& gcode_line);
GCodeCheckResult parse_M83(const GCodeLine& gcode_line);
GCodeCheckResult parse_M104_M109(const GCodeLine &gcode_line);
GCodeCheckResult parse_M1020(const GCodeLine& gcode_line);
GCodeCheckResult parse_comment(GCodeLine& gcode_line);