From fe11b7a247e61597c5b51e7025ab54b09c965729 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Fri, 18 Nov 2022 17:31:46 +0100 Subject: [PATCH] Tune Interrupted state based on unit tests Now finally the printer can restart ToolChange if MMU restarted. --- Firmware/mmu2.cpp | 7 ++++++- Firmware/mmu2_protocol_logic.cpp | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 84dfdd603..a991dc8df 100644 --- a/Firmware/mmu2.cpp +++ b/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); diff --git a/Firmware/mmu2_protocol_logic.cpp b/Firmware/mmu2_protocol_logic.cpp index f3720bf45..e2c368518 100644 --- a/Firmware/mmu2_protocol_logic.cpp +++ b/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(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: