From: Logxen Date: Tue, 4 Mar 2014 21:58:05 +0000 (-0800) Subject: improved error response of ToolManager X-Git-Url: http://git.hcoop.net/clinton/Smoothieware.git/commitdiff_plain/f4a68aece6930e355165bf37604aaf7059259c92 improved error response of ToolManager --- diff --git a/src/modules/tools/toolmanager/ToolManager.cpp b/src/modules/tools/toolmanager/ToolManager.cpp index dc58b354..71e4267a 100644 --- a/src/modules/tools/toolmanager/ToolManager.cpp +++ b/src/modules/tools/toolmanager/ToolManager.cpp @@ -13,14 +13,23 @@ using namespace std; #include "ToolManager.h" #include "Conveyor.h" +#define return_error_on_unhandled_gcode_checksum CHECKSUM("return_error_on_unhandled_gcode") + ToolManager::ToolManager(){ active_tool = 0; } void ToolManager::on_module_loaded(){ + this->on_config_reload(this); + + this->register_for_event(ON_CONFIG_RELOAD); this->register_for_event(ON_GCODE_RECEIVED); } +void ToolManager::on_config_reload(void *argument){ + return_error_on_unhandled_gcode = THEKERNEL->config->value( return_error_on_unhandled_gcode_checksum )->by_default(false)->as_bool(); +} + void ToolManager::on_gcode_received(void *argument){ Gcode *gcode = static_cast(argument); @@ -33,8 +42,11 @@ void ToolManager::on_gcode_received(void *argument){ gcode->mark_as_taken(); if(new_tool >= (int)this->tools.size() || new_tool < 0){ // invalid tool - // TODO: report invalid selection - gcode->stream->printf(";;T%d invalid tool\r\n", new_tool); + if( return_error_on_unhandled_gcode ) { + char buf[32]; // should be big enough for any status + int n= snprintf(buf, sizeof(buf), "T%d invalid tool ", new_tool); + gcode->txt_after_ok.append(buf, n); + } } else { if(new_tool != this->active_tool){ void *returned_data; diff --git a/src/modules/tools/toolmanager/ToolManager.h b/src/modules/tools/toolmanager/ToolManager.h index ddc9589d..04b25395 100644 --- a/src/modules/tools/toolmanager/ToolManager.h +++ b/src/modules/tools/toolmanager/ToolManager.h @@ -19,11 +19,13 @@ class ToolManager : public Module { void on_module_loaded(); void on_gcode_received(void*); + void on_config_reload(void*); void add_tool(Tool* tool_to_add); vector tools; int active_tool; + bool return_error_on_unhandled_gcode; };