Fix the missing stuff from broken merge

How did this even happen?
This commit is contained in:
Matti Viljanen 2021-05-23 15:45:03 +03:00
parent 49a59183d2
commit a7d83df085
2 changed files with 38 additions and 0 deletions

View file

@ -124,6 +124,26 @@ void Battery::updateData()
}
currentFile->close();
}
if(healthFile && healthFile->open(QIODevice::ReadOnly)) {
nextHealth = (QString(healthFile->readLine().trimmed().toLower()));
if(nextHealth != health) {
health = nextHealth;
emit healthChanged(health);
logV("Health: " + health);
}
healthFile->close();
}
if(temperatureFile && temperatureFile->open(QIODevice::ReadOnly)) {
nextTemperature = temperatureFile->readLine().trimmed().toInt();
if(nextTemperature != temperature) {
temperature = nextTemperature;
emit temperatureChanged(temperature);
// TODO: factor might be different depending on device
// X10 has degrees * 10
logD(QString("Temperature: %1°C").arg(temperature / 10));
}
temperatureFile->close();
}
}
int Battery::getCharge(){ return charge; }
@ -132,6 +152,10 @@ int Battery::getCurrent(){ return current; }
QString Battery::getState() { return state; }
QString Battery::getHealth() { return health; }
int Battery::getTemperature(){ return temperature; }
bool Battery::getChargingEnabled() { return chargingEnabled; }
bool Battery::getChargerConnected() { return chargerConnected; }

View file

@ -36,6 +36,9 @@ class Battery : public QObject
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
Q_PROPERTY(bool chargingEnabled READ getChargingEnabled NOTIFY chargingEnabledChanged)
Q_PROPERTY(QString health READ getHealth NOTIFY healthChanged)
Q_PROPERTY(int temperature READ getTemperature NOTIFY temperatureChanged)
public:
Battery(Settings* newSettings, Logger* newLogger, QObject* parent = nullptr);
~Battery();
@ -46,6 +49,9 @@ public:
bool getChargerConnected();
QString getState();
QString getHealth();
int getTemperature();
bool getChargingEnabled();
public slots:
@ -60,6 +66,9 @@ private:
Settings* settings = nullptr;
Logger* logger = nullptr;
QFile* temperatureFile = nullptr;
QFile* healthFile = nullptr;
// Default values:
int charge = 100; // 100% full
int current = 0; // Not charging/discharging
@ -81,12 +90,17 @@ private:
QString nextState = state;
bool nextChargingEnabled = chargingEnabled;
QString nextHealth = health;
int nextTemperature = temperature;
signals:
void chargeChanged(int);
void currentChanged(int);
void stateChanged(QString);
void chargingEnabledChanged(bool);
void chargerConnectedChanged(bool);
void healthChanged(QString);
void temperatureChanged(int);
};
#endif // BATTERY_H