Emit coolant state events
This commit is contained in:
@@ -15,6 +15,8 @@ namespace {
|
||||
|
||||
CanonEventSink *active_sink = nullptr;
|
||||
int active_line = 0;
|
||||
bool flood_on = false;
|
||||
bool mist_on = false;
|
||||
std::string parameter_file_name = "rs274ngc.var";
|
||||
|
||||
CncSimPose make_pose(double x, double y, double z,
|
||||
@@ -86,12 +88,26 @@ int event_line(int lineno = 0) {
|
||||
return lineno > 0 ? lineno : active_line;
|
||||
}
|
||||
|
||||
void emit_state_event(CncSimEventType type, int reserved) {
|
||||
if (!active_sink) {
|
||||
return;
|
||||
}
|
||||
CncSimEvent event{};
|
||||
event.version = 1;
|
||||
event.type = type;
|
||||
event.line = event_line();
|
||||
event.reserved = reserved;
|
||||
active_sink->emit_raw(event);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void cnc_sim_linuxcnc_set_canon_sink(CanonEventSink *sink) {
|
||||
trace_call("cnc_sim_linuxcnc_set_canon_sink");
|
||||
active_sink = sink;
|
||||
active_line = 0;
|
||||
flood_on = false;
|
||||
mist_on = false;
|
||||
}
|
||||
|
||||
CanonEventSink *cnc_sim_linuxcnc_get_canon_sink() {
|
||||
@@ -107,6 +123,8 @@ void INIT_CANON() {
|
||||
if (active_sink) {
|
||||
active_sink->reset();
|
||||
}
|
||||
flood_on = false;
|
||||
mist_on = false;
|
||||
}
|
||||
|
||||
void USE_LENGTH_UNITS(CANON_UNITS units) {
|
||||
@@ -410,13 +428,7 @@ void CLAMP_AXIS(CANON_AXIS) {
|
||||
}
|
||||
|
||||
void COMMENT(const char *) {
|
||||
if (active_sink) {
|
||||
CncSimEvent event{};
|
||||
event.version = 1;
|
||||
event.type = CNC_SIM_EVENT_COMMENT;
|
||||
event.line = event_line();
|
||||
active_sink->emit_raw(event);
|
||||
}
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 0);
|
||||
}
|
||||
|
||||
void DISABLE_ADAPTIVE_FEED() {
|
||||
@@ -444,9 +456,13 @@ void ENABLE_FEED_HOLD() {
|
||||
}
|
||||
|
||||
void FLOOD_OFF() {
|
||||
flood_on = false;
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 20);
|
||||
}
|
||||
|
||||
void FLOOD_ON() {
|
||||
flood_on = true;
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 21);
|
||||
}
|
||||
|
||||
void MESSAGE(char *) {
|
||||
@@ -465,9 +481,13 @@ void LOGCLOSE() {
|
||||
}
|
||||
|
||||
void MIST_OFF() {
|
||||
mist_on = false;
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 10);
|
||||
}
|
||||
|
||||
void MIST_ON() {
|
||||
mist_on = true;
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 11);
|
||||
}
|
||||
|
||||
void PALLET_SHUTTLE() {
|
||||
@@ -555,7 +575,7 @@ double GET_EXTERNAL_FEED_RATE() {
|
||||
}
|
||||
|
||||
int GET_EXTERNAL_FLOOD() {
|
||||
return 0;
|
||||
return flood_on ? 1 : 0;
|
||||
}
|
||||
|
||||
CANON_UNITS GET_EXTERNAL_LENGTH_UNIT_TYPE() {
|
||||
@@ -571,7 +591,7 @@ double GET_EXTERNAL_ANGLE_UNITS() {
|
||||
}
|
||||
|
||||
int GET_EXTERNAL_MIST() {
|
||||
return 0;
|
||||
return mist_on ? 1 : 0;
|
||||
}
|
||||
|
||||
CANON_MOTION_MODE GET_EXTERNAL_MOTION_CONTROL_MODE() {
|
||||
|
||||
@@ -230,6 +230,15 @@ bool stop_if_callback_aborted(CanonEventSink &sink, std::string *error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void emit_comment_state(CanonEventSink &sink, int line, int reserved) {
|
||||
CncSimEvent event{};
|
||||
event.version = 1;
|
||||
event.type = CNC_SIM_EVENT_COMMENT;
|
||||
event.line = line;
|
||||
event.reserved = reserved;
|
||||
sink.emit_raw(event);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int SmokeGcodeParser::parse(const char *program, size_t program_len, std::string *error) {
|
||||
@@ -366,6 +375,25 @@ int SmokeGcodeParser::parse(const char *program, size_t program_len, std::string
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 7) {
|
||||
emit_comment_state(sink_, line_number, 11);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 8) {
|
||||
emit_comment_state(sink_, line_number, 21);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 9) {
|
||||
emit_comment_state(sink_, line_number, 10);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
emit_comment_state(sink_, line_number, 20);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 428) {
|
||||
sink_.switch_kinematics(1, true, line_number);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
|
||||
Reference in New Issue
Block a user