Added command line option --pause-on-battery and renamed config option.

This commit is contained in:
XMRig 2020-07-23 15:45:01 +07:00
parent 6484bbb716
commit 32e9b7e34a
No known key found for this signature in database
GPG key ID: 446A53638BE94409
10 changed files with 32 additions and 25 deletions

View file

@ -61,13 +61,13 @@ const char *BaseConfig::kColors = "colors";
const char *BaseConfig::kDryRun = "dry-run";
const char *BaseConfig::kHttp = "http";
const char *BaseConfig::kLogFile = "log-file";
const char *BaseConfig::kPauseOnBattery = "pause-on-battery";
const char *BaseConfig::kPrintTime = "print-time";
const char *BaseConfig::kSyslog = "syslog";
const char *BaseConfig::kTitle = "title";
const char *BaseConfig::kUserAgent = "user-agent";
const char *BaseConfig::kVerbose = "verbose";
const char *BaseConfig::kWatch = "watch";
const char *BaseConfig::kMineOnBattery = "mine-on-battery";
#ifdef XMRIG_FEATURE_TLS
@ -91,7 +91,7 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
m_dryRun = reader.getBool(kDryRun, m_dryRun);
m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool(kWatch, m_watch);
m_mineOnBattery = reader.getBool(kMineOnBattery, m_mineOnBattery);
m_pauseOnBattery = reader.getBool(kPauseOnBattery, m_pauseOnBattery);
m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent);
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);

View file

@ -55,13 +55,13 @@ public:
static const char *kDryRun;
static const char *kHttp;
static const char *kLogFile;
static const char *kPauseOnBattery;
static const char *kPrintTime;
static const char *kSyslog;
static const char *kTitle;
static const char *kUserAgent;
static const char *kVerbose;
static const char *kWatch;
static const char* kMineOnBattery;
# ifdef XMRIG_FEATURE_TLS
static const char *kTls;
@ -72,6 +72,7 @@ public:
inline bool isAutoSave() const { return m_autoSave; }
inline bool isBackground() const { return m_background; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isPauseOnBattery() const { return m_pauseOnBattery; }
inline bool isSyslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); }
@ -81,7 +82,6 @@ public:
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline const Title &title() const { return m_title; }
inline uint32_t printTime() const { return m_printTime; }
inline bool mineOnBattery() const { return m_mineOnBattery; }
# ifdef XMRIG_FEATURE_TLS
inline const TlsConfig &tls() const { return m_tls; }
@ -100,10 +100,10 @@ protected:
bool m_autoSave = true;
bool m_background = false;
bool m_dryRun = false;
bool m_pauseOnBattery = false;
bool m_syslog = false;
bool m_upgrade = false;
bool m_watch = true;
bool m_mineOnBattery = true;
Http m_http;
Pools m_pools;
String m_apiId;

View file

@ -247,6 +247,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::HttpEnabledKey: /* --http-enabled */
case IConfig::DaemonKey: /* --daemon */
case IConfig::VerboseKey: /* --verbose */
case IConfig::PauseOnBatteryKey: /* --pause-on-battery */
return transformBoolean(doc, key, true);
case IConfig::ColorKey: /* --no-color */
@ -305,6 +306,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
case IConfig::NoTitleKey: /* --no-title */
return set(doc, BaseConfig::kTitle, enable);
case IConfig::PauseOnBatteryKey: /* --pause-on-battery */
return set(doc, BaseConfig::kPauseOnBattery, enable);
default:
break;
}

View file

@ -76,6 +76,7 @@ public:
DataDirKey = 1035,
TitleKey = 1037,
NoTitleKey = 1038,
PauseOnBatteryKey = 1041,
// xmrig common
CPUPriorityKey = 1021,

View file

@ -92,5 +92,5 @@
"user-agent": null,
"verbose": 0,
"watch": true,
"mine-on-battery": true
"pause-on-battery": false
}

View file

@ -551,8 +551,8 @@ void xmrig::Miner::onTimer(const Timer *)
d_ptr->ticks++;
if (!d_ptr->controller->config()->mineOnBattery()) {
const bool battery_power = xmrig::Platform::isOnBatteryPower();
if (d_ptr->controller->config()->isPauseOnBattery()) {
const bool battery_power = Platform::isOnBatteryPower();
if (battery_power && d_ptr->enabled) {
LOG_INFO("%s " YELLOW_BOLD("on battery power"), Tags::miner());
d_ptr->battery_power = true;

View file

@ -252,5 +252,5 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember(StringRef(kUserAgent), m_userAgent.toJSON(), allocator);
doc.AddMember(StringRef(kVerbose), Log::verbose(), allocator);
doc.AddMember(StringRef(kWatch), m_watch, allocator);
doc.AddMember(StringRef(kMineOnBattery), m_mineOnBattery, allocator);
doc.AddMember(StringRef(kPauseOnBattery), isPauseOnBattery(), allocator);
}

View file

@ -110,7 +110,7 @@ R"===(
"syslog": false,
"user-agent": null,
"watch": true,
"mine-on-battery": true
"pause-on-battery": false
}
)===";
#endif

View file

@ -95,6 +95,7 @@ static const option options[] = {
{ "data-dir", 1, nullptr, IConfig::DataDirKey },
{ "title", 1, nullptr, IConfig::TitleKey },
{ "no-title", 0, nullptr, IConfig::NoTitleKey },
{ "pause-on-battery", 0, nullptr, IConfig::PauseOnBatteryKey },
# ifdef XMRIG_FEATURE_TLS
{ "tls", 0, nullptr, IConfig::TlsKey },
{ "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey },

View file

@ -177,6 +177,7 @@ static inline const std::string &usage()
u += " --title set custom console window title\n";
u += " --no-title disable setting console window title\n";
# endif
u += " --pause-on-battery pause mine on battery power\n";
return u;
}