Lots of work on status representation

This commit is contained in:
2023-04-28 14:50:58 +03:00
parent 796fd57ac3
commit 30ccb20846
8 changed files with 430 additions and 457 deletions
+17 -6
View File
@@ -74,6 +74,8 @@ void grbl::tcp_transport::worker() {
std::string received;
uint8_t buffer[200];
auto last_report = std::chrono::high_resolution_clock::now();
while (!should_quit) {
if (is_connected) {
// anything to write?
@@ -103,12 +105,12 @@ void grbl::tcp_transport::worker() {
if (is_eol) {
if (!is_empty_line(received)) {
// starts with? https://stackoverflow.com/questions/1878001/how-do-i-check-if-a-c-stdstring-starts-with-a-certain-string-and-convert-a
if (received.rfind("Grbl", 0) == 0) {
listener->on_banner(received, this);
} else {
listener->on_line_received(received, this);
}
// if (received.rfind("Grbl", 0) == 0) {
// listener->on_banner(received, this);
//
// } else {
listener->on_line_received(received, this);
// }
}
received.clear();
} else {
@@ -117,6 +119,15 @@ void grbl::tcp_transport::worker() {
}
}
auto now = std::chrono::high_resolution_clock::now();
auto ms_since_last_report = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_report);
// maintain a 5Hz rate
if (ms_since_last_report.count() >= 200) {
request_realtime_report();
last_report = now;
}
// give some time to others
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}