Perform 3xRetry automatically

This is a draft PR showing the potential 3x retry implementation on the printer's side.
It is much less code and looks more reliable than the same functionality in the MMU FW.

Still, more work needs to be done:
- [ ] Button is sent to the MMU even before returning from the parking position
- [ ] Then the button is sent again
- [ ] Then the printer runs out of retryAttempts

We need to find a better spot to check for "automatic" retry and issuing of the buttons
This commit is contained in:
D.R.racer 2022-06-23 14:53:32 +02:00
parent 999320f671
commit c412f062c8
5 changed files with 49 additions and 4 deletions

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);