Skip to content

Commit

Permalink
Fix lack of keys on standalone MMU2 (#354)
Browse files Browse the repository at this point in the history
* Fix lack of keys on standalone MMU2

* Add FINDA control as actions
  • Loading branch information
vintagepc authored Jan 25, 2022
1 parent 8d86fc8 commit 4888e65
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 52 deletions.
20 changes: 11 additions & 9 deletions parts/Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
Expand Down
38 changes: 35 additions & 3 deletions parts/components/MMU2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand All @@ -76,6 +81,33 @@ void MMU2::OnKeyPress(const Key& key)
}
}

IScriptable::LineStatus MMU2::ProcessAction(unsigned int iAction, const std::vector<std::string> &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();
Expand Down
16 changes: 14 additions & 2 deletions parts/components/MMU2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <atomic>
Expand All @@ -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();}

Expand All @@ -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<std::string> &args) override;

void SetupHardware() override;

void OnKeyPress(const Key& key) override;
Expand Down
29 changes: 1 addition & 28 deletions parts/printers/Prusa_MMU2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int,int> Prusa_MMU2::GetWindowSize()
{
Expand All @@ -35,26 +27,7 @@ std::pair<int,int> Prusa_MMU2::GetWindowSize()
void Prusa_MMU2::Draw()
{
glScalef(50.F/35.F,4,1);
MM_Control_01::Draw(static_cast<float>(GetWindowSize().second));
MMU2::Draw(static_cast<float>(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);
}
14 changes: 4 additions & 10 deletions parts/printers/Prusa_MMU2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,27 @@
#pragma once

#include "GCodeSniffer.h"
#include "MMU2.h"
#include "Printer.h"
#include "boards/MM_Control_01.h"
#include <gsl-lite.hpp>

class MK3SGL;

#include <utility> // for pair

class Prusa_MMU2 : public Printer, public Boards::MM_Control_01
class Prusa_MMU2 : public Printer, public MMU2
{
public:

inline std::pair<int,int> GetWindowSize() override;
Prusa_MMU2():MMU2(false){};

void OnVisualTypeSet(const std::string &type) override;

//void SetupHardware() override;
inline std::pair<int,int> GetWindowSize() override;

void Draw() override;

//zinline bool GetHasMMU() override {return true;}


protected:

// GCodeSniffer m_sniffer = GCodeSniffer('T');

std::unique_ptr<MK3SGL> m_pVis {nullptr};

};
Binary file added scripts/tests/snaps/ext1/MMU2F1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/tests/snaps/ext1/MMU2F2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/tests/snaps/ext1/MMU2F3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/tests/snaps/ext1/MMU2F4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions scripts/tests/test_boot_mmu2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,18 @@ ScriptHost::SetTimeoutMs(1000)
ScriptHost::SetQuitOnTimeout(1)
Board::WaitMs(500);
GLHelper::Snapshot(tests/snaps/MMU2_start)
Board::SetFINDA(1)
Board::WaitMs(10)
GLHelper::SnapRect(tests/snaps/MMU2F1, 429, 160, 21, 35)
Board::SetFINDA(0)
Board::WaitMs(10)
GLHelper::SnapRect(tests/snaps/MMU2F2, 429, 160, 21, 35)
Board::ToggleFINDA()
Board::WaitMs(10)
GLHelper::SnapRect(tests/snaps/MMU2F3, 429, 160, 21, 35)
Board::ToggleFINDA()
Board::WaitMs(10)
GLHelper::SnapRect(tests/snaps/MMU2F4, 429, 160, 21, 35)
Board::SetFINDAAuto()
Board::WaitMs(10)
Board::Quit()

0 comments on commit 4888e65

Please sign in to comment.