[AC] Support USB+AC Charging: application
This commit is contained in:
parent
2c48109a71
commit
af767e4b09
2 changed files with 34 additions and 1 deletions
|
@ -79,6 +79,20 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO
|
||||||
|
|
||||||
logL("Charger status file: " + (chargerConnectedFile ? chargerConnectedFile->fileName() : notFound));
|
logL("Charger status file: " + (chargerConnectedFile ? chargerConnectedFile->fileName() : notFound));
|
||||||
|
|
||||||
|
// Number: 0 or 1
|
||||||
|
filenames.clear();
|
||||||
|
filenames << "/sys/class/power_supply/ac/present"
|
||||||
|
<< "/sys/class/power_supply/axp813-ac/present";
|
||||||
|
|
||||||
|
foreach(const QString& file, filenames) {
|
||||||
|
if(!acConnectedFile && QFile::exists(file)) {
|
||||||
|
acConnectedFile = new QFile(file, this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logL("AC status file: " + (acConnectedFile ? acConnectedFile->fileName() : notFound));
|
||||||
|
|
||||||
// Number: temperature
|
// Number: temperature
|
||||||
filenames.clear();
|
filenames.clear();
|
||||||
filenames << "/sys/class/power_supply/battery/temp"
|
filenames << "/sys/class/power_supply/battery/temp"
|
||||||
|
@ -170,6 +184,16 @@ void Battery::updateData()
|
||||||
chargerConnectedFile->close();
|
chargerConnectedFile->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(acConnectedFile && acConnectedFile->open(QIODevice::ReadOnly)) {
|
||||||
|
nextAcConnected = acConnectedFile->readLine().trimmed().toInt();
|
||||||
|
if(nextAcConnected != acConnected) {
|
||||||
|
acConnected = nextAcConnected;
|
||||||
|
emit acConnectedChanged(acConnected);
|
||||||
|
logM(QString("AC: %1").arg(acConnected ? "connected" : "disconnected"));
|
||||||
|
}
|
||||||
|
acConnectedFile->close();
|
||||||
|
}
|
||||||
|
|
||||||
if(stateFile && 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) {
|
||||||
|
@ -183,7 +207,7 @@ void Battery::updateData()
|
||||||
if(currentFile && currentFile->open(QIODevice::ReadOnly)) {
|
if(currentFile && currentFile->open(QIODevice::ReadOnly)) {
|
||||||
current = currentFile->readLine().trimmed().toInt();
|
current = currentFile->readLine().trimmed().toInt();
|
||||||
if(!invertDecided) {
|
if(!invertDecided) {
|
||||||
invertCurrent = (!chargerConnected && current > 10);
|
invertCurrent = (!chargerConnected && !acConnected && current > 10);
|
||||||
if(invertCurrent) logL("Battery current inverted");
|
if(invertCurrent) logL("Battery current inverted");
|
||||||
else logL("Battery current not inverted");
|
else logL("Battery current not inverted");
|
||||||
invertDecided = true;
|
invertDecided = true;
|
||||||
|
@ -230,3 +254,5 @@ int Battery::getTemperature(){ return temperature; }
|
||||||
bool Battery::getChargingEnabled() { return chargingEnabled; }
|
bool Battery::getChargingEnabled() { return chargingEnabled; }
|
||||||
|
|
||||||
bool Battery::getChargerConnected() { return chargerConnected; }
|
bool Battery::getChargerConnected() { return chargerConnected; }
|
||||||
|
|
||||||
|
bool Battery::getAcConnected() { return acConnected; }
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Battery : public QObject
|
||||||
Q_PROPERTY(int current READ getCurrent NOTIFY currentChanged)
|
Q_PROPERTY(int current READ getCurrent NOTIFY currentChanged)
|
||||||
Q_PROPERTY(int maxChargeCurrent READ getMaxChargeCurrent)
|
Q_PROPERTY(int maxChargeCurrent READ getMaxChargeCurrent)
|
||||||
Q_PROPERTY(bool chargerConnected READ getChargerConnected NOTIFY chargerConnectedChanged)
|
Q_PROPERTY(bool chargerConnected READ getChargerConnected NOTIFY chargerConnectedChanged)
|
||||||
|
Q_PROPERTY(bool acConnected READ getAcConnected NOTIFY acConnectedChanged)
|
||||||
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
|
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
|
||||||
Q_PROPERTY(bool chargingEnabled READ getChargingEnabled NOTIFY chargingEnabledChanged)
|
Q_PROPERTY(bool chargingEnabled READ getChargingEnabled NOTIFY chargingEnabledChanged)
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ public:
|
||||||
int getMaxChargeCurrent();
|
int getMaxChargeCurrent();
|
||||||
bool getCharging();
|
bool getCharging();
|
||||||
bool getChargerConnected();
|
bool getChargerConnected();
|
||||||
|
bool getAcConnected();
|
||||||
QString getState();
|
QString getState();
|
||||||
|
|
||||||
QString getHealth();
|
QString getHealth();
|
||||||
|
@ -62,6 +64,7 @@ private:
|
||||||
QFile* chargeFile = nullptr;
|
QFile* chargeFile = nullptr;
|
||||||
QFile* currentFile = nullptr;
|
QFile* currentFile = nullptr;
|
||||||
QFile* chargerConnectedFile = nullptr;
|
QFile* chargerConnectedFile = nullptr;
|
||||||
|
QFile* acConnectedFile = nullptr;
|
||||||
QFile* stateFile = nullptr;
|
QFile* stateFile = nullptr;
|
||||||
QFile* chargingEnabledFile = nullptr;
|
QFile* chargingEnabledFile = nullptr;
|
||||||
QFile* maxChargeCurrentFile = nullptr;
|
QFile* maxChargeCurrentFile = nullptr;
|
||||||
|
@ -75,6 +78,7 @@ private:
|
||||||
int charge = 100; // 100% full
|
int charge = 100; // 100% full
|
||||||
int current = 0; // Not charging/discharging
|
int current = 0; // Not charging/discharging
|
||||||
bool chargerConnected = false; // Charger plugged in
|
bool chargerConnected = false; // Charger plugged in
|
||||||
|
bool acConnected = false; // AC plugged in
|
||||||
QString state = "idle"; // dis/charging, idle, unknown
|
QString state = "idle"; // dis/charging, idle, unknown
|
||||||
bool chargingEnabled = true; // Only ever disabled manually
|
bool chargingEnabled = true; // Only ever disabled manually
|
||||||
int maxChargeCurrent = 0; // Charge current limit in micro amps
|
int maxChargeCurrent = 0; // Charge current limit in micro amps
|
||||||
|
@ -91,9 +95,11 @@ private:
|
||||||
bool invertDecided = false;
|
bool invertDecided = false;
|
||||||
|
|
||||||
bool nextChargerConnected = chargerConnected;
|
bool nextChargerConnected = chargerConnected;
|
||||||
|
bool nextAcConnected = acConnected;
|
||||||
QString nextState = state;
|
QString nextState = state;
|
||||||
bool nextChargingEnabled = chargingEnabled;
|
bool nextChargingEnabled = chargingEnabled;
|
||||||
|
|
||||||
|
|
||||||
QString nextHealth = health;
|
QString nextHealth = health;
|
||||||
int nextTemperature = temperature;
|
int nextTemperature = temperature;
|
||||||
|
|
||||||
|
@ -103,6 +109,7 @@ signals:
|
||||||
void stateChanged(QString);
|
void stateChanged(QString);
|
||||||
void chargingEnabledChanged(bool);
|
void chargingEnabledChanged(bool);
|
||||||
void chargerConnectedChanged(bool);
|
void chargerConnectedChanged(bool);
|
||||||
|
void acConnectedChanged(bool);
|
||||||
void healthChanged(QString);
|
void healthChanged(QString);
|
||||||
void temperatureChanged(int);
|
void temperatureChanged(int);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue