temperaturecontrol: allow setting background tool without activating m104_hack
authorClinton Ebadi <clinton@unknownlamer.org>
Fri, 27 Oct 2017 20:27:26 +0000 (16:27 -0400)
committerClinton Ebadi <clinton@unknownlamer.org>
Mon, 26 Nov 2018 02:05:21 +0000 (21:05 -0500)
 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).

src/modules/tools/temperaturecontrol/TemperatureControl.cpp
src/modules/tools/toolmanager/ToolManager.cpp

index 5e163b2..61bafaa 100644 (file)
@@ -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<uint16_t *>(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<uint16_t *>(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');
 
index 94a239d..72e4985 100644 (file)
@@ -43,8 +43,11 @@ void ToolManager::on_gcode_received(void *argument)
 {
     Gcode *gcode = static_cast<Gcode*>(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