Invert the charge current if necessary, assume the value always changes
This commit is contained in:
parent
31c709435b
commit
c0b7c4ddce
4 changed files with 23 additions and 11 deletions
|
@ -187,12 +187,16 @@ void Battery::updateData()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentFile && currentFile->open(QIODevice::ReadOnly)) {
|
if(currentFile && currentFile->open(QIODevice::ReadOnly)) {
|
||||||
nextCurrent = currentFile->readLine().trimmed().toInt();
|
current = currentFile->readLine().trimmed().toInt();
|
||||||
if(nextCurrent != current) {
|
if(!invertDecided) {
|
||||||
current = nextCurrent;
|
invertCurrent = (!chargerConnected && current > 10);
|
||||||
emit currentChanged(current);
|
if(invertCurrent) logL("Battery current inverted");
|
||||||
logD(QString("Current: %1mA").arg(current / 1000));
|
else logL("Battery current not inverted");
|
||||||
|
invertDecided = true;
|
||||||
}
|
}
|
||||||
|
current = current * (invertCurrent ? -1 : 1);
|
||||||
|
emit currentChanged(current);
|
||||||
|
logH(QString("Current: %1mA").arg(current / 1000));
|
||||||
currentFile->close();
|
currentFile->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,9 @@ private:
|
||||||
bool chargerIsEnabled = true;
|
bool chargerIsEnabled = true;
|
||||||
|
|
||||||
int nextCharge = charge;
|
int nextCharge = charge;
|
||||||
int nextCurrent = current;
|
bool invertCurrent = false;
|
||||||
|
bool invertDecided = false;
|
||||||
|
|
||||||
bool nextChargerConnected = chargerConnected;
|
bool nextChargerConnected = chargerConnected;
|
||||||
QString nextState = state;
|
QString nextState = state;
|
||||||
bool nextChargingEnabled = chargingEnabled;
|
bool nextChargingEnabled = chargingEnabled;
|
||||||
|
|
|
@ -224,11 +224,15 @@ void Battery::updateData()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentFile && currentFile->open(QIODevice::ReadOnly)) {
|
if(currentFile && currentFile->open(QIODevice::ReadOnly)) {
|
||||||
nextCurrent = currentFile->readLine().trimmed().toInt();
|
current = currentFile->readLine().trimmed().toInt();
|
||||||
if(nextCurrent != current) {
|
if(!invertDecided) {
|
||||||
current = nextCurrent;
|
invertCurrent = (!chargerConnected && current > 10);
|
||||||
logV(QString("Current: %1mA").arg(current / 1000));
|
if(invertCurrent) logL("Battery current inverted");
|
||||||
|
else logL("Battery current not inverted");
|
||||||
|
invertDecided = true;
|
||||||
}
|
}
|
||||||
|
current = current * (invertCurrent ? -1 : 1);
|
||||||
|
logH(QString("Current: %1mA").arg(current / 1000));
|
||||||
currentFile->close();
|
currentFile->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,9 @@ private:
|
||||||
bool chargerIsEnabled = true;
|
bool chargerIsEnabled = true;
|
||||||
|
|
||||||
int nextCharge = charge;
|
int nextCharge = charge;
|
||||||
int nextCurrent = current;
|
bool invertCurrent = false;
|
||||||
|
bool invertDecided = false;
|
||||||
|
|
||||||
bool nextChargerConnected = chargerConnected;
|
bool nextChargerConnected = chargerConnected;
|
||||||
QString nextState = state;
|
QString nextState = state;
|
||||||
bool nextChargingEnabled = chargingEnabled;
|
bool nextChargingEnabled = chargingEnabled;
|
||||||
|
|
Loading…
Reference in a new issue