24 #include "MGrblPlatformDevice.hpp"
26 #include <ccut/async.hpp>
27 #include <ccut/utils.hpp>
29 #include "MGrblPlatform.hpp"
31 using namespace logger;
33 using namespace smc::internal;
36 const std::set<std::string> MGrblPlatformDevice::s_ctrlSettings{
37 "layout",
"grblCount",
"trigArm"};
39 MGrblPlatformDevice::MGrblPlatformDevice(
40 const std::string &uid,
41 const std::shared_ptr<MGrblPlatform> &mgrbl,
42 const std::shared_ptr<GrblPlatform> &grbl) :
47 std::future<std::set<std::string>> MGrblPlatformDevice::listConfig()
const
51 std::shared_ptr<MGrblPlatform> mgrbl(m_mgrbl.lock());
53 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
55 return mgrbl->run<std::set<std::string>>(
57 std::set<std::string> ret;
64 ret.insert(s_ctrlSettings.begin(), s_ctrlSettings.end());
65 cmd.prom->get<std::set<std::string>>().set_value(ret);
70 return ccut::make_future_error<std::set<std::string>>(ex);
75 const std::string &name)
const
79 std::shared_ptr<MGrblPlatform> mgrbl(m_mgrbl.lock());
81 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
83 if (s_ctrlSettings.count(name))
85 return mgrbl->run<std::string>(
88 const std::string settingCmd = mgrbl::ControlSymbol +
90 grbl::ErrorCode rc = ctx.device->send(
92 [&settingCmd, &ret](
const std::string &line) {
93 if (ccut::startsWith(line, settingCmd))
95 ret = line.substr(settingCmd.size() + 1);
101 cmd.prom->get<std::string>().set_value(ret);
111 return ccut::make_future_error<std::string>(ex);
116 const std::string &value)
const
120 std::shared_ptr<MGrblPlatform> mgrbl(m_mgrbl.lock());
122 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
124 if (s_ctrlSettings.count(name))
126 return mgrbl->run<
void>(
129 grbl::ErrorCode rc = ctx.device->send(
130 mgrbl::ControlSymbol + (
"$" + name) +
"=" + value);
132 mgrbl->loadLayout(ctx);
133 cmd.prom->get<
void>().set_value();
143 return ccut::make_future_error<void>(ex);
Exception thrown by MotionController in case of issues with command.
main motion-lib namespace
std::set< std::string > listConfig()
list config values