Add alarm details and only rerender status when it changes
This commit is contained in:
+2
-2
@@ -121,9 +121,9 @@ std::string grbl::status_to_string(const grbl::machine_status& status) {
|
|||||||
std::string grbl::alarm_to_string(int alarm) {
|
std::string grbl::alarm_to_string(int alarm) {
|
||||||
switch (alarm) {
|
switch (alarm) {
|
||||||
case 1:
|
case 1:
|
||||||
return "Hard limit has been triggered. Machine position is likely lost due to sudden halt. Re-homing is highly recommended.";
|
return "Hard limit has been triggered.\nMachine position is likely lost due to sudden halt.\nRe-homing is highly recommended.";
|
||||||
case 2:
|
case 2:
|
||||||
return "Soft limit alarm. G-code motion target exceeds machine travel. Machine position retained. Alarm may be safely unlocked.";
|
return "Soft limit alarm. G-code motion target exceeds\nmachine travel. Machine position retained.\nAlarm may be safely unlocked.";
|
||||||
case 3:
|
case 3:
|
||||||
return "Reset while in motion. Machine position is likely lost due to sudden halt. Re-homing is highly recommended.";
|
return "Reset while in motion. Machine position is likely lost due to sudden halt. Re-homing is highly recommended.";
|
||||||
case 4:
|
case 4:
|
||||||
|
|||||||
@@ -46,6 +46,19 @@ struct realtime_status_report {
|
|||||||
std::string firmware;
|
std::string firmware;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const realtime_status_report& a, const realtime_status_report& b) {
|
||||||
|
return (a.status == b.status &&
|
||||||
|
a.sub_status == b.sub_status &&
|
||||||
|
a.machine_pos[0] == b.machine_pos[0] &&
|
||||||
|
a.machine_pos[1] == b.machine_pos[1] &&
|
||||||
|
a.machine_pos[2] == b.machine_pos[2] &&
|
||||||
|
a.work_pos[0] == b.work_pos[0] &&
|
||||||
|
a.work_pos[1] == b.work_pos[1] &&
|
||||||
|
a.work_pos[2] == b.work_pos[2] &&
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
realtime_status_report parse_status_report(std::string line, grbl::realtime_status_report& result);
|
realtime_status_report parse_status_report(std::string line, grbl::realtime_status_report& result);
|
||||||
|
|
||||||
enum class grbl_machine_state {
|
enum class grbl_machine_state {
|
||||||
@@ -119,7 +132,7 @@ protected:
|
|||||||
void on_line_received(std::string line, transport *transport) override;
|
void on_line_received(std::string line, transport *transport) override;
|
||||||
|
|
||||||
realtime_status_report last_report{};
|
realtime_status_report last_report{};
|
||||||
machine_listener* listener = nullptr;
|
machine_listener *listener = nullptr;
|
||||||
transport *pipe = nullptr;
|
transport *pipe = nullptr;
|
||||||
grbl_machine_state state = grbl_machine_state::init;
|
grbl_machine_state state = grbl_machine_state::init;
|
||||||
program running_program;
|
program running_program;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <nanogui/graph.h>
|
#include <nanogui/graph.h>
|
||||||
#include <nanogui/tabwidget.h>
|
#include <nanogui/tabwidget.h>
|
||||||
#include <nanogui/texture.h>
|
#include <nanogui/texture.h>
|
||||||
|
#include <nanogui/textarea.h>
|
||||||
#include <nanogui/shader.h>
|
#include <nanogui/shader.h>
|
||||||
#include <nanogui/renderpass.h>
|
#include <nanogui/renderpass.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -52,6 +53,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "grbl_communication.h"
|
#include "grbl_communication.h"
|
||||||
#include "machine.h"
|
#include "machine.h"
|
||||||
|
#include "string_utils.h"
|
||||||
|
|
||||||
using namespace nanogui;
|
using namespace nanogui;
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ public:
|
|||||||
Window *window;
|
Window *window;
|
||||||
grbl::jog_state jog;
|
grbl::jog_state jog;
|
||||||
Label *m_pos_x, *m_pos_y, *m_pos_z;
|
Label *m_pos_x, *m_pos_y, *m_pos_z;
|
||||||
TextBox *lblStatus, *lblSubstatus;
|
TextArea *lblStatus, *lblSubstatus;
|
||||||
nanogui::Color red = nanogui::Color(255, 0, 0, 255);
|
nanogui::Color red = nanogui::Color(255, 0, 0, 255);
|
||||||
int last_alarm = 0;
|
int last_alarm = 0;
|
||||||
|
|
||||||
@@ -80,8 +82,13 @@ public:
|
|||||||
Widget *status_holder = new Widget(window);
|
Widget *status_holder = new Widget(window);
|
||||||
status_holder->set_layout(new GridLayout());
|
status_holder->set_layout(new GridLayout());
|
||||||
|
|
||||||
lblStatus = new TextBox(window, grbl::status_to_string(cnc.get_status().status));
|
lblStatus = new TextArea(window);
|
||||||
lblSubstatus = new TextBox(window, cnc.get_status().sub_status);
|
lblStatus->set_fixed_height(20);
|
||||||
|
lblStatus->set_font("sans");
|
||||||
|
|
||||||
|
lblSubstatus = new TextArea(window);
|
||||||
|
lblSubstatus->set_font("sans");
|
||||||
|
lblSubstatus->set_fixed_height(50);
|
||||||
|
|
||||||
// Machine pos
|
// Machine pos
|
||||||
new Label(window, "Machine pos", "sans-bold");
|
new Label(window, "Machine pos", "sans-bold");
|
||||||
@@ -282,17 +289,34 @@ public:
|
|||||||
void on_disconnected() override {
|
void on_disconnected() override {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
grbl::realtime_status_report last_report;
|
||||||
|
|
||||||
void on_realtime_status_report(grbl::realtime_status_report report) override {
|
void on_realtime_status_report(grbl::realtime_status_report report) override {
|
||||||
lblStatus->set_value(grbl::status_to_string(cnc.get_status().status) + " ");
|
if (report == last_report) return;
|
||||||
|
|
||||||
|
if (last_report.status != report.status) {
|
||||||
|
lblStatus->clear();
|
||||||
|
lblStatus->append(grbl::status_to_string(cnc.get_status().status));
|
||||||
|
|
||||||
|
lblSubstatus->clear();
|
||||||
if (cnc.get_status().status == grbl::machine_status::alarm) {
|
if (cnc.get_status().status == grbl::machine_status::alarm) {
|
||||||
lblSubstatus->set_value(grbl::alarm_to_string(last_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 {
|
} else {
|
||||||
lblSubstatus->set_value(cnc.get_status().sub_status);
|
lblSubstatus->append(cnc.get_status().sub_status);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pos_x->set_caption(std::to_string(cnc.get_status().machine_pos[0]));
|
m_pos_x->set_caption(std::to_string(cnc.get_status().machine_pos[0]));
|
||||||
m_pos_y->set_caption(std::to_string(cnc.get_status().machine_pos[1]));
|
m_pos_y->set_caption(std::to_string(cnc.get_status().machine_pos[1]));
|
||||||
m_pos_z->set_caption(std::to_string(cnc.get_status().machine_pos[2]));
|
m_pos_z->set_caption(std::to_string(cnc.get_status().machine_pos[2]));
|
||||||
|
|
||||||
|
last_report = report;
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_banner(std::string line) override {
|
void on_banner(std::string line) override {
|
||||||
|
|||||||
+7
-7
@@ -3,7 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::vector<std::string> split_string(const std::string& in, const std::string& delimiter) {
|
inline std::vector<std::string> split_string(const std::string& in, const std::string& delimiter) {
|
||||||
std::vector<std::string> result{};
|
std::vector<std::string> result{};
|
||||||
size_t last{0}, next;
|
size_t last{0}, next;
|
||||||
while ((next = in.find(delimiter, last)) != std::string::npos) {
|
while ((next = in.find(delimiter, last)) != std::string::npos) {
|
||||||
@@ -14,30 +14,30 @@ std::vector<std::string> split_string(const std::string& in, const std::string&
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
inline std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
||||||
str.erase(0, str.find_first_not_of(chars));
|
str.erase(0, str.find_first_not_of(chars));
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ltrim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
inline std::string ltrim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
||||||
str.erase(0, str.find_first_not_of(chars));
|
str.erase(0, str.find_first_not_of(chars));
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
inline std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
||||||
str.erase(str.find_last_not_of(chars) + 1);
|
str.erase(str.find_last_not_of(chars) + 1);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string rtrim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
inline std::string rtrim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
||||||
str.erase(str.find_last_not_of(chars) + 1);
|
str.erase(str.find_last_not_of(chars) + 1);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
inline std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
||||||
return ltrim(rtrim(str, chars), chars);
|
return ltrim(rtrim(str, chars), chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string trim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
inline std::string trim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
||||||
return ltrim(rtrim(str, chars), chars);
|
return ltrim(rtrim(str, chars), chars);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user