Skip to content

Commit

Permalink
Merge pull request #46 from gudnimg/PFW-1375
Browse files Browse the repository at this point in the history
PFW-1375 MMU error reported by MK3S does not appear on LCD
  • Loading branch information
DRracer authored Jul 20, 2022
2 parents 7bf003d + 70cb3c8 commit 45f657e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
14 changes: 7 additions & 7 deletions Firmware/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void MMU2::mmu_loop() {
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((uint16_t)lastErrorCode);
ReportErrorHook((uint16_t)lastErrorCode, mmu2.MMUCurrentErrorCode() == ErrorCode::OK ? ErrorSourcePrinter : ErrorSourceMMU);
}

avoidRecursion = false;
Expand Down Expand Up @@ -728,19 +728,19 @@ StepStatus MMU2::LogicStep() {
OnMMUProgressMsg(logic.Progress());
break;
case CommandError:
ReportError(logic.Error());
ReportError(logic.Error(), ErrorSourceMMU);
break;
case CommunicationTimeout:
state = xState::Connecting;
ReportError(ErrorCode::MMU_NOT_RESPONDING);
ReportError(ErrorCode::MMU_NOT_RESPONDING, ErrorSourcePrinter);
break;
case ProtocolError:
state = xState::Connecting;
ReportError(ErrorCode::PROTOCOL_ERROR);
ReportError(ErrorCode::PROTOCOL_ERROR, ErrorSourcePrinter);
break;
case VersionMismatch:
StopKeepPowered();
ReportError(ErrorCode::VERSION_MISMATCH);
ReportError(ErrorCode::VERSION_MISMATCH, ErrorSourcePrinter);
break;
case ButtonPushed:
lastButton = logic.Button();
Expand Down Expand Up @@ -778,7 +778,7 @@ void MMU2::SetActiveExtruder(uint8_t ex){
active_extruder = ex;
}

void MMU2::ReportError(ErrorCode ec) {
void MMU2::ReportError(ErrorCode ec, uint8_t res) {
// Due to a potential lossy error reporting layers linked to this hook
// we'd better report everything to make sure especially the error states
// do not get lost.
Expand All @@ -805,7 +805,7 @@ void MMU2::ReportError(ErrorCode ec) {
break;
}

ReportErrorHook((uint16_t)ec);
ReportErrorHook((uint16_t)ec, res);

if( ec != lastErrorCode ){ // deduplicate: only report changes in error codes into the log
lastErrorCode = ec;
Expand Down
11 changes: 9 additions & 2 deletions Firmware/mmu2.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ class MMU2 {
Cooldown = 2, // The extruder was allowed to cool.
CooldownPending = 4,
};


/// Source of operation error
enum ReportErrorSource: uint8_t {
ErrorSourcePrinter = 0,
ErrorSourceMMU = 1,
};

/// Perform a reset of the MMU
/// @param level physical form of the reset
void Reset(ResetForm level);
Expand Down Expand Up @@ -199,7 +205,8 @@ class MMU2 {

/// Reports an error into attached ExtUIs
/// @param ec error code, see ErrorCode
void ReportError(ErrorCode ec);
/// @param res reporter error source, is either Printer (0) or MMU (1)
void ReportError(ErrorCode ec, uint8_t res);

/// Reports progress of operations into attached ExtUIs
/// @param pc progress code, see ProgressCode
Expand Down
16 changes: 5 additions & 11 deletions Firmware/mmu2_reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,11 @@ enum class ReportErrorHookStates : uint8_t {

enum ReportErrorHookStates ReportErrorHookState = ReportErrorHookStates::RENDER_ERROR_SCREEN;

/**
* @brief Render MMU error screen on the LCD. This must be non-blocking
* and allow the MMU and printer to communicate with each other.
* @param[in] ec Error code
*/
void ReportErrorHook(uint16_t ec) {

// SERIAL_ECHOPGM("ReportErrorHookState=");
// SERIAL_ECHOLN((int)ReportErrorHookState);

if (mmu2.MMUCurrentErrorCode() == ErrorCode::OK) {
/// @brief Render MMU error screen on the LCD. This must be non-blocking
/// and allow the MMU and printer to communicate with each other.
/// @param[in] ec Error code
void ReportErrorHook(uint16_t ec, uint8_t res) {
if (mmu2.MMUCurrentErrorCode() == ErrorCode::OK && res == MMU2::ErrorSourceMMU) {
// If the error code suddenly changes to OK, that means
// a button was pushed on the MMU and the LCD should
// dismiss the error screen until MMU raises a new error
Expand Down
10 changes: 8 additions & 2 deletions Firmware/mmu2_reporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ void BeginReport(CommandInProgress cip, uint16_t ec);
/// Called at the end of every MMU operation
void EndReport(CommandInProgress cip, uint16_t ec);

/// Called when the MMU sends operation error (even repeatedly)
void ReportErrorHook(uint16_t ec);
/**
* @brief Called when the MMU or MK3S sends operation error (even repeatedly).
* Render MMU error screen on the LCD. This must be non-blocking
* and allow the MMU and printer to communicate with each other.
* @param[in] ec error code
* @param[in] res reporter error source, is either Printer (0) or MMU (1)
*/
void ReportErrorHook(uint16_t ec, uint8_t res);

/// Called when the MMU sends operation progress update
void ReportProgressHook(CommandInProgress cip, uint16_t ec);
Expand Down

0 comments on commit 45f657e

Please sign in to comment.