diff --git a/application/qml/pages/MainPage.qml b/application/qml/pages/MainPage.qml
index f43a8cd..bd4159f 100644
--- a/application/qml/pages/MainPage.qml
+++ b/application/qml/pages/MainPage.qml
@@ -153,6 +153,11 @@ Page {
label: qsTr("Charge:")
value: battery.charge + "%"
}
+ MyDetailItem {
+ label: qsTr("Current:")
+ value: Math.floor(battery.current / 1000) + " mA"
+ }
+
MyDetailItem {
label: qsTr("Charger connected:")
value: battery.chargerConnected ? qsTr("yes") : qsTr("no")
diff --git a/application/src/battery.cpp b/application/src/battery.cpp
index aac7688..35b87e1 100644
--- a/application/src/battery.cpp
+++ b/application/src/battery.cpp
@@ -26,6 +26,10 @@ Battery::Battery(Settings* newSettings, QObject* parent) : QObject(parent)
chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this);
qInfo() << "Reading capacity from" << chargeFile->fileName();
+ // Number: battery/charging current, e.g. -1450000 (-145mA)
+ currentFile = new QFile("/sys/class/power_supply/battery/current_now", this);
+ qInfo() << "Reading current from" << currentFile->fileName();
+
// String: charging, discharging, full, empty, unknown (others?)
stateFile = new QFile("/sys/class/power_supply/battery/status", this);
qInfo() << "Reading charge state from" << stateFile->fileName();
@@ -105,6 +109,15 @@ void Battery::updateData()
}
chargeFile->close();
}
+ if(currentFile && currentFile->open(QIODevice::ReadOnly)) {
+ nextCurrent = currentFile->readLine().trimmed().toInt();
+ if(nextCurrent != current) {
+ current = nextCurrent;
+ emit currentChanged(current);
+ qDebug() << "Current:" << current;
+ }
+ currentFile->close();
+ }
if(chargerConnectedFile && chargerConnectedFile->open(QIODevice::ReadOnly)) {
nextChargerConnected = chargerConnectedFile->readLine().trimmed().toInt();
if(nextChargerConnected != chargerConnected) {
@@ -127,6 +140,8 @@ void Battery::updateData()
int Battery::getCharge(){ return charge; }
+int Battery::getCurrent(){ return current; }
+
QString Battery::getState() { return state; }
bool Battery::getChargingEnabled() { return chargingEnabled; }
diff --git a/application/src/battery.h b/application/src/battery.h
index 535fa4c..bd8b159 100644
--- a/application/src/battery.h
+++ b/application/src/battery.h
@@ -31,6 +31,7 @@ class Battery : public QObject
{
Q_OBJECT
Q_PROPERTY(int charge READ getCharge NOTIFY chargeChanged)
+ Q_PROPERTY(int current READ getCurrent NOTIFY currentChanged)
Q_PROPERTY(bool chargerConnected READ getChargerConnected NOTIFY chargerConnectedChanged)
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
Q_PROPERTY(bool chargingEnabled READ getChargingEnabled WRITE setChargingEnabled NOTIFY chargingEnabledChanged)
@@ -40,6 +41,7 @@ public:
~Battery();
int getCharge();
+ int getCurrent();
bool getCharging();
bool getChargerConnected();
QString getState();
@@ -52,6 +54,7 @@ public slots:
private:
QFile* chargeFile = nullptr;
+ QFile* currentFile = nullptr;
QFile* chargerConnectedFile = nullptr;
QFile* stateFile = nullptr;
QFile* chargingEnabledFile = nullptr;
@@ -59,6 +62,7 @@ private:
// Default values:
int charge = 100; // 100% full
+ int current = 0; // Not charging/discharging
bool chargerConnected = false; // Charger plugged in
QString state = "idle"; // dis/charging, idle, unknown
bool chargingEnabled = true; // Only ever disabled manually
@@ -68,12 +72,14 @@ private:
bool chargerIsEnabled = true;
int nextCharge = charge;
+ int nextCurrent = current;
bool nextChargerConnected = chargerConnected;
QString nextState = state;
bool nextChargingEnabled = chargingEnabled;
signals:
void chargeChanged(int);
+ void currentChanged(int);
void stateChanged(QString);
void chargingEnabledChanged(bool);
void chargerConnectedChanged(bool);
diff --git a/application/translations/harbour-batterybuddy.ts b/application/translations/harbour-batterybuddy.ts
index 0b31b64..5065065 100644
--- a/application/translations/harbour-batterybuddy.ts
+++ b/application/translations/harbour-batterybuddy.ts
@@ -235,6 +235,10 @@
+
+
+
+
Settings