Always try to write new charger status
This commit is contained in:
parent
a1c77e6268
commit
87e72bed0b
1 changed files with 23 additions and 13 deletions
|
@ -73,11 +73,13 @@ Battery::Battery(Settings *newSettings, QTimer *newUpdater, QTimer *newNotifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we found a usable file, check that it is writable
|
// If we found a usable file, check that it is writable
|
||||||
if(chargingEnabledFile && !chargingEnabledFile->open(QIODevice::WriteOnly)) {
|
if(chargingEnabledFile) {
|
||||||
delete chargingEnabledFile;
|
if(chargingEnabledFile->open(QIODevice::WriteOnly)) {
|
||||||
chargingEnabledFile = Q_NULLPTR;
|
chargingEnabledFile->close();
|
||||||
qWarning() << "Charger control file" << chargingEnabledFile->fileName() << "is not writable";
|
}
|
||||||
qWarning() << "Charger control feature disabled";
|
else {
|
||||||
|
qWarning() << "Charger control file" << chargingEnabledFile->fileName() << "is not writable";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateData();
|
updateData();
|
||||||
|
@ -173,19 +175,27 @@ QString Battery::getState() { return state; }
|
||||||
bool Battery::getChargingEnabled() { return chargingEnabled; }
|
bool Battery::getChargingEnabled() { return chargingEnabled; }
|
||||||
|
|
||||||
void Battery::setChargingEnabled(bool isEnabled) {
|
void Battery::setChargingEnabled(bool isEnabled) {
|
||||||
if(chargingEnabledFile && chargingEnabledFile->open(QIODevice::WriteOnly)) {
|
if(chargingEnabledFile) {
|
||||||
if(chargingEnabledFile->write(QString("%1").arg(isEnabled ? enableChargingValue : disableChargingValue).toLatin1())) {
|
if(chargingEnabledFile->open(QIODevice::WriteOnly)) {
|
||||||
chargingEnabled = isEnabled;
|
if(chargingEnabledFile->write(QString("%1").arg(isEnabled ? enableChargingValue : disableChargingValue).toLatin1())) {
|
||||||
emit chargingEnabledChanged(chargingEnabled);
|
chargingEnabled = isEnabled;
|
||||||
|
emit chargingEnabledChanged(chargingEnabled);
|
||||||
|
|
||||||
if(isEnabled) {
|
if(isEnabled) {
|
||||||
qInfo() << "Charging resumed";
|
qInfo() << "Charging resumed";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qInfo() << "Charging paused";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qInfo() << "Charging paused";
|
qWarning() << "Could not write new charger state";
|
||||||
}
|
}
|
||||||
|
chargingEnabledFile->close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qWarning() << "Could not open charger control file";
|
||||||
}
|
}
|
||||||
chargingEnabledFile->close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue