diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 972fc5cd1..15c42915b 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -196,7 +196,7 @@ void __attribute__((noinline)) MMU2::mmu_loop_inner(bool reportErrors) { 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(), (uint16_t)lastErrorCode, uint8_t(lastErrorSource)); + ReportErrorHook((CommandInProgress)logic.CommandInProgress(), lastErrorCode, uint8_t(lastErrorSource)); } } @@ -218,10 +218,10 @@ struct ReportingRAII { CommandInProgress cip; explicit inline __attribute__((always_inline)) ReportingRAII(CommandInProgress cip) : cip(cip) { - BeginReport(cip, (uint16_t)ProgressCode::EngagingIdler); + BeginReport(cip, ProgressCode::EngagingIdler); } inline __attribute__((always_inline)) ~ReportingRAII() { - EndReport(cip, (uint16_t)ProgressCode::OK); + EndReport(cip, ProgressCode::OK); } }; @@ -1001,7 +1001,7 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { // If retry attempts are all used up // or if 'Retry' operation is not available // raise the MMU error sceen and wait for user input - ReportErrorHook((CommandInProgress)logic.CommandInProgress(), (uint16_t)ec, uint8_t(lastErrorSource)); + ReportErrorHook((CommandInProgress)logic.CommandInProgress(), ec, uint8_t(lastErrorSource)); } static_assert(mmu2Magic[0] == 'M' @@ -1014,8 +1014,8 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { } void MMU2::ReportProgress(ProgressCode pc) { - ReportProgressHook((CommandInProgress)logic.CommandInProgress(), (uint16_t)pc); - LogEchoEvent_P(_O(ProgressCodeToText((uint16_t)pc))); + ReportProgressHook((CommandInProgress)logic.CommandInProgress(), pc); + LogEchoEvent_P(_O(ProgressCodeToText(pc))); } void MMU2::OnMMUProgressMsg(ProgressCode pc) { diff --git a/Firmware/mmu2_progress_converter.cpp b/Firmware/mmu2_progress_converter.cpp index b44951385..29fd0d250 100644 --- a/Firmware/mmu2_progress_converter.cpp +++ b/Firmware/mmu2_progress_converter.cpp @@ -62,10 +62,10 @@ static const char * const progressTexts[] PROGMEM = { _R(MSG_PROGRESS_FEED_FSENSOR) }; -const char * ProgressCodeToText(uint16_t pc){ +const char * ProgressCodeToText(ProgressCode pc){ // @@TODO ?? a better fallback option? - return ( pc <= (sizeof(progressTexts) / sizeof(progressTexts[0])) ) - ? static_cast(pgm_read_ptr(&progressTexts[pc])) + return ( (uint16_t)pc <= (sizeof(progressTexts) / sizeof(progressTexts[0])) ) + ? static_cast(pgm_read_ptr(&progressTexts[(uint16_t)pc])) : static_cast(pgm_read_ptr(&progressTexts[0])); } diff --git a/Firmware/mmu2_progress_converter.h b/Firmware/mmu2_progress_converter.h index b8cd8611b..560cc5f7d 100644 --- a/Firmware/mmu2_progress_converter.h +++ b/Firmware/mmu2_progress_converter.h @@ -1,9 +1,14 @@ #pragma once #include #include +#ifdef __AVR__ + #include "mmu2/progress_codes.h" +#else + #include "../../../../../../Prusa-Firmware-MMU/src/logic/progress_codes.h" +#endif namespace MMU2 { -const char *ProgressCodeToText(uint16_t pc); +const char *ProgressCodeToText(ProgressCode pc); } diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index ddef50c61..844fe5fe5 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -3,6 +3,7 @@ #include "mmu2_log.h" #include "mmu2_reporting.h" #include "mmu2_error_converter.h" +#include "mmu2_progress_converter.h" #include "mmu2/error_codes.h" #include "mmu2/buttons.h" #include "menu.h" @@ -14,14 +15,12 @@ namespace MMU2 { -const char * ProgressCodeToText(uint16_t pc); // we may join progress convertor and reporter together - -void BeginReport(CommandInProgress /*cip*/, uint16_t ec) { +void BeginReport(CommandInProgress /*cip*/, ProgressCode ec) { custom_message_type = CustomMsg::MMUProgress; lcd_setstatuspgm( _T(ProgressCodeToText(ec)) ); } -void EndReport(CommandInProgress /*cip*/, uint16_t /*ec*/) { +void EndReport(CommandInProgress /*cip*/, ProgressCode /*ec*/) { // clear the status msg line - let the printed filename get visible again if (!printJobOngoing()) { lcd_setstatuspgm(MSG_WELCOME); @@ -231,7 +230,7 @@ bool TuneMenuEntered() { return putErrorScreenToSleep; } -void ReportErrorHook(CommandInProgress /*cip*/, uint16_t ec, uint8_t /*es*/) { +void ReportErrorHook(CommandInProgress /*cip*/, ErrorCode ec, uint8_t /*es*/) { if (putErrorScreenToSleep) return; if (mmu2.MMUCurrentErrorCode() == ErrorCode::OK && mmu2.MMULastErrorSource() == MMU2::ErrorSourceMMU) { @@ -289,7 +288,7 @@ void ReportErrorHook(CommandInProgress /*cip*/, uint16_t ec, uint8_t /*es*/) { } } -void ReportProgressHook(CommandInProgress cip, uint16_t ec) { +void ReportProgressHook(CommandInProgress cip, ProgressCode ec) { if (cip != CommandInProgress::NoCommand) { custom_message_type = CustomMsg::MMUProgress; lcd_setstatuspgm( _T(ProgressCodeToText(ec)) ); diff --git a/Firmware/mmu2_reporting.h b/Firmware/mmu2_reporting.h index e26a11ea0..0549db2d6 100644 --- a/Firmware/mmu2_reporting.h +++ b/Firmware/mmu2_reporting.h @@ -2,12 +2,19 @@ #pragma once #include +#ifdef __AVR__ + #include "mmu2/error_codes.h" + #include "mmu2/progress_codes.h" +#else + #include "../../../../../../Prusa-Firmware-MMU/src/logic/error_codes.h" + #include "../../../../../../Prusa-Firmware-MMU/src/logic/progress_codes.h" +#endif namespace MMU2 { enum CommandInProgress : uint8_t { NoCommand = 0, - CutFilament = 'C', + CutFilament = 'K', EjectFilament = 'E', Homing = 'H', LoadFilament = 'L', @@ -17,10 +24,10 @@ enum CommandInProgress : uint8_t { }; /// Called at the begin of every MMU operation -void BeginReport(CommandInProgress cip, uint16_t ec); +void BeginReport(CommandInProgress cip, ProgressCode ec); /// Called at the end of every MMU operation -void EndReport(CommandInProgress cip, uint16_t ec); +void EndReport(CommandInProgress cip, ProgressCode ec); /// Return true if the printer's LCD is drawing the error screen bool isErrorScreenRunning(); @@ -35,10 +42,10 @@ bool TuneMenuEntered(); /// and allow the MMU and printer to communicate with each other. /// @param[in] ec error code /// @param[in] es error source -void ReportErrorHook(CommandInProgress cip, uint16_t ec, uint8_t es); +void ReportErrorHook(CommandInProgress cip, ErrorCode ec, uint8_t es); /// Called when the MMU sends operation progress update -void ReportProgressHook(CommandInProgress cip, uint16_t ec); +void ReportProgressHook(CommandInProgress cip, ProgressCode ec); /// @brief Clear the status line and setup the LCD cursor void TryLoadUnloadProgressbarInit(); @@ -96,4 +103,4 @@ void ScreenClear(); void tuneIdlerStallguardThreshold(); -} // namespace +} // namespace MMU2