Merge pull request #4454 from gudnimg/mmu-sync

MMU: Backport code changes from 32-bit firmware
This commit is contained in:
Guðni Már Gilbert 2023-10-23 06:31:06 +00:00 committed by GitHub
commit e7f56118d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 62 additions and 38 deletions

View File

@ -55,7 +55,7 @@ MMU2::MMU2()
void MMU2::Start() {
mmu2Serial.begin(MMU_BAUD);
PowerOn(); // I repurposed this to serve as our EEPROM disable toggle.
PowerOn();
mmu2Serial.flush(); // make sure the UART buffer is clear before starting communication
extruder = MMU2_NO_TOOL;
@ -63,13 +63,13 @@ void MMU2::Start() {
// start the communication
logic.Start();
logic.ResetRetryAttempts();
logic.ResetCommunicationTimeoutAttempts();
}
void MMU2::Stop() {
StopKeepPowered();
PowerOff(); // This also disables the MMU in the EEPROM.
PowerOff();
}
void MMU2::StopKeepPowered() {
@ -125,11 +125,9 @@ void MMU2::TriggerResetPin() {
void MMU2::PowerCycle() {
// cut the power to the MMU and after a while restore it
// Sadly, MK3/S/+ cannot do this
// NOTE: the below will toggle the EEPROM var. Should we
// assert this function is never called in the MK3 FW? Do we even care?
PowerOff();
Stop();
safe_delay_keep_alive(1000);
PowerOn();
Start();
}
void MMU2::PowerOff() {
@ -191,12 +189,7 @@ void MMU2::mmu_loop() {
void __attribute__((noinline)) MMU2::mmu_loop_inner(bool reportErrors) {
logicStepLastStatus = LogicStep(reportErrors); // it looks like the mmu_loop doesn't need to be a blocking call
if (isErrorScreenRunning()) {
// Call this every iteration to keep the knob rotation responsive
// This includes when mmu_loop is called within manage_response
ReportErrorHook((CommandInProgress)logic.CommandInProgress(), lastErrorCode, uint8_t(lastErrorSource));
}
CheckErrorScreenUserInput();
}
void MMU2::CheckFINDARunout() {
@ -740,7 +733,8 @@ void MMU2::CheckUserInput() {
// ... but mmu2_power.cpp knows this and triggers a soft-reset instead.
break;
case Buttons::DisableMMU:
Stop(); // Poweroff handles updating the EEPROM shutoff.
Stop();
DisableMMUInSettings();
break;
case Buttons::StopPrint:
// @@TODO not sure if we shall handle this high level operation at this spot
@ -840,45 +834,58 @@ bool MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
}
StepStatus MMU2::LogicStep(bool reportErrors) {
CheckUserInput(); // Process any buttons before proceeding with another MMU Query
StepStatus ss = logic.Step();
// Process any buttons before proceeding with another MMU Query
CheckUserInput();
const StepStatus ss = logic.Step();
switch (ss) {
case Finished:
// At this point it is safe to trigger a runout and not interrupt the MMU protocol
CheckFINDARunout();
break;
case Processing:
OnMMUProgressMsg(logic.Progress());
break;
case ButtonPushed:
lastButton = logic.Button();
LogEchoEvent_P(PSTR("MMU Button pushed"));
CheckUserInput(); // Process the button immediately
break;
case Interrupted:
// can be silently handed over to a higher layer, no processing necessary at this spot
break;
default:
if (reportErrors) {
switch (ss) {
case CommandError:
ReportError(logic.Error(), ErrorSourceMMU);
break;
case CommunicationTimeout:
state = xState::Connecting;
ReportError(ErrorCode::MMU_NOT_RESPONDING, ErrorSourcePrinter);
break;
case ProtocolError:
state = xState::Connecting;
ReportError(ErrorCode::PROTOCOL_ERROR, ErrorSourcePrinter);
break;
case VersionMismatch:
StopKeepPowered();
ReportError(ErrorCode::VERSION_MISMATCH, ErrorSourcePrinter);
break;
case PrinterError:
ReportError(logic.PrinterError(), ErrorSourcePrinter);
break;
default:
break;
}
@ -888,6 +895,7 @@ StepStatus MMU2::LogicStep(bool reportErrors) {
if (logic.Running()) {
state = xState::Active;
}
return ss;
}

View File

@ -160,9 +160,15 @@ public:
/// @returns Current error code
inline ErrorCode MMUCurrentErrorCode() const { return logic.Error(); }
/// @returns Command in progress
inline uint8_t GetCommandInProgress() const { return logic.CommandInProgress(); }
/// @returns Last error source
inline ErrorSource MMULastErrorSource() const { return lastErrorSource; }
/// @returns Last error code
inline ErrorCode GetLastErrorCode() const { return lastErrorCode; }
/// @returns the version of the connected MMU FW.
/// In the future we'll return the trully detected FW version
Version GetMMUFWVersion() const {

View File

@ -186,20 +186,15 @@ const char * PrusaErrorButtonMore(){
return MSG_BTN_MORE;
}
struct ResetOnExit {
ResetOnExit() = default;
~ResetOnExit(){
buttonSelectedOperation = ButtonOperations::NoOperation;
}
};
Buttons ButtonPressed(ErrorCode ec) {
if (buttonSelectedOperation == ButtonOperations::NoOperation) {
return Buttons::NoButton; // no button
}
ResetOnExit ros; // clear buttonSelectedOperation on exit from this call
return ButtonAvailable(ec);
const auto result = ButtonAvailable(ec);
buttonSelectedOperation = ButtonOperations::NoOperation; // Reset operation
return result;
}
Buttons ButtonAvailable(ErrorCode ec) {

View File

@ -4,25 +4,20 @@
#include "fastio.h"
#include <util/delay.h>
#include "mmu2.h"
#include "eeprom.h"
namespace MMU2 {
// sadly, on MK3 we cannot do actual power cycle on HW...
// so we just block the MMU via EEPROM var instead.
// On MK3 we cannot do actual power cycle on HW. Instead trigger a hardware reset.
void power_on() {
#ifdef MMU_HWRESET
WRITE(MMU_RST_PIN, 1);
SET_OUTPUT(MMU_RST_PIN); // setup reset pin
#endif //MMU_HWRESET
eeprom_update_byte((uint8_t *)EEPROM_MMU_ENABLED, true);
reset();
}
void power_off() {
eeprom_update_byte((uint8_t *)EEPROM_MMU_ENABLED, false);
}
void reset() {

View File

@ -256,7 +256,7 @@ StepStatus ProtocolLogic::ProcessVersionResponse(uint8_t stage) {
SendVersion(stage);
}
} else {
dataTO.Reset(); // got a meaningful response from the MMU, stop data layer timeout tracking
ResetCommunicationTimeoutAttempts(); // got a meaningful response from the MMU, stop data layer timeout tracking
SendVersion(stage + 1);
}
}
@ -774,7 +774,7 @@ void ProtocolLogic::LogResponse() {
StepStatus ProtocolLogic::SuppressShortDropOuts(const char *msg_P, StepStatus ss) {
if (dataTO.Record(ss)) {
LogError(msg_P);
dataTO.Reset(); // prepare for another run of consecutive retries before firing an error
ResetCommunicationTimeoutAttempts(); // prepare for another run of consecutive retries before firing an error
return dataTO.InitialCause();
} else {
return Processing; // suppress short drop outs of communication
@ -865,6 +865,11 @@ void ProtocolLogic::ResetRetryAttempts() {
retryAttempts = MAX_RETRIES;
}
void __attribute__((noinline)) ProtocolLogic::ResetCommunicationTimeoutAttempts() {
SERIAL_ECHOLNPGM("RSTCommTimeout");
dataTO.Reset();
}
bool DropOutFilter::Record(StepStatus ss) {
if (occurrences == maxOccurrences) {
cause = ss;

View File

@ -186,6 +186,8 @@ public:
/// Reset the retryAttempts back to the default value
void ResetRetryAttempts();
void ResetCommunicationTimeoutAttempts();
constexpr bool InAutoRetry() const { return inAutoRetry; }
void SetInAutoRetry(bool iar) {
inAutoRetry = iar;

View File

@ -1,4 +1,5 @@
#include <avr/pgmspace.h>
#include "eeprom.h"
#include "mmu2.h"
#include "mmu2_log.h"
#include "mmu2_reporting.h"
@ -221,8 +222,12 @@ static bool is_mmu_error_monitor_active;
// Set to false to allow the error screen to render again.
static bool putErrorScreenToSleep;
bool isErrorScreenRunning() {
return is_mmu_error_monitor_active;
void CheckErrorScreenUserInput() {
if (is_mmu_error_monitor_active) {
// Call this every iteration to keep the knob rotation responsive
// This includes when mmu_loop is called within manage_response
ReportErrorHook((CommandInProgress)mmu2.GetCommandInProgress(), mmu2.GetLastErrorCode(), mmu2.MMULastErrorSource());
}
}
bool TuneMenuEntered() {
@ -336,6 +341,11 @@ void TryLoadUnloadReporter::DumpToSerial(){
MMU2_ECHO_MSGLN(buf);
}
/// Disables MMU in EEPROM
void DisableMMUInSettings() {
eeprom_update_byte((uint8_t *)EEPROM_MMU_ENABLED, false);
}
void IncrementLoadFails(){
eeprom_increment_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL);
eeprom_increment_word((uint16_t *)EEPROM_MMU_LOAD_FAIL_TOT);

View File

@ -29,8 +29,8 @@ void BeginReport(CommandInProgress cip, ProgressCode ec);
/// Called at the end of every MMU operation
void EndReport(CommandInProgress cip, ProgressCode ec);
/// Return true if the printer's LCD is drawing the error screen
bool isErrorScreenRunning();
/// Checks for error screen user input, if the error screen is open
void CheckErrorScreenUserInput();
/// Return true if the error screen is sleeping in the background
/// Error screen sleeps when the firmware is rendering complementary
@ -81,6 +81,9 @@ bool MMUAvailable();
/// Global Enable/Disable use MMU (to be stored in EEPROM)
bool UseMMU();
/// Disables MMU in EEPROM
void DisableMMUInSettings();
/// Increments EEPROM cell - number of failed loads into the nozzle
/// Note: technically, this is not an MMU error but an error of the printer.
void IncrementLoadFails();