Don't change charger status on timer (it's the daemons job)

This commit is contained in:
Matti Viljanen 2020-04-26 11:38:53 +03:00
parent 397b1d77bb
commit 6191766aa2
No known key found for this signature in database
GPG key ID: CF32A1495158F888

View file

@ -36,12 +36,7 @@ Battery::Battery(Settings* newSettings, QObject* parent) : QObject(parent)
// ENABLE/DISABLE CHARGING // ENABLE/DISABLE CHARGING
if(QHostInfo::localHostName().contains("SailfishEmul")) { if(QHostInfo::localHostName().contains("SailfishEmul")) {
qInfo() << "Sailfish SDK detected"; qInfo() << "Sailfish SDK detected, not using charger control file";
qInfo() << "Using dummy control file";
filename = QStandardPaths::writableLocation(QStandardPaths::TempLocation)+"/charging_enabled_dummy";
chargingEnabledFile = new QFile(filename, this);
enableChargingValue = 1;
disableChargingValue = 0;
} }
else { else {
// e.g. for Sony Xperia XA2 // e.g. for Sony Xperia XA2
@ -90,9 +85,9 @@ Battery::Battery(Settings* newSettings, QObject* parent) : QObject(parent)
} }
// TODO // TODO
// Implement DBus mechanism for reading battery status, or try // Use DBus instead of polling the files - where is the documentation?
// QFileSystemWatcher again without /run/state/namespaces/Battery/ // QFileWatcher doesn't work, because e.g. the charge file
// thingamabob - it is deprecated anyway. // isn't a real file, and it doesn't "change" when the value changes.
updateData(); updateData();
} }
@ -101,7 +96,7 @@ Battery::~Battery() { }
void Battery::updateData() void Battery::updateData()
{ {
if(chargeFile->open(QIODevice::ReadOnly)) { if(chargeFile && chargeFile->open(QIODevice::ReadOnly)) {
nextCharge = chargeFile->readLine().trimmed().toInt(); nextCharge = chargeFile->readLine().trimmed().toInt();
if(nextCharge != charge) { if(nextCharge != charge) {
charge = nextCharge; charge = nextCharge;
@ -110,7 +105,7 @@ void Battery::updateData()
} }
chargeFile->close(); chargeFile->close();
} }
if(chargerConnectedFile->open(QIODevice::ReadOnly)) { if(chargerConnectedFile && chargerConnectedFile->open(QIODevice::ReadOnly)) {
nextChargerConnected = chargerConnectedFile->readLine().trimmed().toInt(); nextChargerConnected = chargerConnectedFile->readLine().trimmed().toInt();
if(nextChargerConnected != chargerConnected) { if(nextChargerConnected != chargerConnected) {
chargerConnected = nextChargerConnected; chargerConnected = nextChargerConnected;
@ -119,7 +114,7 @@ void Battery::updateData()
} }
chargerConnectedFile->close(); chargerConnectedFile->close();
} }
if(stateFile->open(QIODevice::ReadOnly)) { if(stateFile && stateFile->open(QIODevice::ReadOnly)) {
nextState = (QString(stateFile->readLine().trimmed().toLower())); nextState = (QString(stateFile->readLine().trimmed().toLower()));
if(nextState != state) { if(nextState != state) {
state = nextState; state = nextState;
@ -128,26 +123,6 @@ void Battery::updateData()
} }
stateFile->close(); stateFile->close();
} }
// This can't be used, because on Jolla Phone the file always reads "0" :(
// It doesn't matter that much anyway, because the value changes only when we change it.
// if(chargingEnabledFile && chargingEnabledFile->open(QIODevice::ReadOnly)) {
// nextChargingEnabled = chargingEnabledFile->readLine().trimmed().toInt() == enableChargingValue;
// if(nextChargingEnabled != chargingEnabled) {
// chargingEnabled = nextChargingEnabled;
// emit chargingEnabledChanged(chargingEnabled);
// }
// chargingEnabledFile->close();
// }
if(chargingEnabledFile && settings->getLimitEnabled()) {
if(chargingEnabled && charge >= settings->getHighLimit()) {
setChargingEnabled(false);
}
else if(!chargingEnabled && charge <= settings->getLowLimit()) {
setChargingEnabled(true);
}
}
} }
int Battery::getCharge(){ return charge; } int Battery::getCharge(){ return charge; }