From 4888e650eae1dbb0f10ec03703cde08245994cc5 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Tue, 25 Jan 2022 06:16:25 -0500 Subject: [PATCH] Fix lack of keys on standalone MMU2 (#354) * Fix lack of keys on standalone MMU2 * Add FINDA control as actions --- parts/Board.h | 20 ++++++++------- parts/components/MMU2.cpp | 38 +++++++++++++++++++++++++--- parts/components/MMU2.h | 16 ++++++++++-- parts/printers/Prusa_MMU2.cpp | 29 +-------------------- parts/printers/Prusa_MMU2.h | 14 +++------- scripts/tests/snaps/ext1/MMU2F1.png | Bin 0 -> 123 bytes scripts/tests/snaps/ext1/MMU2F2.png | Bin 0 -> 126 bytes scripts/tests/snaps/ext1/MMU2F3.png | Bin 0 -> 123 bytes scripts/tests/snaps/ext1/MMU2F4.png | Bin 0 -> 126 bytes scripts/tests/test_boot_mmu2.txt | 14 ++++++++++ 10 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 scripts/tests/snaps/ext1/MMU2F1.png create mode 100644 scripts/tests/snaps/ext1/MMU2F2.png create mode 100644 scripts/tests/snaps/ext1/MMU2F3.png create mode 100644 scripts/tests/snaps/ext1/MMU2F4.png diff --git a/parts/Board.h b/parts/Board.h index 31150841..c7509bcb 100644 --- a/parts/Board.h +++ b/parts/Board.h @@ -155,6 +155,17 @@ namespace Boards // Whether any vendor-specific hackery should be disabled. bool m_bNoHacks = false; + enum ScriptAction + { + Quit, + Reset, + Wait, + Pause, + Unpause, + WaitReset, + BOARD_ACT_END + }; + private: #ifdef TEST_MODE @@ -198,15 +209,6 @@ namespace Boards avr_flashaddr_t m_bootBase{0}, m_FWBase{0}; // Loads an ELF or HEX file into the MCU. Returns boot PC - enum ScriptAction - { - Quit, - Reset, - Wait, - Pause, - Unpause, - WaitReset - }; EEPROM m_EEPROM; }; diff --git a/parts/components/MMU2.cpp b/parts/components/MMU2.cpp index 7b5a004d..0c114cda 100644 --- a/parts/components/MMU2.cpp +++ b/parts/components/MMU2.cpp @@ -40,7 +40,7 @@ MMU2 *MMU2::g_pMMU = nullptr; using Boards::MM_Control_01; -MMU2::MMU2():IKeyClient(),MM_Control_01() +MMU2::MMU2(bool bCreate):IKeyClient(),MM_Control_01() { if (g_pMMU) { @@ -49,10 +49,15 @@ MMU2::MMU2():IKeyClient(),MM_Control_01() } g_pMMU = this; SetBoardName("MMU2"); - CreateBoard(Config::Get().GetFW2(),0, false, 100,""); - + if (bCreate) + { + CreateBoard(Config::Get().GetFW2(),0, false, 100,""); + } RegisterKeyHandler('F',"Toggle the FINDA"); RegisterKeyHandler('A', "Resumes full-auto MMU mode."); + RegisterActionAndMenu("ToggleFINDA","Toggles the FINDA", ActToggleFINDA); + RegisterActionAndMenu("SetFINDAAuto", "Returns FINDA operation to automatic", ActSetFINDAAuto); + RegisterAction("SetFINDA", "Sets FINDA state", ActSetFINDA, {ArgType::Bool}); } void MMU2::OnKeyPress(const Key& key) @@ -76,6 +81,33 @@ void MMU2::OnKeyPress(const Key& key) } } +IScriptable::LineStatus MMU2::ProcessAction(unsigned int iAction, const std::vector &vArgs) +{ + switch (iAction) + { + case ActToggleFINDA: + m_bAutoFINDA = false; + ToggleFINDA(); + return LineStatus::Finished; + case ActSetFINDA: + { + m_bAutoFINDA = false; + bool bState = std::stoi(vArgs.at(0))!=0; + if (m_bFINDAManual != bState) + { + ToggleFINDA(); + } + return LineStatus::Finished; + } + case ActSetFINDAAuto: + m_bAutoFINDA = true; + return LineStatus::Finished; + default: + return Board::ProcessAction(iAction, vArgs); + } +} + + const std::string MMU2::GetSerialPort() { return m_UART.GetSlaveName(); diff --git a/parts/components/MMU2.h b/parts/components/MMU2.h index 467e9ae0..8d2cc9c2 100644 --- a/parts/components/MMU2.h +++ b/parts/components/MMU2.h @@ -24,6 +24,7 @@ #include "ADC_Buttons.h" #include "BasePeripheral.h" // for BasePeripheral #include "IKeyClient.h" +#include "IScriptable.h" #include "boards/MM_Control_01.h" // for MM_Control_01 #include "sim_irq.h" // for avr_irq_t #include @@ -41,8 +42,8 @@ class MMU2: public BasePeripheral, public Boards::MM_Control_01, virtual private _IRQ(SHIFT_IN,"<32shift.in") #include "IRQHelper.h" - // Creates a new MMU2. Does all of the setup and firmware load. - MMU2(); + // Creates a new MMU2. Creates board and starts it if bCreate = true + explicit MMU2(bool bCreate = true); ~MMU2() override {StopAVR();} @@ -53,6 +54,17 @@ class MMU2: public BasePeripheral, public Boards::MM_Control_01, virtual private void ToggleFINDA(); protected: + enum Actions + { + // We have to extend board rather than being our own IScriptable due + // to it causing multiple-inheritance ambiguity. + ActToggleFINDA = Board::ScriptAction::BOARD_ACT_END, + ActSetFINDA, + ActSetFINDAAuto + }; + + LineStatus ProcessAction(unsigned int iAction, const std::vector &args) override; + void SetupHardware() override; void OnKeyPress(const Key& key) override; diff --git a/parts/printers/Prusa_MMU2.cpp b/parts/printers/Prusa_MMU2.cpp index c9ecdd17..5a5226e4 100644 --- a/parts/printers/Prusa_MMU2.cpp +++ b/parts/printers/Prusa_MMU2.cpp @@ -17,14 +17,6 @@ #include "Prusa_MMU2.h" #include "GLHelper.h" #include "MK3SGL.h" -#include "MMU2.h" - -// void Prusa_MMU2::SetupHardware() -// { -// _Init(Board::m_pAVR,this); -// m_MMU.StartAVR(); -// } - std::pair Prusa_MMU2::GetWindowSize() { @@ -35,26 +27,7 @@ std::pair Prusa_MMU2::GetWindowSize() void Prusa_MMU2::Draw() { glScalef(50.F/35.F,4,1); - MM_Control_01::Draw(static_cast(GetWindowSize().second)); + MMU2::Draw(static_cast(GetWindowSize().second)); m_gl.OnDraw(); } -void Prusa_MMU2::OnVisualTypeSet(const std::string& /*type*/ ) -{ - // if (type=="lite") - // { - // m_pVis.reset(new MK3SGL(type,true,this)); //NOLINT - suggestion is c++14. - // AddHardware(*m_pVis); - // } - - - // Wire up the additional MMU stuff. - - //AddHardware(m_sniffer,'2'); - //m_pVis->ConnectFrom(m_sniffer.GetIRQ(GCodeSniffer::CODEVAL_OUT),MK3SGL::TOOL_IN); - //m_pVis->ConnectFrom(GetIRQ(MMU2::SELECTOR_OUT), MK3SGL::SEL_IN); - //m_pVis->ConnectFrom(GetIRQ(MMU2::IDLER_OUT), MK3SGL::IDL_IN); - //m_pVis->ConnectFrom(GetIRQ(MMU2::LEDS_OUT),MK3SGL::MMU_LEDS_IN); - //m_pVis->ConnectFrom(GetIRQ(MMU2::FINDA_OUT),MK3SGL::FINDA_IN); - //m_pVis->ConnectFrom(GetIRQ(MMU2::FEED_DISTANCE), MK3SGL::FEED_IN); -} diff --git a/parts/printers/Prusa_MMU2.h b/parts/printers/Prusa_MMU2.h index de1c8234..b215f1a8 100644 --- a/parts/printers/Prusa_MMU2.h +++ b/parts/printers/Prusa_MMU2.h @@ -17,33 +17,27 @@ #pragma once #include "GCodeSniffer.h" +#include "MMU2.h" #include "Printer.h" -#include "boards/MM_Control_01.h" #include class MK3SGL; #include // for pair -class Prusa_MMU2 : public Printer, public Boards::MM_Control_01 +class Prusa_MMU2 : public Printer, public MMU2 { public: - inline std::pair GetWindowSize() override; + Prusa_MMU2():MMU2(false){}; - void OnVisualTypeSet(const std::string &type) override; - //void SetupHardware() override; + inline std::pair GetWindowSize() override; void Draw() override; - //zinline bool GetHasMMU() override {return true;} - - protected: - // GCodeSniffer m_sniffer = GCodeSniffer('T'); - std::unique_ptr m_pVis {nullptr}; }; diff --git a/scripts/tests/snaps/ext1/MMU2F1.png b/scripts/tests/snaps/ext1/MMU2F1.png new file mode 100644 index 0000000000000000000000000000000000000000..f038f9f17868368d3898cf477e9093a7ba39e47b GIT binary patch literal 123 zcmeAS@N?(olHy`uVBq!ia0vp^qCl+7!2~3~gk38HQcj*Ojv*eM$$yHw8ifwHOnevk zcgm~ugPMtL{?azr3SYU0wXpMS`S1Rfe@$J@OLkq(BwxS9FY`nGJG@GlS^K|jOC3Wh WBX_EDBbyh{GzL#sKbLh*2~7YX@+wIH literal 0 HcmV?d00001 diff --git a/scripts/tests/snaps/ext1/MMU2F2.png b/scripts/tests/snaps/ext1/MMU2F2.png new file mode 100644 index 0000000000000000000000000000000000000000..cb6a0eddc55a7c226fd3f22ce708a3cb11278a3b GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^qCl+7!2~3~gk38HQm&pZjv*eM$x}oU7qA!vE~yT& zU-~Puz|*GsuYA9mW}q9>uZf}$8JXYy5B$r#T0Z`lqjyupuZf}$8JXYy5B$r#T0Z`lqjyup