From eb5f6de454a36e22a16d7bbff790df0ea8f2a76f Mon Sep 17 00:00:00 2001 From: Clinton Ebadi Date: Fri, 27 Oct 2017 16:27:26 -0400 Subject: [PATCH] temperaturecontrol: allow setting background tool without activating Violates NIST spec, unmergable upstream per wolfmanjm Correct solution will be to use a subcode, and adjust cura/slic3r to generate that instead of the illegal T command This also makes M104 immediate, and only makes set_and_wait actually wait for the machine to idle (preventing stuttering). --- .../temperaturecontrol/TemperatureControl.cpp | 41 ++++++++++++------- src/modules/tools/toolmanager/ToolManager.cpp | 5 ++- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/modules/tools/temperaturecontrol/TemperatureControl.cpp b/src/modules/tools/temperaturecontrol/TemperatureControl.cpp index 5e163b2d..61bafaa4 100644 --- a/src/modules/tools/temperaturecontrol/TemperatureControl.cpp +++ b/src/modules/tools/temperaturecontrol/TemperatureControl.cpp @@ -326,21 +326,34 @@ void TemperatureControl::on_gcode_received(void *argument) } } else if( ( gcode->m == this->set_m_code || gcode->m == this->set_and_wait_m_code ) && gcode->has_letter('S')) { - // this only gets handled if it is not controlled by the tool manager or is active in the toolmanager - this->active = true; - - // this is safe as old configs as well as single extruder configs the toolmanager will not be running so will return false - // this will also ignore anything that the tool manager is not controlling and return false, otherwise it returns the active tool - void *returned_data; - bool ok = PublicData::get_value( tool_manager_checksum, is_active_tool_checksum, this->name_checksum, &returned_data ); - if (ok) { - uint16_t active_tool_name = *static_cast(returned_data); - this->active = (active_tool_name == this->name_checksum); - } - - if(this->active) { + int tool = gcode->has_letter('T') ? gcode->get_value('T') : -1; + // default on when no T, for unmanaged tools (e.g. heatbed) + bool am_tool = (tool == -1) ? true : false; + + if (tool == -1) { + // this is safe as old configs as well as single extruder configs the toolmanager will not be running so will return false + // this will also ignore anything that the tool manager is not controlling and return false, otherwise it returns the active tool + void *returned_data; + bool ok = PublicData::get_value( tool_manager_checksum, is_active_tool_checksum, this->name_checksum, &returned_data ); + if (ok) { + uint16_t active_tool_name = *static_cast(returned_data); + am_tool = (active_tool_name == this->name_checksum); + } + } else { + // FIXME + // this is wrong because we can't get the names of any + // inactive tools to check that we are associated with + // one. Just assume one temperature control per + // tool... + am_tool = (tool == this->pool_index); + } + + if(am_tool) { // required so temp change happens in order - THEKERNEL->conveyor->wait_for_idle(); + // Allow set without wait to be processed immediately + if( gcode->m == this->set_and_wait_m_code ) { + THEKERNEL->conveyor->wait_for_idle(); + } float v = gcode->get_value('S'); diff --git a/src/modules/tools/toolmanager/ToolManager.cpp b/src/modules/tools/toolmanager/ToolManager.cpp index 94a239d8..72e4985d 100644 --- a/src/modules/tools/toolmanager/ToolManager.cpp +++ b/src/modules/tools/toolmanager/ToolManager.cpp @@ -43,8 +43,11 @@ void ToolManager::on_gcode_received(void *argument) { Gcode *gcode = static_cast(argument); - if( gcode->has_letter('T') ) { + if( gcode->has_letter('T') && !gcode->has_m) { int new_tool = gcode->get_value('T'); + char buff[32]; // should be big enough for any status + int n = snprintf(buff, sizeof(buff), "T%d,T%d switching ", this->active_tool, new_tool); + gcode->txt_after_ok.append(buff, n); if(new_tool >= (int)this->tools.size() || new_tool < 0) { // invalid tool char buf[32]; // should be big enough for any status -- 2.20.1