Skip to content

Commit

Permalink
Implement commandline option to enable/disable softPWM #345 (#346)
Browse files Browse the repository at this point in the history
* Implement commandline option to enable/disable softPWM for MK2
  • Loading branch information
GilesBathgate authored Dec 4, 2021
1 parent 5bc62ae commit 3bfe0ee
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
5 changes: 5 additions & 0 deletions MK404.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "Config.h"
#include "EnabledType.h"
#include "FatImage.h" // for FatImage
#include "KeyController.h"
#include "Macros.h"
Expand Down Expand Up @@ -328,6 +329,9 @@ int main(int argc, char *argv[])
ValueArg<string> argSD("","sdimage","Use the given SD card .img file instead of the default", false ,"", "filename.img", cmd);
SwitchArg argScriptHelp("","scripthelp", "Prints the available scripting commands for the current printer/context",cmd, false);
ValueArg<string> argScript("","script","Execute the given script. Use --scripthelp for syntax.", false ,"", "filename.txt", cmd);
std::vector<string> vstrEnabled = EnabledType::GetOpts();
ValuesConstraint<string> vcEnabledOpts(vstrEnabled);
ValueArg<string> argSoftPWM("p","softPWM","enable/disable software PWM (currently only valid for MK2)",false,"",&vcEnabledOpts,cmd);
SwitchArg argNoHacks("n","no-hacks","Disable any special hackery that might have been implemented for a board to run its manufacturer firmware, e.g. if you want to run stock marlin and have issues. Effects depend on the board and firmware.",cmd);
SwitchArg argMute("m","mute","Tell a printer to mute any audio it may produce.", cmd);
SwitchArg argMarlin("","marlin","Synonym for --no-hacks",cmd,false);
Expand Down Expand Up @@ -398,6 +402,7 @@ int main(int argc, char *argv[])
m_bTestMode = (argModel.getValue()=="Test_Printer") | argTest.isSet();

Config::Get().SetLCDScheme(argLCDSCheme.getValue());
Config::Get().SetSoftPWM(EnabledType::GetNameToType().at(argSoftPWM.getValue()));
Config::Get().SetExtrusionMode(PrintVisualType::GetNameToType().at(argExtrusion.getValue()));
Config::Get().SetColourE(argColourE.isSet());
Config::Get().SetFW2(argFW2.getValue());
Expand Down
11 changes: 11 additions & 0 deletions parts/printers/Prusa_MK2_13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ void Prusa_MK2_13::SetupHardware()

SetupPINDA();

switch (Config::Get().GetSoftPWM())
{
case EnabledType::Type_t::Enabled:
hBed.SetSoftPWM(true);
break;
case EnabledType::Type_t::Disabled:
hBed.SetSoftPWM(false);
break;
default:
break;
}
if (GetConnectSerial())
{
UART0.Connect('0');
Expand Down
6 changes: 5 additions & 1 deletion utility/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#pragma once

#include "EnabledType.h"
#include "PrintVisualType.h"

class Config
Expand Down Expand Up @@ -52,6 +53,9 @@ class Config
inline void SetDebugCore(bool bVal){ m_bDebugCore = bVal;}
inline bool GetDebugCore(){ return m_bDebugCore;}

inline void SetSoftPWM(EnabledType::Type_t val){ m_SoftPWM = val; }
inline EnabledType::Type_t GetSoftPWM(){ return m_SoftPWM; }

// Secondary firmware?
inline void SetFW2(std::string strName){ m_strSecFW = std::move(strName);}
inline const std::string GetFW2(){ return m_strSecFW;}
Expand All @@ -63,5 +67,5 @@ class Config
uint8_t m_iScheme = 0;
bool m_bDebugCore = false;
std::string m_strSecFW = "MM-control-01.hex";

EnabledType::Type_t m_SoftPWM = EnabledType::Type_t::NotSet;
};
59 changes: 59 additions & 0 deletions utility/EnabledType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
EnabledType.h - Enum for the enabled/disabled options
Copyright 2020 VintagePC <https://github.com/vintagepc/>
This file is part of MK404.
MK404 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MK404 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MK404. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <map>
#include <string>
#include <vector>

class EnabledType
{
public:

enum class Type_t
{
NotSet,
Enabled,
Disabled
};

static inline std::vector<std::string> GetOpts()
{
static const std::vector<std::string> v {
"enabled",
"disabled"
};
return v;
}

static const std::map<std::string, Type_t>& GetNameToType()
{
static const std::map<std::string, Type_t> m {
{"",Type_t::NotSet},
{"enabled",Type_t::Enabled},
{"disabled",Type_t::Disabled},
};
return m;
};

};

0 comments on commit 3bfe0ee

Please sign in to comment.