Fixed program checking and executing report
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
#include "grbl.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include "grbl_communication.h"
|
||||
#include "machine.h"
|
||||
#include "grbl_machine.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
using namespace nanogui;
|
||||
@@ -67,8 +67,12 @@ public:
|
||||
grbl::jog_state jog;
|
||||
Label *m_pos_x, *m_pos_y, *m_pos_z;
|
||||
TextArea *lblStatus, *lblSubstatus;
|
||||
nanogui::Color red = nanogui::Color(255, 0, 0, 255);
|
||||
nanogui::Color colRed = nanogui::Color(255, 0, 0, 255);
|
||||
nanogui::Color colGreen = nanogui::Color(0, 255, 0, 255);
|
||||
nanogui::Color colBg;
|
||||
int last_alarm = 0;
|
||||
grbl::program pgm;
|
||||
Button *btnLoadProgram, *btnCheckProgram, *btnRunProgram;
|
||||
|
||||
SenderApp() : Screen(Vector2i(1024, 768), "GRBL Sender") {
|
||||
inc_ref();
|
||||
@@ -78,6 +82,12 @@ public:
|
||||
window->set_layout(new GroupLayout());
|
||||
// window->set_size(Screen::size());
|
||||
|
||||
// save regular button color
|
||||
auto b = new Button(this);
|
||||
colBg = b->background_color();
|
||||
b->set_visible(false);
|
||||
|
||||
|
||||
new Label(window, "Status", "sans-bold");
|
||||
Widget *status_holder = new Widget(window);
|
||||
status_holder->set_layout(new GridLayout());
|
||||
@@ -116,7 +126,7 @@ public:
|
||||
cnc.request_home();
|
||||
});
|
||||
Button *btnReset = new Button(actions, "Reset");
|
||||
btnReset->set_background_color(red);
|
||||
btnReset->set_background_color(colRed);
|
||||
btnReset->set_callback([&] {
|
||||
cnc.request_reset();
|
||||
});
|
||||
@@ -133,17 +143,42 @@ public:
|
||||
// freed when the parent window is deleted
|
||||
new Label(window, "Program", "sans-bold");
|
||||
|
||||
Button *btnLoadProgram = new Button(window, "Load");
|
||||
Widget *pgm_actions = new Widget(window);
|
||||
pgm_actions->set_layout(new BoxLayout(Orientation::Horizontal));
|
||||
|
||||
|
||||
btnLoadProgram = new Button(pgm_actions, "Load");
|
||||
btnLoadProgram->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);
|
||||
|
||||
btnCheckProgram->set_background_color(colBg);
|
||||
btnRunProgram->set_background_color(colBg);
|
||||
|
||||
if (pgm.load_from_file(path)) {
|
||||
btnCheckProgram->set_enabled(true);
|
||||
// btnRunProgram->set_enabled(true);
|
||||
} else {
|
||||
btnCheckProgram->set_enabled(false);
|
||||
btnRunProgram->set_enabled(false);
|
||||
}
|
||||
});
|
||||
btnLoadProgram->set_tooltip("short tooltip");
|
||||
btnLoadProgram->set_tooltip("Load program");
|
||||
|
||||
btnCheckProgram = new Button(pgm_actions, "Check");
|
||||
btnCheckProgram->set_enabled(false);
|
||||
btnCheckProgram->set_callback([&] {
|
||||
cnc.check_program(pgm);
|
||||
});
|
||||
btnCheckProgram->set_tooltip("Check program");
|
||||
|
||||
btnRunProgram = new Button(pgm_actions, "Run");
|
||||
btnRunProgram->set_enabled(false);
|
||||
btnRunProgram->set_callback([&] {
|
||||
cnc.run_program(pgm);
|
||||
});
|
||||
btnRunProgram->set_tooltip("Execute program");
|
||||
|
||||
// Alternative construction notation using variadic template
|
||||
btnLoadProgram = window->add<Button>("Styled", FA_ROCKET);
|
||||
@@ -302,14 +337,9 @@ public:
|
||||
lblSubstatus->clear();
|
||||
if (cnc.get_status().status == grbl::machine_status::alarm) {
|
||||
lblSubstatus->append(grbl::alarm_to_string(last_alarm));
|
||||
// auto lines = split_string(grbl::alarm_to_string(last_alarm), "\n");
|
||||
// for (auto& l: lines) {
|
||||
// lblSubstatus->append_line(trim(l));
|
||||
// }
|
||||
} else {
|
||||
lblSubstatus->append(cnc.get_status().sub_status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
m_pos_x->set_caption(std::to_string(cnc.get_status().machine_pos[0]));
|
||||
@@ -330,6 +360,32 @@ public:
|
||||
last_alarm = alarm;
|
||||
}
|
||||
|
||||
void on_check_completed(bool success, size_t failed_index, int error) override {
|
||||
btnCheckProgram->set_background_color(success ? colGreen : colRed);
|
||||
if (success) {
|
||||
btnRunProgram->set_enabled(true);
|
||||
new MessageDialog(this, MessageDialog::Type::Information, "Check result", "Program checked successfully");
|
||||
} else {
|
||||
btnRunProgram->set_enabled(false);
|
||||
std::stringstream ss;
|
||||
auto i = pgm.instruction_at(failed_index);
|
||||
ss << "Program check failed at line " << i.line << " (" << i.command << "). Error: " << error;
|
||||
new MessageDialog(this, MessageDialog::Type::Warning, "Check result", ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
void on_run_completed(bool success, size_t failed_index, int error) override {
|
||||
btnRunProgram->set_background_color(success ? colGreen : colRed);
|
||||
if (success) {
|
||||
new MessageDialog(this, MessageDialog::Type::Information, "Run result", "Program executed successfully");
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
auto i = pgm.instruction_at(failed_index);
|
||||
ss << "Program execution failed at line " << i.line << " (" << i.command << "). Error: " << error;
|
||||
new MessageDialog(this, MessageDialog::Type::Warning, "Run result", ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool keyboard_event(int key, int scancode, int action, int modifiers) override {
|
||||
if (Screen::keyboard_event(key, scancode, action, modifiers))
|
||||
|
||||
Reference in New Issue
Block a user