From 69c39e2281bc6d2aacaca49ce38c5b471b605ec7 Mon Sep 17 00:00:00 2001 From: VintagePC <53943260+vintagepc@users.noreply.github.com> Date: Sun, 26 Jun 2022 13:58:25 -0400 Subject: [PATCH] An attempt at fixing the retry. Discussion needed. --- Firmware/mmu2.cpp | 28 ++++++++++++++++++++++++---- Firmware/mmu2.h | 9 +++++++-- Firmware/mmu2_protocol_logic.cpp | 13 +++++++++---- Firmware/mmu2_reporting.cpp | 1 - 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index cf5f353a9..503de8417 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -112,6 +112,7 @@ MMU2::MMU2() , loadFilamentStarted(false) , unloadFilamentStarted(false) , loadingToNozzle(false) + , inAutoRetry(false) { ResetRetryAttempts(); } @@ -230,11 +231,14 @@ bool MMU2::RetryIfPossible(uint16_t ec){ SetButtonResponse(ButtonOperations::Retry); // check, that Retry is actually allowed on that operation if( ButtonAvailable(ec) != NoButton ){ + inAutoRetry = true; SERIAL_ECHOLNPGM("RetryButtonPressed"); - --retryAttempts; // "used" one retry attempt + // We don't decrement until the button is acknowledged by the MMU. + //--retryAttempts; // "used" one retry attempt return true; } } + inAutoRetry = false; return false; } @@ -243,6 +247,14 @@ void MMU2::ResetRetryAttempts(){ retryAttempts = 3; } +void MMU2::DecrementRetryAttempts(){ + if (inAutoRetry && retryAttempts) + { + SERIAL_ECHOLNPGM("DecrementRetryAttempts"); + retryAttempts--; + } +} + bool MMU2::tool_change(uint8_t index) { if( ! WaitForMMUReady()) return false; @@ -607,7 +619,8 @@ void MMU2::CheckUserInput(){ case Left: case Middle: case Right: - SERIAL_ECHOLNPGM("CheckUserInput-btnLMR"); + SERIAL_ECHOPGM("CheckUserInput-btnLMR "); + SERIAL_ECHOLN(btn); ResumeHotendTemp(); // Recover the hotend temp before we attempt to do anything else... Button(btn); break; @@ -655,7 +668,7 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) { if (!nozzleTimeout.running()) { nozzleTimeout.start(); - LogEchoEvent(" Cooling Timeout started"); + LogEchoEvent("Cooling Timeout started"); } else if (nozzleTimeout.expired(DEFAULT_SAFETYTIMER_TIME_MINS*60*1000ul)) // mins->msec. TODO: do we use the global or have our own independent timeout { @@ -676,13 +689,20 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) { // command/operation completed, let Marlin continue its work // the E may have some more moves to finish - wait for them ResumeUnpark(); // We can now travel back to the tower or wherever we were when we saved. + ResetRetryAttempts(); // Reset the retry counter. st_synchronize(); return; case VersionMismatch: // this basically means the MMU will be disabled until reconnected CheckUserInput(); return; - case CommunicationTimeout: case CommandError: + // Don't proceed to the park/save if we are doing an autoretry. + if (inAutoRetry) + { + continue; + } + /* FALLTHRU */ + case CommunicationTimeout: case ProtocolError: SaveAndPark(move_axes, turn_off_nozzle); // and wait for the user to resolve the problem CheckUserInput(); diff --git a/Firmware/mmu2.h b/Firmware/mmu2.h index 75091e1ed..6113d45fa 100644 --- a/Firmware/mmu2.h +++ b/Firmware/mmu2.h @@ -168,10 +168,13 @@ public: /// Automagically "press" a Retry button if we have any retry attempts left bool RetryIfPossible(uint16_t ec); - /// Reset the retryAttempts back to the default value - void ResetRetryAttempts(); + /// Decrement the retry attempts, if in a retry. + // Called by the MMU protocol when a sent button is acknowledged. + void DecrementRetryAttempts(); private: + /// Reset the retryAttempts back to the default value + void ResetRetryAttempts(); /// Perform software self-reset of the MMU (sends an X0 command) void ResetX0(); @@ -261,6 +264,8 @@ private: bool loadingToNozzle; uint8_t retryAttempts; + + bool inAutoRetry; }; /// following Marlin's way of doing stuff - one and only instance of MMU implementation in the code base diff --git a/Firmware/mmu2_protocol_logic.cpp b/Firmware/mmu2_protocol_logic.cpp index ca5de501e..b1cc8f493 100644 --- a/Firmware/mmu2_protocol_logic.cpp +++ b/Firmware/mmu2_protocol_logic.cpp @@ -261,10 +261,15 @@ StepStatus Command::Step() { return ProcessFINDAReqSent(Processing, State::Wait); case State::ButtonSent:{ // button is never confirmed ... may be it should be - // auto expmsg = logic->ExpectingMessage(linkLayerTimeout); - // if (expmsg != MessageReady) - // return expmsg; - SendQuery(); + auto expmsg = logic->ExpectingMessage(linkLayerTimeout); + if (expmsg != MessageReady) + return expmsg; + if (logic->rsp.paramCode == ResponseMsgParamCodes::Accepted) + { + // Button was accepted, decrement the retry. + mmu2.DecrementRetryAttempts(); + } + SendAndUpdateFilamentSensor(); } break; default: return ProtocolError; diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index 8f2127394..db4c0de08 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -205,7 +205,6 @@ void ReportErrorHook(uint16_t ec, uint8_t res) { // a button was pushed on the MMU and the LCD should // dismiss the error screen until MMU raises a new error ReportErrorHookState = ReportErrorHookStates::DISMISS_ERROR_SCREEN; - mmu2.ResetRetryAttempts(); } else { // attempt an automatic Retry button if( ReportErrorHookState == ReportErrorHookStates::MONITOR_SELECTION ){