From f9bedc3c947304ce7910191ec12bdf2be772bc74 Mon Sep 17 00:00:00 2001 From: VintagePC <53943260+vintagepc@users.noreply.github.com> Date: Sat, 18 Jun 2022 11:34:44 -0400 Subject: [PATCH] Button handling WIP --- Firmware/mmu2.cpp | 14 +++++++++++++- Firmware/mmu2.h | 1 + Firmware/mmu2_protocol.cpp | 1 + Firmware/mmu2_protocol_logic.cpp | 5 +++++ Firmware/mmu2_protocol_logic.h | 6 ++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index d3fdd3641..25332e631 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -502,12 +502,13 @@ void MMU2::ResumeHotendTemp() { MMU2_ECHO_MSG("Restoring hotend temperature "); SERIAL_ECHOLN(resume_hotend_temp); setTargetHotend(resume_hotend_temp, active_extruder); - lcd_display_message_fullscreen_P(_i("MMU OK. Resuming temperature...")); // better report the event and let the GUI do its work somewhere else + lcd_display_message_fullscreen_P(_i("MMU Retry: Restoring temperature...")); // better report the event and let the GUI do its work somewhere else ReportErrorHookSensorLineRender(); waitForHotendTargetTemp(1000, []{ ReportErrorHookDynamicRender(); }); LogEchoEvent("Hotend temperature reached"); + lcd_clear(); lcd_update_enable(true); // temporary hack to stop this locking the printer... } } @@ -532,6 +533,13 @@ void MMU2::ResumeUnpark() void MMU2::CheckUserInput(){ auto btn = ButtonPressed((uint16_t)lastErrorCode); + + // Was a button pressed on the MMU itself instead of the LCD? + if (btn == Buttons::NoButton && lastButton != Buttons::NoButton) + { + btn = lastButton; + lastButton = Buttons::NoButton; // Clear it. + } switch (btn) { case Left: case Middle: @@ -629,6 +637,10 @@ StepStatus MMU2::LogicStep() { StopKeepPowered(); ReportError(ErrorCode::VERSION_MISMATCH); CheckUserInput(); + case ButtonPushed: + lastButton = logic.Button(); + LogEchoEvent("MMU Button pushed"); + CheckUserInput(); break; default: break; diff --git a/Firmware/mmu2.h b/Firmware/mmu2.h index 93a5ca3aa..aa84c8787 100644 --- a/Firmware/mmu2.h +++ b/Firmware/mmu2.h @@ -225,6 +225,7 @@ private: ProgressCode lastProgressCode = ProgressCode::OK; ErrorCode lastErrorCode = ErrorCode::MMU_NOT_RESPONDING; + Buttons lastButton = Buttons::NoButton; StepStatus logicStepLastStatus; diff --git a/Firmware/mmu2_protocol.cpp b/Firmware/mmu2_protocol.cpp index 6fdf9c1b7..140c4e49b 100644 --- a/Firmware/mmu2_protocol.cpp +++ b/Firmware/mmu2_protocol.cpp @@ -138,6 +138,7 @@ DecodeStatus Protocol::DecodeResponse(uint8_t c) { case 'F': case 'A': case 'R': + case 'B': rspState = ResponseStates::ParamValue; responseMsg.paramCode = (ResponseMsgParamCodes)c; responseMsg.paramValue = 0; diff --git a/Firmware/mmu2_protocol_logic.cpp b/Firmware/mmu2_protocol_logic.cpp index 45fc741fc..a1677d383 100644 --- a/Firmware/mmu2_protocol_logic.cpp +++ b/Firmware/mmu2_protocol_logic.cpp @@ -234,6 +234,11 @@ StepStatus Command::Step() { // - the MMU checks FINDA and fsensor even while recovering from errors SendAndUpdateFilamentSensor(); return CommandError; + case ResponseMsgParamCodes::Button: + // The user pushed a button on the MMU. Save it, do what we need to do + // to prepare, then pass it back to the MMU so it can work its magic. + logic->buttonCode = static_cast(logic->rsp.paramValue); + return ButtonPushed; case ResponseMsgParamCodes::Finished: logic->progressCode = ProgressCode::OK; state = State::Ready; diff --git a/Firmware/mmu2_protocol_logic.h b/Firmware/mmu2_protocol_logic.h index eb8c26834..85632d88c 100644 --- a/Firmware/mmu2_protocol_logic.h +++ b/Firmware/mmu2_protocol_logic.h @@ -16,6 +16,7 @@ public: #include "mmu2/error_codes.h" #include "mmu2/progress_codes.h" +#include "mmu2/buttons.h" #include "mmu2_protocol.h" #include "mmu2_serial.h" @@ -38,6 +39,7 @@ enum StepStatus : uint_fast8_t { CommandError, ///< the command in progress stopped due to unrecoverable error, user interaction required VersionMismatch, ///< the MMU reports its firmware version incompatible with our implementation CommunicationRecovered, + ButtonPushed, ///< The MMU reported the user pushed one of its three buttons. }; @@ -221,6 +223,9 @@ public: /// @returns the current/latest process code as reported by the MMU ProgressCode Progress() const { return progressCode; } + /// @returns the current/latest button code as reported by the MMU + Buttons Button() const { return buttonCode; } + uint8_t CommandInProgress()const; inline bool Running()const { @@ -297,6 +302,7 @@ private: ErrorCode errorCode; ///< last received error code from the MMU ProgressCode progressCode; ///< last received progress code from the MMU + Buttons buttonCode; ///< Last received button from the MMU. uint8_t lastFSensor; ///< last state of filament sensor