diff --git a/grbl_machine.cpp b/grbl_machine.cpp index a345376..88942dc 100644 --- a/grbl_machine.cpp +++ b/grbl_machine.cpp @@ -44,7 +44,12 @@ void grbl::machine::on_disconnected(grbl::transport *transport) { grbl::realtime_status_report grbl::parse_status_report(std::string line, grbl::realtime_status_report& result) { // grbl::realtime_status_report result; - auto l = line.substr(1, -1); + // pin values are always reset when a report arrives + // if there is no value in the Pn: field then it means + // no pin is active + result.signals.value = 0; + + auto l = line.substr(1, line.size() - 2); auto pieces = split_string(l, "|"); for (auto i = 0; i < pieces.size(); i++) { if (i == 0) { @@ -68,6 +73,38 @@ grbl::realtime_status_report grbl::parse_status_report(std::string line, grbl::r auto p = split_string(elements[1], ","); result.buffers_free = std::stoi(p[0]); result.rx_chars_free = std::stoi(p[1]); + } else if (elements[0] == "Pn") { + for (auto& c: elements[1]) { + switch (c) { + case 'P': + result.signals.bit.probe = true; + break; + case 'X': + result.signals.bit.x_limit = true; + break; + case 'Y': + result.signals.bit.y_limit = true; + break; + case 'Z': + result.signals.bit.z_limit = true; + break; + case 'D': + result.signals.bit.door = true; + break; + case 'H': + result.signals.bit.hold = true; + break; + case 'R': + result.signals.bit.soft_reset = true; + break; + case 'S': + result.signals.bit.cycle_start = true; + break; + default: + std::cerr << "Unknown pin value [" << c << "] when parsing status report" << std::endl; + break; + } + } } else { // not implemented } @@ -640,7 +677,7 @@ void grbl::machine::request_jog_fixed(grbl::jog_direction dir, float distance, f break; } command += std::to_string(distance) + " F" + std::to_string(feed); - + pipe->send(command); awaiting_responses++; } @@ -714,7 +751,7 @@ void grbl::machine_state_init::move_to_next_init_stage() { switch (init_state) { case init_stage::start: init_state = init_stage::set_work_pos; - cnc->pipe->send("$10=1"); // machine pos in report, please + cnc->pipe->send("$10=511"); // machine pos in report, please. also sensors and buffers info break; case init_stage::set_work_pos: init_state = init_stage::fetch_settings; diff --git a/grbl_machine.h b/grbl_machine.h index e1648ef..407270b 100644 --- a/grbl_machine.h +++ b/grbl_machine.h @@ -38,7 +38,19 @@ struct realtime_status_report { float feed_rate = 0; float programmed_rpm = 0; float actual_rpm = 0; - std::string signals; + union { + struct { + bool x_limit : 1; + bool y_limit : 1; + bool z_limit : 1; + bool probe : 1; + bool door : 1; + bool hold : 1; + bool soft_reset : 1; + bool cycle_start : 1; + } bit; + uint8_t value = 0; + } signals; float axis_offsets[3] = {0}; std::string coordinate_system; std::string overrides; diff --git a/grbl_test.cpp b/grbl_test.cpp index f921568..0ff95d5 100644 --- a/grbl_test.cpp +++ b/grbl_test.cpp @@ -44,7 +44,13 @@ TEST(grbl_status_report, parse) { EXPECT_EQ(35, r.buffers_free); // - grbl::parse_status_report("", r); + grbl::parse_status_report("", r); EXPECT_EQ(grbl::machine_status::home, r.status); EXPECT_EQ(1022, r.rx_chars_free); + + EXPECT_EQ(true, r.signals.bit.probe); + + EXPECT_EQ(false, r.signals.bit.x_limit); + EXPECT_EQ(false, r.signals.bit.y_limit); + EXPECT_EQ(true, r.signals.bit.z_limit); } \ No newline at end of file diff --git a/main.cpp b/main.cpp index 98ee1b1..26c1488 100644 --- a/main.cpp +++ b/main.cpp @@ -77,6 +77,10 @@ public: Widget *parameters_layer; TextBox *mpos_x_text, *mpos_y_text, *mpos_z_text; ComboBox *cbo_work_offset, *cbo_tool, *cbo_jog_feed_rates, *cbo_jog_distance; + + ToolButton *btn_pin_door, *btn_pin_hold, *btn_pin_reset, *btn_pin_cycle_start; + ToolButton *btn_pin_limit_x, *btn_pin_limit_y, *btn_pin_limit_z, *btn_pin_probe; + Button *btn_keyboard_jog; std::stringstream dro_ss; @@ -101,6 +105,7 @@ public: add_status_markup(); add_dro_markup(); + add_pins_markup(); add_jogging_markup(); add_work_parameters_markup(); @@ -318,7 +323,7 @@ public: } void add_dro_markup() { - dro_ss << std::setprecision(4) << std::fixed; + dro_ss << std::setprecision(3) << std::fixed; // DRO info_layer->add