Enabling opening and running of programs. Added jogging.

This commit is contained in:
2023-04-27 23:15:06 +03:00
parent 32bda9d55b
commit 796fd57ac3
7 changed files with 420 additions and 1441 deletions
+103 -18
View File
@@ -51,15 +51,20 @@
#include "grbl.h"
#include <gtest/gtest.h>
#include "grbl_communication.h"
#include "machine.h"
using namespace nanogui;
grbl::machine cnc{};
class SenderApp : public Screen {
public:
Window *window;
Window *left_window;
Window *right_window;
grbl::jog_state jog;
SenderApp() : Screen(Vector2i(1024, 768), "GRBL Sender") {
inc_ref();
@@ -82,7 +87,15 @@ public:
new Label(left_window, "Push buttons", "sans-bold");
Button *b = new Button(left_window, "Plain button");
b->set_callback([] { std::cout << "pushed!" << std::endl; });
b->set_callback([&] {
auto path = file_dialog(
{{"nc", "G-Code files"},
{"ngc", "G-Code files"}}, false);
grbl::program pgm{path};
if (pgm.is_loaded) {
cnc.run_program(pgm);
}
});
b->set_tooltip("short tooltip");
/* Alternative construction notation using variadic template */
@@ -553,12 +566,13 @@ public:
m_shader->set_uniform("intensity", 0.5f);
}
bool resize_event(const Vector2i &size) override {
bool resize_event(const Vector2i& size) override {
window->set_size(size);
Screen::resize_event(size);
return true;
}
virtual bool keyboard_event(int key, int scancode, int action, int modifiers) {
if (Screen::keyboard_event(key, scancode, action, modifiers))
return true;
@@ -567,13 +581,77 @@ public:
return true;
}
if (key == GLFW_KEY_UP) {
auto new_jog = jog;
if (key == GLFW_KEY_LEFT_SHIFT) {
if (action == GLFW_PRESS) {
set_caption("Jogging");
new_jog.speed_fast_pressed = true;
} else if (action == GLFW_RELEASE) {
set_caption("Idle");
new_jog.speed_fast_pressed = false;
}
}
if (key == GLFW_KEY_LEFT_CONTROL) {
if (action == GLFW_PRESS) {
new_jog.speed_slow_pressed = true;
} else if (action == GLFW_RELEASE) {
new_jog.speed_slow_pressed = false;
}
}
if (key == GLFW_KEY_UP) {
if (action == GLFW_PRESS) {
new_jog.up_pressed = true;
} else if (action == GLFW_RELEASE) {
new_jog.up_pressed = false;
}
}
if (key == GLFW_KEY_DOWN) {
if (action == GLFW_PRESS) {
new_jog.down_pressed = true;
} else if (action == GLFW_RELEASE) {
new_jog.down_pressed = false;
}
}
if (key == GLFW_KEY_LEFT) {
if (action == GLFW_PRESS) {
new_jog.left_pressed = true;
} else if (action == GLFW_RELEASE) {
new_jog.left_pressed = false;
}
}
if (key == GLFW_KEY_RIGHT) {
if (action == GLFW_PRESS) {
new_jog.right_pressed = true;
} else if (action == GLFW_RELEASE) {
new_jog.right_pressed = false;
}
}
if (key == GLFW_KEY_PAGE_UP) {
if (action == GLFW_PRESS) {
new_jog.z_up_pressed = true;
} else if (action == GLFW_RELEASE) {
new_jog.z_up_pressed = false;
}
}
if (key == GLFW_KEY_PAGE_DOWN) {
if (action == GLFW_PRESS) {
new_jog.z_down_pressed = true;
} else if (action == GLFW_RELEASE) {
new_jog.z_down_pressed = false;
}
}
if (jog != new_jog) {
cnc.request_jog(new_jog);
jog = new_jog;
}
return false;
}
@@ -625,22 +703,22 @@ struct grbl_listener : public grbl::transport_callbacks {
std::cout << "Listener: disconnected!" << std::endl;
}
void on_line_received(std::string line, grbl::transport *t) override {
std::cout << "Listener: -> " << line << std::endl;
}
void on_banner(std::string version, grbl::transport *t) override {
std::cout << "Banner: " << version << std::endl;
t->send("$$");
}
void on_line_received(std::string line, grbl::transport *t) override {
std::cout << "Listener: -> " << line << std::endl;
}
};
int main(int argc, char **argv) {
grbl_listener listener{};
grbl::tcp_transport transport("192.168.5.39", 23);
transport.open(listener);
// grbl_listener listener;
//
// grbl::tcp_transport transport("192.168.5.39", 23);
// transport.open(listener);
testing::InitGoogleTest(&argc, argv);
auto result = RUN_ALL_TESTS();
@@ -648,10 +726,17 @@ int main(int argc, char **argv) {
exit(result);
}
transport.request_realtime_report();
transport.request_cycle_start();
transport.request_feed_hold();
transport.parser_state_report();
cnc.connect();
// grbl::program pgm{"./program.nc"};
//// pgm.dump(std::cout);
//
// cnc.run_program(pgm);
// transport.request_realtime_report();
// transport.request_cycle_start();
// transport.request_feed_hold();
// transport.parser_state_report();
try {
@@ -671,7 +756,7 @@ int main(int argc, char **argv) {
}
nanogui::shutdown();
} catch (const std::exception &e) {
} catch (const std::exception& e) {
std::string error_msg = std::string("Caught a fatal error: ") + std::string(e.what());
std::cerr << error_msg << std::endl;
return -1;