소스 검색

Button handling WIP

VintagePC 2 년 전
부모
커밋
f9bedc3c94
5개의 변경된 파일26개의 추가작업 그리고 1개의 파일을 삭제
  1. 13 1
      Firmware/mmu2.cpp
  2. 1 0
      Firmware/mmu2.h
  3. 1 0
      Firmware/mmu2_protocol.cpp
  4. 5 0
      Firmware/mmu2_protocol_logic.cpp
  5. 6 0
      Firmware/mmu2_protocol_logic.h

+ 13 - 1
Firmware/mmu2.cpp

@@ -502,12 +502,13 @@ void MMU2::ResumeHotendTemp() {
         MMU2_ECHO_MSG("Restoring hotend temperature ");
         MMU2_ECHO_MSG("Restoring hotend temperature ");
         SERIAL_ECHOLN(resume_hotend_temp);
         SERIAL_ECHOLN(resume_hotend_temp);
         setTargetHotend(resume_hotend_temp, active_extruder);
         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();
         ReportErrorHookSensorLineRender();
         waitForHotendTargetTemp(1000, []{
         waitForHotendTargetTemp(1000, []{
             ReportErrorHookDynamicRender();
             ReportErrorHookDynamicRender();
         });
         });
         LogEchoEvent("Hotend temperature reached");
         LogEchoEvent("Hotend temperature reached");
+        lcd_clear();
         lcd_update_enable(true); // temporary hack to stop this locking the printer...
         lcd_update_enable(true); // temporary hack to stop this locking the printer...
     }
     }
 }
 }
@@ -532,6 +533,13 @@ void MMU2::ResumeUnpark()
 
 
 void MMU2::CheckUserInput(){
 void MMU2::CheckUserInput(){
     auto btn = ButtonPressed((uint16_t)lastErrorCode);
     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) {
     switch (btn) {
     case Left:
     case Left:
     case Middle:
     case Middle:
@@ -629,6 +637,10 @@ StepStatus MMU2::LogicStep() {
         StopKeepPowered();
         StopKeepPowered();
         ReportError(ErrorCode::VERSION_MISMATCH);
         ReportError(ErrorCode::VERSION_MISMATCH);
         CheckUserInput();
         CheckUserInput();
+    case ButtonPushed:
+        lastButton = logic.Button();
+        LogEchoEvent("MMU Button pushed");
+        CheckUserInput();
         break;
         break;
     default:
     default:
         break;
         break;

+ 1 - 0
Firmware/mmu2.h

@@ -225,6 +225,7 @@ private:
     
     
     ProgressCode lastProgressCode = ProgressCode::OK;
     ProgressCode lastProgressCode = ProgressCode::OK;
     ErrorCode lastErrorCode = ErrorCode::MMU_NOT_RESPONDING;
     ErrorCode lastErrorCode = ErrorCode::MMU_NOT_RESPONDING;
+    Buttons lastButton = Buttons::NoButton;
 
 
     StepStatus logicStepLastStatus;
     StepStatus logicStepLastStatus;
     
     

+ 1 - 0
Firmware/mmu2_protocol.cpp

@@ -138,6 +138,7 @@ DecodeStatus Protocol::DecodeResponse(uint8_t c) {
         case 'F':
         case 'F':
         case 'A':
         case 'A':
         case 'R':
         case 'R':
+        case 'B':
             rspState = ResponseStates::ParamValue;
             rspState = ResponseStates::ParamValue;
             responseMsg.paramCode = (ResponseMsgParamCodes)c;
             responseMsg.paramCode = (ResponseMsgParamCodes)c;
             responseMsg.paramValue = 0;
             responseMsg.paramValue = 0;

+ 5 - 0
Firmware/mmu2_protocol_logic.cpp

@@ -234,6 +234,11 @@ StepStatus Command::Step() {
             // - the MMU checks FINDA and fsensor even while recovering from errors
             // - the MMU checks FINDA and fsensor even while recovering from errors
             SendAndUpdateFilamentSensor();
             SendAndUpdateFilamentSensor();
             return CommandError;
             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<Buttons>(logic->rsp.paramValue);
+            return ButtonPushed;
         case ResponseMsgParamCodes::Finished:
         case ResponseMsgParamCodes::Finished:
             logic->progressCode = ProgressCode::OK;
             logic->progressCode = ProgressCode::OK;
             state = State::Ready;
             state = State::Ready;

+ 6 - 0
Firmware/mmu2_protocol_logic.h

@@ -16,6 +16,7 @@ public:
 
 
 #include "mmu2/error_codes.h"
 #include "mmu2/error_codes.h"
 #include "mmu2/progress_codes.h"
 #include "mmu2/progress_codes.h"
+#include "mmu2/buttons.h"
 #include "mmu2_protocol.h"
 #include "mmu2_protocol.h"
 
 
 #include "mmu2_serial.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
     CommandError, ///< the command in progress stopped due to unrecoverable error, user interaction required
     VersionMismatch, ///< the MMU reports its firmware version incompatible with our implementation
     VersionMismatch, ///< the MMU reports its firmware version incompatible with our implementation
     CommunicationRecovered,
     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
     /// @returns the current/latest process code as reported by the MMU
     ProgressCode Progress() const { return progressCode; }
     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;
     uint8_t CommandInProgress()const;
     
     
     inline bool Running()const {
     inline bool Running()const {
@@ -297,6 +302,7 @@ private:
 
 
     ErrorCode errorCode;       ///< last received error code from the MMU
     ErrorCode errorCode;       ///< last received error code from the MMU
     ProgressCode progressCode; ///< last received progress 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
     uint8_t lastFSensor; ///< last state of filament sensor