mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-06 23:31:19 +00:00
AppConfig.hpp, DeviceManager.hpp and UserManager.hpp carried a global "using namespace nlohmann;", json_diff.hpp a global "using json = nlohmann::json;" and PrinterFileSystem.h a global "using nlohmann::json;". Every file that included one of them, directly or not, could write a bare json, and 63 did without declaring it. The last two also made the include checker treat json_diff.hpp and PrinterFileSystem.h as the headers that provide json, so they were included from files that use nothing else from them: 57 of the 59 includers of json_diff.hpp never name json_diff. The five statements are removed. Headers that use the type now spell nlohmann::json, source files declare their own "using json = nlohmann::json;", and the includes that only supplied the name are dropped or replaced by <nlohmann/json.hpp>. Eight files reached json_diff.hpp only through an include that is now gone and with it lost that header's "using namespace std;". The std names they used unqualified are qualified.
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
#include "DevAxis.h"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
#include "slic3r/GUI/DeviceManager.hpp"
|
|
#include <string>
|
|
#include <cstdlib>
|
|
#include <cstdio>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
namespace Slic3r
|
|
{
|
|
|
|
int DevAxis::Ctrl_GoHome()
|
|
{
|
|
if (m_is_support_mqtt_homing) {
|
|
json j;
|
|
j["print"]["command"] = "back_to_center";
|
|
j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
|
return m_owner->publish_json(j);
|
|
}
|
|
|
|
// gcode command
|
|
return m_owner->is_in_printing() ? m_owner->publish_gcode("G28 X\n") : m_owner->publish_gcode("G28 \n");
|
|
}
|
|
|
|
int DevAxis::Ctrl_Axis(std::string axis, double unit, double input_val, int speed)
|
|
{
|
|
if (m_is_support_mqtt_axis_ctrl) {
|
|
int dir = input_val > 0 ? 1 : -1;
|
|
if (!IsArchCoreXY()) {
|
|
if (axis.compare("Y") == 0 || axis.compare("Z") == 0) {
|
|
dir = -dir;
|
|
}
|
|
}
|
|
json j;
|
|
j["print"]["command"] = "xyz_ctrl";
|
|
j["print"]["axis"] = axis;
|
|
j["print"]["dir"] = dir;
|
|
j["print"]["mode"] = (std::abs(input_val) >= 10) ? 1 : 0;
|
|
j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
|
return m_owner->publish_json(j);
|
|
}
|
|
|
|
double value = input_val;
|
|
if (!IsArchCoreXY()) {
|
|
if (axis.compare("Y") == 0 || axis.compare("Z") == 0) {
|
|
value = -1.0 * input_val;
|
|
}
|
|
}
|
|
|
|
char cmd[256];
|
|
if (axis.compare("X") == 0 || axis.compare("Y") == 0 || axis.compare("Z") == 0) {
|
|
sprintf(cmd, "M211 S \nM211 X1 Y1 Z1\nM1002 push_ref_mode\nG91 \nG1 %s%0.1f F%d\nM1002 pop_ref_mode\nM211 R\n", axis.c_str(), value * unit, speed);
|
|
} else if (axis.compare("E") == 0) {
|
|
sprintf(cmd, "M83 \nG0 %s%0.1f F%d\n", axis.c_str(), value * unit, speed);
|
|
} else {
|
|
return -1;
|
|
}
|
|
|
|
// Orca: strip analytics telemetry (matches MachineObject::command_axis_control)
|
|
return m_owner->publish_gcode(cmd);
|
|
}
|
|
|
|
} // namespace Slic3r
|