From 97b818630084dc1d0561b79ca97b08db21a5a747 Mon Sep 17 00:00:00 2001 From: Adrian Scripca Date: Fri, 5 May 2023 22:25:19 +0300 Subject: [PATCH] Keyboard jogging disabled by default. --- grbl_machine.cpp | 28 +++++ grbl_machine.h | 10 ++ main.cpp | 283 ++++++++++++++++++++++++++++++----------------- 3 files changed, 222 insertions(+), 99 deletions(-) diff --git a/grbl_machine.cpp b/grbl_machine.cpp index d613260..a345376 100644 --- a/grbl_machine.cpp +++ b/grbl_machine.cpp @@ -617,6 +617,34 @@ std::array grbl::machine::get_work_pos() const { return result; } +void grbl::machine::request_jog_fixed(grbl::jog_direction dir, float distance, float feed) { + std::string command = "$J=G21 G91"; + switch (dir) { + case jog_direction::x_up: + command += "X"; + break; + case jog_direction::x_down: + command += "X-"; + break; + case jog_direction::y_up: + command += "Y"; + break; + case jog_direction::y_down: + command += "Y-"; + break; + case jog_direction::z_up: + command += "Z"; + break; + case jog_direction::z_down: + command += "Z-"; + break; + } + command += std::to_string(distance) + " F" + std::to_string(feed); + + pipe->send(command); + awaiting_responses++; +} + bool grbl::jog_state::no_jogging() const { return !(up_pressed || down_pressed || left_pressed || right_pressed || z_up_pressed || z_down_pressed); } diff --git a/grbl_machine.h b/grbl_machine.h index 6493830..e1648ef 100644 --- a/grbl_machine.h +++ b/grbl_machine.h @@ -222,6 +222,15 @@ struct parameters_cmp { } }; +enum class jog_direction { + x_up, + x_down, + y_up, + y_down, + z_up, + z_down, +}; + struct machine : public transport_callbacks { machine(); ~machine(); @@ -235,6 +244,7 @@ struct machine : public transport_callbacks { void run_program(const grbl::program& pgm, const std::string& work_offset); void check_program(const grbl::program& pgm); void request_jog(jog_state jog) const; + void request_jog_fixed(jog_direction dir, float distance, float feed); void cancel_jog() const; [[nodiscard]] realtime_status_report get_status() const { return last_report; }; diff --git a/main.cpp b/main.cpp index 33d046e..da42eb6 100644 --- a/main.cpp +++ b/main.cpp @@ -51,7 +51,8 @@ public: Window *window; grbl::jog_state jog; - TextArea *lblStatus, *lblSubstatus; + TextBox *txtStatus; + TextBox *txtMessage; nanogui::Color colRed = nanogui::Color(255, 0, 0, 255); nanogui::Color colGreen = nanogui::Color(0, 255, 0, 255); nanogui::Color colBg; @@ -59,6 +60,9 @@ public: grbl::program pgm; Button *btnLoadProgram, *btnCheckProgram, *btnRunProgram; + std::vector jog_distances = {"0.01", "0.1", "1", "10"}; + std::vector jog_feed_rates = {"5", "100", "500", "1000"}; + grbl::program_renderer renderer; glm::vec3 cam_target = glm::vec3(0); @@ -72,7 +76,8 @@ public: VScrollPanel *parameters_vscroll; Widget *parameters_layer; TextBox *mpos_x_text, *mpos_y_text, *mpos_z_text; - ComboBox *cboOffset, *cboTool; + ComboBox *cbo_work_offset, *cbo_tool, *cbo_jog_feed_rates, *cbo_jog_distance; + Button *btn_keyboard_jog; SenderApp() : Screen(Vector2i(1024, 768), "GRBL Sender") { inc_ref(); @@ -82,36 +87,71 @@ public: // create main window window = new Window(this, "Machine status"); - window->set_fixed_height((Screen::size().y() - 40) / 2); +// window->set_fixed_height((Screen::size().y() - 40) / 2); window->set_position(Vector2i(0, 0)); window->set_layout(new BoxLayout(nanogui::Orientation::Vertical)); tab_widget = window->add(); tab_widget->set_callback([&](int index) { - if (index == 1 || index == 2) { - perform_layout(); - } - tab_widget->set_selected_index(index); }); - tab_widget->set_fixed_height((this->height() - 100) / 2); + tab_widget->set_fixed_height((this->height() - 80) / 2); Widget *layer = new Widget(tab_widget); - layer->set_layout(new GroupLayout()); + layer->set_layout(new GroupLayout(10, 20, 30, 0)); tab_widget->append_tab("Info", layer); - new Label(layer, "Status", "sans-bold"); - Widget *status_holder = new Widget(layer); - status_holder->set_layout(new GridLayout()); + layer->add