diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 1c47eab24..cf5f353a9 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -113,6 +113,7 @@ MMU2::MMU2() , unloadFilamentStarted(false) , loadingToNozzle(false) { + ResetRetryAttempts(); } void MMU2::Start() { @@ -223,6 +224,25 @@ bool MMU2::WaitForMMUReady(){ } } +bool MMU2::RetryIfPossible(uint16_t ec){ + if( retryAttempts ){ + SERIAL_ECHOPGM("retryAttempts=");SERIAL_ECHOLN((uint16_t)retryAttempts); + SetButtonResponse(ButtonOperations::Retry); + // check, that Retry is actually allowed on that operation + if( ButtonAvailable(ec) != NoButton ){ + SERIAL_ECHOLNPGM("RetryButtonPressed"); + --retryAttempts; // "used" one retry attempt + return true; + } + } + return false; +} + +void MMU2::ResetRetryAttempts(){ + SERIAL_ECHOLNPGM("ResetRetryAttempts"); + retryAttempts = 3; +} + bool MMU2::tool_change(uint8_t index) { if( ! WaitForMMUReady()) return false; @@ -484,6 +504,7 @@ bool MMU2::eject_filament(uint8_t index, bool recover) { } void MMU2::Button(uint8_t index){ + SERIAL_ECHOLNPGM("Button"); logic.Button(index); } @@ -586,6 +607,7 @@ void MMU2::CheckUserInput(){ case Left: case Middle: case Right: + SERIAL_ECHOLNPGM("CheckUserInput-btnLMR"); ResumeHotendTemp(); // Recover the hotend temp before we attempt to do anything else... Button(btn); break; diff --git a/Firmware/mmu2.h b/Firmware/mmu2.h index 6731147b6..75091e1ed 100644 --- a/Firmware/mmu2.h +++ b/Firmware/mmu2.h @@ -165,6 +165,12 @@ public: /// Method to read-only mmu_print_saved bool MMU_PRINT_SAVED() const { return mmu_print_saved != SavedState::None; } + /// 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(); + private: /// Perform software self-reset of the MMU (sends an X0 command) void ResetX0(); @@ -222,13 +228,13 @@ private: /// Check for any button/user input coming from the printer's UI void CheckUserInput(); - + /// Entry check of all external commands. /// It can wait until the MMU becomes ready. /// Optionally, it can also emit/display an error screen and the user can decide what to do next. /// @returns false if the MMU is not ready to perform the command (for whatever reason) bool WaitForMMUReady(); - + ProtocolLogic logic; ///< implementation of the protocol logic layer int extruder; ///< currently active slot in the MMU ... somewhat... not sure where to get it from yet uint8_t previous_extruder; ///< last active slot in the MMU, useful for M600 @@ -254,7 +260,7 @@ private: /// unlike the mid-print ToolChange commands, which only load the first ~30mm and then the G-code takes over. bool loadingToNozzle; - + uint8_t retryAttempts; }; /// following Marlin's way of doing stuff - one and only instance of MMU implementation in the code base diff --git a/Firmware/mmu2_error_converter.cpp b/Firmware/mmu2_error_converter.cpp index a450e848c..b035a628d 100644 --- a/Firmware/mmu2_error_converter.cpp +++ b/Firmware/mmu2_error_converter.cpp @@ -166,7 +166,10 @@ Buttons ButtonPressed(uint16_t ec) { } ResetOnExit ros; // clear buttonSelectedOperation on exit from this call - + return ButtonAvailable(ec); +} + +Buttons ButtonAvailable(uint16_t ec) { uint8_t ei = PrusaErrorCodeIndex(ec); // The list of responses which occur in mmu error dialogs diff --git a/Firmware/mmu2_error_converter.h b/Firmware/mmu2_error_converter.h index 27dbfbce5..597cc35a5 100644 --- a/Firmware/mmu2_error_converter.h +++ b/Firmware/mmu2_error_converter.h @@ -37,6 +37,12 @@ const char * const PrusaErrorButtonMore(); void SetButtonResponse(ButtonOperations rsp); /// @returns button index/code based on currently processed error/screen +/// Clears the "pressed" button upon exit Buttons ButtonPressed(uint16_t ec); +/// @returns button index/code based on currently processed error/screen +/// Used as a subfunction of ButtonPressed. +/// Does not clear the "pressed" button upon exit +Buttons ButtonAvailable(uint16_t ec); + } // namespace MMU2 diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index 3ba935da1..8f2127394 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -205,6 +205,14 @@ 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 ){ + if( mmu2.RetryIfPossible(ec) ){ + ReportErrorHookState = ReportErrorHookStates::DISMISS_ERROR_SCREEN; + } + } } const uint8_t ei = PrusaErrorCodeIndex(ec);