Loop through system files, add initial Jolla Tablet support
This commit is contained in:
parent
8721423029
commit
c9788b3500
3 changed files with 187 additions and 77 deletions
|
@ -22,64 +22,132 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO
|
||||||
settings = newSettings;
|
settings = newSettings;
|
||||||
logger = newLogger;
|
logger = newLogger;
|
||||||
|
|
||||||
// Number: charge percentage, e.g. 42
|
QStringList filenames;
|
||||||
chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this);
|
|
||||||
logE("Capacity file: " + chargeFile->fileName());
|
// Battery charge percentage, number, e.g. 42
|
||||||
|
filenames << "/sys/class/power_supply/battery/capacity"
|
||||||
|
<< "/sys/class/power_supply/dollar_cove_battery/capacity";
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!chargeFile && QFile::exists(file)) {
|
||||||
|
chargeFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chargeFile) logE("Battery charge file: " + chargeFile->fileName());
|
||||||
|
else logE("Battery charge file: not found!");
|
||||||
|
|
||||||
// Number: battery/charging current, e.g. -1450000 (-145mA)
|
// Number: battery/charging current, e.g. -1450000 (-145mA)
|
||||||
currentFile = new QFile("/sys/class/power_supply/battery/current_now", this);
|
filenames.clear();
|
||||||
logE("Charge state file: " + currentFile->fileName());
|
filenames << "/sys/class/power_supply/battery/current_now"
|
||||||
|
<< "/sys/class/power_supply/dollar_cove_battery/current_now";
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!currentFile && QFile::exists(file)) {
|
||||||
|
currentFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currentFile) logE("Charging/discharging current file: " + currentFile->fileName());
|
||||||
|
else logE("Charging/discharging current file: not found!");
|
||||||
|
|
||||||
// String: charging, discharging, full, empty, unknown (others?)
|
// String: charging, discharging, full, empty, unknown (others?)
|
||||||
stateFile = new QFile("/sys/class/power_supply/battery/status", this);
|
filenames.clear();
|
||||||
logE("Charger status file: " + stateFile->fileName());
|
filenames << "/sys/class/power_supply/battery/status"
|
||||||
|
<< "/sys/class/power_supply/dollar_cove_battery/status";
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!stateFile && QFile::exists(file)) {
|
||||||
|
stateFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stateFile) logE("Status file: " + stateFile->fileName());
|
||||||
|
else logE("Status file: not found!");
|
||||||
|
|
||||||
// Number: 0 or 1
|
// Number: 0 or 1
|
||||||
chargerConnectedFile = new QFile("/sys/class/power_supply/usb/present", this);
|
filenames.clear();
|
||||||
logE("Reading charger status from" + chargerConnectedFile->fileName());
|
filenames << "/sys/class/power_supply/usb/present"
|
||||||
|
<< "/sys/class/power_supply/dollar_cove_charger/present";
|
||||||
|
|
||||||
QString filename;
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!chargerConnectedFile && QFile::exists(file)) {
|
||||||
|
chargerConnectedFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chargerConnectedFile) logE("Charger status file: " + chargerConnectedFile->fileName());
|
||||||
|
else logE("Charger status file: not found!");
|
||||||
|
|
||||||
// Number: temperature
|
// Number: temperature
|
||||||
filename = "/sys/class/power_supply/battery/temp";
|
filenames.clear();
|
||||||
if(!temperatureFile && QFile::exists(filename)) {
|
filenames << "/sys/class/power_supply/battery/temp"
|
||||||
temperatureFile = new QFile(filename, this);
|
<< "/sys/class/power_supply/dollar_cove_battery/temp";
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!temperatureFile && QFile::exists(file)) {
|
||||||
|
temperatureFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(temperatureFile) logE("Battery temperature file: " + temperatureFile->fileName());
|
||||||
|
else logE("Battery temperature file: not found!");
|
||||||
|
|
||||||
// String: health state
|
// String: health state
|
||||||
filename = "/sys/class/power_supply/battery/health";
|
filenames.clear();
|
||||||
if(!healthFile && QFile::exists(filename)) {
|
filenames << "/sys/class/power_supply/battery/health"
|
||||||
healthFile = new QFile(filename, this);
|
<< "/sys/class/power_supply/dollar_cove_battery/health";
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!healthFile && QFile::exists(file)) {
|
||||||
|
healthFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. for Sony Xperia XA2
|
if(healthFile) logE("Battery health file: " + healthFile->fileName());
|
||||||
filename = "/sys/class/power_supply/battery/input_suspend";
|
else logE("Battery health file: not found!");
|
||||||
if(!chargingEnabledFile && QFile::exists(filename)) {
|
|
||||||
chargingEnabledFile = new QFile(filename, this);
|
// Charger control file
|
||||||
enableChargingValue = 0;
|
filenames.clear();
|
||||||
disableChargingValue = 1;
|
filenames << "/sys/class/power_supply/battery/input_suspend" // e.g. Sony Xperia XA2
|
||||||
|
<< "/sys/class/power_supply/battery/charging_enabled" // e.g. for Sony Xperia Z3 Compact Tablet
|
||||||
|
<< "/sys/class/power_supply/usb/charger_disable" // e.g. for Jolla Phone
|
||||||
|
<< "/sys/class/power_supply/dollar_cove_battery/enable_charging"; // e.g. for Jolla Tablet
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!chargingEnabledFile && QFile::exists(file)) {
|
||||||
|
chargingEnabledFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. for Sony Xperia Z3 Compact Tablet
|
// Flip the charging control bits if necessary
|
||||||
filename = "/sys/class/power_supply/battery/charging_enabled";
|
if(chargingEnabledFile && chargingEnabledFile->fileName().contains("enable")) {
|
||||||
if(!chargingEnabledFile && QFile::exists(filename)) {
|
|
||||||
chargingEnabledFile = new QFile(filename, this);
|
|
||||||
enableChargingValue = 1;
|
enableChargingValue = 1;
|
||||||
disableChargingValue = 0;
|
disableChargingValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. for Jolla Phone
|
// If we found a usable file, check that it is writable
|
||||||
filename = "/sys/class/power_supply/usb/charger_disable";
|
if(chargingEnabledFile) {
|
||||||
if(!chargingEnabledFile && QFile::exists(filename)) {
|
logE("Charger control file: " + chargingEnabledFile->fileName());
|
||||||
chargingEnabledFile = new QFile(filename, this);
|
if(chargingEnabledFile->open(QIODevice::WriteOnly)) {
|
||||||
enableChargingValue = 0;
|
chargingEnabledFile->close();
|
||||||
disableChargingValue = 1;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if(!chargingEnabledFile && !QSysInfo::machineHostName().contains("SailfishEmul")) {
|
logE("Charger control file is not writable - feature disabled");
|
||||||
|
delete chargingEnabledFile;
|
||||||
|
chargingEnabledFile = Q_NULLPTR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(!QSysInfo::machineHostName().contains("SailfishEmul")) {
|
||||||
logE("Charger control file not found!");
|
logE("Charger control file not found!");
|
||||||
logE("Please contact the developer with your device model!");
|
logE("Please contact the developer with your device model!");
|
||||||
}
|
}
|
||||||
|
else logE("Charger control file: not found!");
|
||||||
|
|
||||||
updateData();
|
updateData();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,67 +33,108 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb
|
||||||
chargeNotification = new MyNotification(this);
|
chargeNotification = new MyNotification(this);
|
||||||
healthNotification = new MyNotification(this);
|
healthNotification = new MyNotification(this);
|
||||||
|
|
||||||
// Number: charge percentage, e.g. 42
|
QStringList filenames;
|
||||||
chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this);
|
|
||||||
logE("Capacity file: " + chargeFile->fileName() + (chargeFile->exists() ? " OK" : " doesn't exist"));
|
|
||||||
|
|
||||||
// String: charging, discharging, full, empty, unknown (others?)
|
// Battery charge percentage, number, e.g. 42
|
||||||
stateFile = new QFile("/sys/class/power_supply/battery/status", this);
|
filenames << "/sys/class/power_supply/battery/capacity"
|
||||||
logE("Charge state file: " + stateFile->fileName() + (stateFile->exists() ? " OK" : " doesn't exist"));
|
<< "/sys/class/power_supply/dollar_cove_battery/capacity";
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!chargeFile && QFile::exists(file)) {
|
||||||
|
chargeFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Number: 0 or 1
|
if(chargeFile) logE("Battery charge file: " + chargeFile->fileName());
|
||||||
chargerConnectedFile = new QFile("/sys/class/power_supply/usb/present", this);
|
else logE("Battery charge file: not found!");
|
||||||
logE("Charger status file: " + chargerConnectedFile->fileName() + (chargerConnectedFile->exists() ? " OK" : " doesn't exist"));
|
|
||||||
|
|
||||||
QString filename;
|
// Battery/charging status: charging, discharging, full, empty, unknown (others?)
|
||||||
|
filenames.clear();
|
||||||
|
filenames << "/sys/class/power_supply/battery/status"
|
||||||
|
<< "/sys/class/power_supply/dollar_cove_battery/status";
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!stateFile && QFile::exists(file)) {
|
||||||
|
stateFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stateFile) logE("Status file: " + stateFile->fileName());
|
||||||
|
else logE("Status file: not found!");
|
||||||
|
|
||||||
|
// Charger connected, bool (number): 0 or 1
|
||||||
|
filenames.clear();
|
||||||
|
filenames << "/sys/class/power_supply/usb/present"
|
||||||
|
<< "/sys/class/power_supply/dollar_cove_charger/present";
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!chargerConnectedFile && QFile::exists(file)) {
|
||||||
|
chargerConnectedFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chargerConnectedFile) logE("Charger status file: " + chargerConnectedFile->fileName());
|
||||||
|
else logE("Charger status file: not found!");
|
||||||
|
|
||||||
// Number: temperature
|
// Number: temperature
|
||||||
filename = "/sys/class/power_supply/battery/temp";
|
filenames.clear();
|
||||||
if(!temperatureFile && QFile::exists(filename)) {
|
filenames << "/sys/class/power_supply/battery/temp"
|
||||||
temperatureFile = new QFile(filename, this);
|
<< "/sys/class/power_supply/dollar_cove_battery/temp";
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!temperatureFile && QFile::exists(file)) {
|
||||||
|
temperatureFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
logE("Temperature file: " + filename + (QFile::exists(filename) ? " OK" : " doesn't exist"));
|
}
|
||||||
|
|
||||||
|
if(temperatureFile) logE("Battery temperature file: " + temperatureFile->fileName());
|
||||||
|
else logE("Battery temperature file: not found!");
|
||||||
|
|
||||||
// String: health state
|
// String: health state
|
||||||
filename = "/sys/class/power_supply/battery/health";
|
filenames.clear();
|
||||||
if(!healthFile && QFile::exists(filename)) {
|
filenames << "/sys/class/power_supply/battery/health"
|
||||||
healthFile = new QFile(filename, this);
|
<< "/sys/class/power_supply/dollar_cove_battery/health";
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!healthFile && QFile::exists(file)) {
|
||||||
|
healthFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
logE("Battery health file: " + filename + (QFile::exists(filename) ? " OK" : " doesn't exist"));
|
|
||||||
|
|
||||||
// e.g. for Sony Xperia XA2
|
|
||||||
filename = "/sys/class/power_supply/battery/input_suspend";
|
|
||||||
if(!chargingEnabledFile && QFile::exists(filename)) {
|
|
||||||
chargingEnabledFile = new QFile(filename, this);
|
|
||||||
enableChargingValue = 0;
|
|
||||||
disableChargingValue = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. for Sony Xperia Z3 Compact Tablet
|
if(healthFile) logE("Battery health file: " + healthFile->fileName());
|
||||||
filename = "/sys/class/power_supply/battery/charging_enabled";
|
else logE("Battery health file: not found!");
|
||||||
if(!chargingEnabledFile && QFile::exists(filename)) {
|
|
||||||
chargingEnabledFile = new QFile(filename, this);
|
// Charger control file
|
||||||
|
filenames.clear();
|
||||||
|
filenames << "/sys/class/power_supply/battery/input_suspend" // e.g. Sony Xperia XA2
|
||||||
|
<< "/sys/class/power_supply/battery/charging_enabled" // e.g. for Sony Xperia Z3 Compact Tablet
|
||||||
|
<< "/sys/class/power_supply/usb/charger_disable" // e.g. for Jolla Phone
|
||||||
|
<< "/sys/class/power_supply/dollar_cove_battery/enable_charging"; // e.g. for Jolla Tablet
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!chargingEnabledFile && QFile::exists(file)) {
|
||||||
|
chargingEnabledFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flip the charging control bits if necessary
|
||||||
|
if(chargingEnabledFile && chargingEnabledFile->fileName().contains("enable")) {
|
||||||
enableChargingValue = 1;
|
enableChargingValue = 1;
|
||||||
disableChargingValue = 0;
|
disableChargingValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. for Jolla Phone
|
|
||||||
filename = "/sys/class/power_supply/usb/charger_disable";
|
|
||||||
if(!chargingEnabledFile && QFile::exists(filename)) {
|
|
||||||
chargingEnabledFile = new QFile(filename, this);
|
|
||||||
enableChargingValue = 0;
|
|
||||||
disableChargingValue = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we found a usable file, check that it is writable
|
// If we found a usable file, check that it is writable
|
||||||
if(chargingEnabledFile) {
|
if(chargingEnabledFile) {
|
||||||
logE("Charger control file: " + chargingEnabledFile->fileName() + (chargingEnabledFile->exists() ? " OK" : " doesn't exist"));
|
logE("Charger control file: " + chargingEnabledFile->fileName());
|
||||||
if(chargingEnabledFile->open(QIODevice::WriteOnly)) {
|
if(chargingEnabledFile->open(QIODevice::WriteOnly)) {
|
||||||
chargingEnabledFile->close();
|
chargingEnabledFile->close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logE("Charger control file" + chargingEnabledFile->fileName() + "is not writable");
|
logE("Charger control file is not writable - feature disabled");
|
||||||
logE("Charger control feature disabled");
|
|
||||||
delete chargingEnabledFile;
|
delete chargingEnabledFile;
|
||||||
chargingEnabledFile = Q_NULLPTR;
|
chargingEnabledFile = Q_NULLPTR;
|
||||||
}
|
}
|
||||||
|
@ -102,6 +143,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb
|
||||||
logE("Charger control file not found!");
|
logE("Charger control file not found!");
|
||||||
logE("Please contact the developer with your device model!");
|
logE("Please contact the developer with your device model!");
|
||||||
}
|
}
|
||||||
|
else logE("Charger control file: not found!");
|
||||||
|
|
||||||
connect(settings, SIGNAL(resetTimers()), this, SLOT(resetTimers()));
|
connect(settings, SIGNAL(resetTimers()), this, SLOT(resetTimers()));
|
||||||
|
|
||||||
|
|
|
@ -100,8 +100,8 @@ private:
|
||||||
QString health = "unknown"; // Good, warm, overheat. Might have Cold or Overvoltage depending on driver
|
QString health = "unknown"; // Good, warm, overheat. Might have Cold or Overvoltage depending on driver
|
||||||
int temperature = 0x7FFFFFFF; // This value means "unknown" (32-bit INT_MAX)
|
int temperature = 0x7FFFFFFF; // This value means "unknown" (32-bit INT_MAX)
|
||||||
|
|
||||||
int enableChargingValue = 1;
|
int enableChargingValue = 0;
|
||||||
int disableChargingValue = 0;
|
int disableChargingValue = 1;
|
||||||
bool chargerIsEnabled = true;
|
bool chargerIsEnabled = true;
|
||||||
|
|
||||||
int nextCharge = charge;
|
int nextCharge = charge;
|
||||||
|
|
Loading…
Reference in a new issue