Pārlūkot izejas kodu

Tune Interrupted state based on unit tests

Now finally the printer can restart ToolChange if MMU restarted.
D.R.racer 1 gadu atpakaļ
vecāks
revīzija
fe11b7a247
2 mainītis faili ar 19 papildinājumiem un 3 dzēšanām
  1. 6 1
      Firmware/mmu2.cpp
  2. 13 2
      Firmware/mmu2_protocol_logic.cpp

+ 6 - 1
Firmware/mmu2.cpp

@@ -311,7 +311,7 @@ void MMU2::update_tool_change_counter_eeprom() {
     reset_toolchange_counter();
 }
 
-void MMU2::MMU2::ToolChangeCommon(uint8_t slot){
+void MMU2::ToolChangeCommon(uint8_t slot){
     tool_change_extruder = slot;
     do {
         for(;;) {
@@ -320,10 +320,15 @@ void MMU2::MMU2::ToolChangeCommon(uint8_t slot){
                 break;
             // otherwise: failed to perform the command - unload first and then let it run again
             unload();
+            // if we run out of retries, we must do something ... may be raise an error screen and allow the user to do something
+            // but honestly - if the MMU restarts during every toolchange,
+            // something else is seriously broken and stopping a print is probably our best option.
         }
         // reset current position to whatever the planner thinks it is
         plan_set_e_position(current_position[E_AXIS]);
     } while (0); // while not successfully fed into etruder's PTFE tube
+    // when we run out of feeding retries, we should call an unload + cut before trying again.
+    // + we need some error screen report
 
     extruder = slot; //filament change is finished
     SpoolJoin::spooljoin.setSlot(slot);

+ 13 - 2
Firmware/mmu2_protocol_logic.cpp

@@ -347,9 +347,12 @@ StepStatus ProtocolLogic::ProcessCommandQueryResponse() {
         if( ReqMsg().code == rsp.request.code && ReqMsg().value == rsp.request.value ){
             progressCode = ProgressCode::OK;
             scopeState = ScopeState::Ready;
+            rq = RequestMsg(RequestMsgCodes::unknown, 0); // clear the successfully finished request
             return Finished;
         } else {
             // got response to some other command - the originally issued command was interrupted!
+            static const char intr[] PROGMEM = "Intr2"; // @@TODO clean up
+            MMU2_ERROR_MSGRPGM(intr);
             return Interrupted;
         }
     default:
@@ -437,11 +440,19 @@ StepStatus ProtocolLogic::IdleStep() {
                 buttonCode = static_cast<Buttons>(rsp.paramValue);
                 StartReading8bitRegisters();
                 return ButtonPushed;
+            case ResponseMsgParamCodes::Finished:
+                if( ReqMsg().code != RequestMsgCodes::unknown ){
+                    // got reset while doing some other command - the originally issued command was interrupted!
+                    // this must be solved by the upper layer, protocol logic doesn't have all the context (like unload before trying again)
+                    static const char intr[] PROGMEM = "Intr1"; // @@TODO cleanup
+                    MMU2_ERROR_MSGRPGM(intr);
+                    IdleRestart();
+                    return Interrupted;
+                }
+                [[fallthrough]];
             case ResponseMsgParamCodes::Processing:
                 // @@TODO we may actually use this branch to report progress of manual operation on the MMU
                 // The MMU sends e.g. X0 P27 after its restart when the user presses an MMU button to move the Selector
-                // For now let's behave just like "finished"
-            case ResponseMsgParamCodes::Finished:
                 errorCode = ErrorCode::OK;
                 break;
             default: