From ce994a0d1ed7053ba566110275aaf2c6829fc963 Mon Sep 17 00:00:00 2001 From: "Peter G. (nephros)" Date: Sun, 2 May 2021 16:00:00 +0200 Subject: [PATCH 01/18] support weird US temperature measurement --- application/qml/pages/MainPage.qml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/application/qml/pages/MainPage.qml b/application/qml/pages/MainPage.qml index d60147a..abfc258 100644 --- a/application/qml/pages/MainPage.qml +++ b/application/qml/pages/MainPage.qml @@ -177,9 +177,7 @@ Page { } MyDetailItem { label: qsTr("Temperature:") - // TODO: use weird degrees for US users - //value: useImperial ? celsiusToFahrenheit(battery.temperature) + " F" : Math.floor(battery.temperature / 10) + " °C" - value: Math.floor(battery.temperature / 10) + " °C" + value: (Qt.locale().measurementSystem == Locale.ImperialUSSystem) ? Math.floor((battery.temperature / 10) * 1.8 + 32) + " F" : Math.floor(battery.temperature / 10) + " °C" } } } From 93fa677a6fcd4234c09c0b91bf13d9c815d44006 Mon Sep 17 00:00:00 2001 From: "Peter G. (nephros)" Date: Sun, 2 May 2021 12:33:32 +0200 Subject: [PATCH 02/18] prepare settings for health alert --- application/qml/pages/SettingsPage.qml | 55 ++++++++++++++++++++++++++ application/src/settings.cpp | 38 +++++++++++------- application/src/settings.h | 23 +++++++++++ 3 files changed, 102 insertions(+), 14 deletions(-) diff --git a/application/qml/pages/SettingsPage.qml b/application/qml/pages/SettingsPage.qml index 3c9b06c..ded6bbc 100644 --- a/application/qml/pages/SettingsPage.qml +++ b/application/qml/pages/SettingsPage.qml @@ -43,9 +43,11 @@ Page { highLimitSlider.value = settings.highLimit lowLimitSlider.value = settings.lowLimit highAlertSlider.value = settings.highAlert + healthAlertSlider.value = settings.healthAlert lowAlertSlider.value = settings.lowAlert highIntervalSlider.value = settings.highNotificationsInterval lowIntervalSlider.value = settings.lowNotificationsInterval + healthIntervalSlider.value = settings.healthNotificationsInterval if(logger.debug) logger.log("SettingsPage values updated") daemonCheck.start() } @@ -365,6 +367,59 @@ Page { smallChange: 10 largeChange: 60 } + + SectionHeader { text: qsTr("Battery health notification") } + + MySlider { + id: healthAlertSlider + minimumValue: 0 + maximumValue: 2 + stepSize: 1 + onValueChanged: { + if(healthAlertSlider.value <= value) + healthAlertSlider.value = value + 1 + } + valueText: { + if (value === 0) + return "None" + if (value === 1) + return "Warning" + if (value === 2) + return "Critical" + } + onReleased: save() + function save(){ + settings.healthAlert = value + } + } + + SectionHeader { text: qsTr("Battery health warning interval") } + + MySlider { + id: healthIntervalSlider + minimumValue: 50 + maximumValue: 610 + stepSize: 10 + valueText: updateValueText() + onValueChanged: updateValueText() + function updateValueText() { + if(value == 50) + return qsTr("Once") + if(value == 610) + return qsTr("Never") + return Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60) + } + onReleased: save() + function save() { + settings.healthNotificationsInterval = value + } + } + + AdjustmentButtons { + targetSlider: healthIntervalSlider + smallChange: 10 + largeChange: 60 + } } } } diff --git a/application/src/settings.cpp b/application/src/settings.cpp index 04ef177..fe0107a 100644 --- a/application/src/settings.cpp +++ b/application/src/settings.cpp @@ -56,20 +56,24 @@ Settings::~Settings() } // Getters condensed. -int Settings::getLowAlert() { return lowAlert; } -int Settings::getHighAlert() { return highAlert; } -int Settings::getHighNotificationsInterval() { return highNotificationsInterval; } -int Settings::getLowNotificationsInterval() { return lowNotificationsInterval; } -int Settings::getLowLimit() { return lowLimit; } -int Settings::getHighLimit() { return highLimit; } -bool Settings::getLimitEnabled() { return limitEnabled == 1; } -QString Settings::getLowAlertFile() { return lowAlertFile; } -QString Settings::getHighAlertFile() { return highAlertFile; } -QString Settings::getLogFilename() { return logFilename; } -QString Settings::getNotificationTitle() { return notificationTitle; } -QString Settings::getNotificationLowText() { return notificationLowText; } -QString Settings::getNotificationHighText() { return notificationHighText; } -int Settings::getLogLevel() { return logLevel; } +int Settings::getLowAlert() { return lowAlert; } +int Settings::getHighAlert() { return highAlert; } +int Settings::getHealthAlert() { return healthAlert; } +int Settings::getHighNotificationsInterval() { return highNotificationsInterval; } +int Settings::getLowNotificationsInterval() { return lowNotificationsInterval; } +int Settings::getHealthNotificationsInterval() { return healthNotificationsInterval; } +int Settings::getLowLimit() { return lowLimit; } +int Settings::getHighLimit() { return highLimit; } +bool Settings::getLimitEnabled() { return limitEnabled == 1; } +QString Settings::getLowAlertFile() { return lowAlertFile; } +QString Settings::getHighAlertFile() { return highAlertFile; } +QString Settings::getHealthAlertFile() { return healthAlertFile; } +QString Settings::getLogFilename() { return logFilename; } +QString Settings::getNotificationTitle() { return notificationTitle; } +QString Settings::getNotificationLowText() { return notificationLowText; } +QString Settings::getNotificationHighText() { return notificationHighText; } +QString Settings::getNotificationHealthText() { return notificationHealthText; } +int Settings::getLogLevel() { return logLevel; } void Settings::setLowAlert(const int newLimit) { if(saveInteger(sLowAlert, newLimit, lowAlert)) { @@ -83,6 +87,12 @@ void Settings::setHighAlert(const int newLimit) { } } +void Settings::setHealthAlert(const int newLimit) { + if(saveInteger(sHealthAlert, newLimit, healthAlert)) { + emit healthAlertChanged(healthAlert); + } +} + void Settings::setHighNotificationsInterval(const int newInterval) { if(saveInteger(sHighNotificationsInterval, newInterval, highNotificationsInterval)) { emit highNotificationsIntervalChanged(highNotificationsInterval); diff --git a/application/src/settings.h b/application/src/settings.h index eecc6a0..497ba44 100644 --- a/application/src/settings.h +++ b/application/src/settings.h @@ -27,16 +27,20 @@ class Settings : public QObject Q_OBJECT Q_PROPERTY(int highAlert READ getHighAlert WRITE setHighAlert NOTIFY highAlertChanged) Q_PROPERTY(int lowAlert READ getLowAlert WRITE setLowAlert NOTIFY lowAlertChanged) + Q_PROPERTY(int healthAlert READ getHealthAlert WRITE setHealthAlert NOTIFY healthAlertChanged) Q_PROPERTY(int highNotificationsInterval READ getHighNotificationsInterval WRITE setHighNotificationsInterval NOTIFY highNotificationsIntervalChanged) Q_PROPERTY(int lowNotificationsInterval READ getLowNotificationsInterval WRITE setLowNotificationsInterval NOTIFY lowNotificationsIntervalChanged) + Q_PROPERTY(int healthNotificationsInterval READ getHealthNotificationsInterval WRITE setHealthNotificationsInterval NOTIFY healthNotificationsIntervalChanged) Q_PROPERTY(int highLimit READ getHighLimit WRITE setHighLimit NOTIFY highLimitChanged) Q_PROPERTY(int lowLimit READ getLowLimit WRITE setLowLimit NOTIFY lowLimitChanged) Q_PROPERTY(bool limitEnabled READ getLimitEnabled WRITE setLimitEnabled NOTIFY limitEnabledChanged) Q_PROPERTY(QString highAlertFile READ getHighAlertFile NOTIFY highAlertFileChanged) Q_PROPERTY(QString lowAlertFile READ getLowAlertFile NOTIFY lowAlertFileChanged) + Q_PROPERTY(QString healthAlertFile READ getHealthAlertFile NOTIFY healthAlertFileChanged) Q_PROPERTY(QString notificationTitle READ getNotificationTitle WRITE setNotificationTitle NOTIFY notificationTitleChanged) Q_PROPERTY(QString notificationLowText READ getNotificationLowText WRITE setNotificationLowText NOTIFY notificationLowTextChanged) Q_PROPERTY(QString notificationHighText READ getNotificationHighText WRITE setNotificationHighText NOTIFY notificationHighTextChanged) + Q_PROPERTY(QString notificationHealthText READ getNotificationHealthText WRITE setNotificationHealthText NOTIFY notificationHealthTextChanged) Q_PROPERTY(QString logFilename READ getLogFilename NOTIFY logFilenameChanged) Q_PROPERTY(int logLevel READ getLogLevel WRITE setLogLevel NOTIFY logLevelChanged) @@ -46,29 +50,36 @@ public: int getLowAlert(); int getHighAlert(); + int getHealthAlert(); int getHighNotificationsInterval(); int getLowNotificationsInterval(); + int getHealthNotificationsInterval(); int getLowLimit(); int getHighLimit(); bool getLimitEnabled(); QString getLowAlertFile(); QString getHighAlertFile(); + QString getHealthAlertFile(); QString getNotificationTitle(); QString getNotificationLowText(); QString getNotificationHighText(); + QString getNotificationHealthText(); QString getLogFilename(); int getLogLevel(); void setLowAlert(const int newLimit); void setHighAlert(const int newLimit); + void setHealthAlert(const int newLimit); void setHighNotificationsInterval(const int newInterval); void setLowNotificationsInterval(const int newInterval); + void setHealthNotificationsInterval(const int newInterval); void setLowLimit(const int newLimit); void setHighLimit(const int newLimit); void setLimitEnabled(const bool newEnabled); void setNotificationTitle(const QString newText); void setNotificationLowText(const QString newText); void setNotificationHighText(const QString newText); + void setNotificationHealthText(const QString newText); void setLogLevel(const int newLogLevel); private: @@ -79,32 +90,40 @@ private: // Default values int lowAlert = 25; int highAlert = 75; + int healthAlert = 1; // warn int highNotificationsInterval = 60; int lowNotificationsInterval = 60; + int healthNotificationsInterval = 60; int limitEnabled = 1; // Converted to boolean for QML int lowLimit = 65; int highLimit = 70; QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav"; QString highAlertFile = "/usr/share/sounds/jolla-ambient/stereo/positive_confirmation.wav"; + QString healthAlertFile = lowAlertFile; QString notificationTitle; QString notificationLowText; QString notificationHighText; + QString notificationHealthText; QString logFilename; int logLevel; // To avoid repeating the same string over and over and over... const char* sLowAlert = "lowAlert"; const char* sHighAlert = "highAlert"; + const char* sHealthAlert = "healthAlert"; const char* sHighNotificationsInterval = "highNotificationsInterval"; const char* sLowNotificationsInterval = "lowNotificationsInterval"; + const char* sHealthNotificationsInterval = "healthNotificationsInterval"; const char* sLimitEnabled = "limitEnabled"; const char* sLowLimit = "lowLimit"; const char* sHighLimit = "highLimit"; const char* sLowAlertFile = "lowAlertFile"; const char* sHighAlertFile = "highAlertFile"; + const char* sHealthAlertFile = "healthAlertFile"; const char* sNotificationTitle = "notificationTitle"; const char* sNotificationLowText = "notificationLowText"; const char* sNotificationHighText = "notificationHighText"; + const char* sNotificationHealthText = "notificationHealthText"; const char* sLogFilename = "logFilename"; const char* sLogLevel = "logLevel"; @@ -117,16 +136,20 @@ private: signals: void lowAlertChanged(int); void highAlertChanged(int); + void healthAlertChanged(int); void highNotificationsIntervalChanged(int); void lowNotificationsIntervalChanged(int); + void healthNotificationsIntervalChanged(int); void limitEnabledChanged(bool); void lowLimitChanged(int); void highLimitChanged(int); void lowAlertFileChanged(QString); void highAlertFileChanged(QString); + void healthAlertFileChanged(QString); void notificationTitleChanged(QString); void notificationLowTextChanged(QString); void notificationHighTextChanged(QString); + void notificationHealthTextChanged(QString); void logFilenameChanged(QString); void logLevelChanged(int); }; From dfbf1ec078020f59139817956c5c588e4342f4da Mon Sep 17 00:00:00 2001 From: "Peter G. (nephros)" Date: Sun, 2 May 2021 11:33:45 +0200 Subject: [PATCH 03/18] implement settings for health alert --- application/qml/pages/SettingsPage.qml | 51 ++++++++++++++++---------- application/src/settings.cpp | 15 ++++++++ 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/application/qml/pages/SettingsPage.qml b/application/qml/pages/SettingsPage.qml index ded6bbc..040f479 100644 --- a/application/qml/pages/SettingsPage.qml +++ b/application/qml/pages/SettingsPage.qml @@ -43,7 +43,7 @@ Page { highLimitSlider.value = settings.highLimit lowLimitSlider.value = settings.lowLimit highAlertSlider.value = settings.highAlert - healthAlertSlider.value = settings.healthAlert + healthSelector.currentIndex = settings.healthAlert lowAlertSlider.value = settings.lowAlert highIntervalSlider.value = settings.highNotificationsInterval lowIntervalSlider.value = settings.lowNotificationsInterval @@ -368,28 +368,39 @@ Page { largeChange: 60 } + Label { + x: Theme.paddingLarge + text: qsTr("Health Notification settings") + color: Theme.highlightColor + } + Label { + text: qsTr("Display visual and audible notifications about battery health, when the battery temperature is below or above safe values.") + anchors { + left: parent.left + right: parent.right + leftMargin: Theme.horizontalPageMargin*2 + rightMargin: Theme.horizontalPageMargin + } + color: Theme.primaryColor + font.pixelSize: Theme.fontSizeExtraSmall + wrapMode: Text.Wrap + } + SectionHeader { text: qsTr("Battery health notification") } - MySlider { - id: healthAlertSlider - minimumValue: 0 - maximumValue: 2 - stepSize: 1 - onValueChanged: { - if(healthAlertSlider.value <= value) - healthAlertSlider.value = value + 1 + ComboBox { + id: healthSelector + width: parent.width + label: qsTr("Warn on Health status" + ":") + currentIndex: settings.healthAlert + menu: ContextMenu { + MenuItem { text: qsTr("None") } + MenuItem { text: qsTr("Warning") } + MenuItem { text: qsTr("Critical") } } - valueText: { - if (value === 0) - return "None" - if (value === 1) - return "Warning" - if (value === 2) - return "Critical" - } - onReleased: save() - function save(){ - settings.healthAlert = value + onValueChanged: save() + function save() { + settings.healthAlert = healthSelector.currentIndex } } diff --git a/application/src/settings.cpp b/application/src/settings.cpp index fe0107a..29bbe64 100644 --- a/application/src/settings.cpp +++ b/application/src/settings.cpp @@ -31,8 +31,10 @@ Settings::Settings(Logger *newLogger, QObject *parent) : QObject(parent) // Read in the values loadInteger(sLowAlert, lowAlert, 5, 99); loadInteger(sHighAlert, highAlert, 6, 100); + loadInteger(sHealthAlert, healthAlert, 0, 2); loadInteger(sHighNotificationsInterval, highNotificationsInterval, 50, 610); loadInteger(sLowNotificationsInterval, lowNotificationsInterval, 50, 610); + loadInteger(sHealthNotificationsInterval, healthNotificationsInterval, 50, 610); loadInteger(sLimitEnabled, limitEnabled, 0, 1); loadInteger(sLowLimit, lowLimit, 5, 99); loadInteger(sHighLimit, highLimit, 6, 100); @@ -43,10 +45,12 @@ Settings::Settings(Logger *newLogger, QObject *parent) : QObject(parent) loadString(sNotificationTitle, notificationTitle); loadString(sNotificationLowText, notificationLowText); loadString(sNotificationHighText, notificationHighText); + loadString(sNotificationHealthText, notificationHealthText); saveString(sNotificationTitle, tr("Battery charge %1%"), notificationTitle); saveString(sNotificationLowText, tr("Please connect the charger."), notificationLowText); saveString(sNotificationHighText, tr("Please disconnect the charger."), notificationHighText); + saveString(sNotificationHealthText, tr("Battery health"), notificationHealthText); } Settings::~Settings() @@ -105,6 +109,12 @@ void Settings::setLowNotificationsInterval(const int newInterval) { } } +void Settings::setHealthNotificationsInterval(const int newInterval) { + if(saveInteger(sHealthNotificationsInterval, newInterval, healthNotificationsInterval)) { + emit healthNotificationsIntervalChanged(healthNotificationsInterval); + } +} + void Settings::setLowLimit(const int newLimit) { if(saveInteger(sLowLimit, newLimit, lowLimit)) { emit lowLimitChanged(lowLimit); @@ -136,6 +146,11 @@ void Settings::setNotificationHighText(const QString newText) { emit notificationHighTextChanged(notificationHighText); } +void Settings::setNotificationHealthText(const QString newText) { + if(saveString(sNotificationHealthText, newText, notificationHealthText)) + emit notificationHealthTextChanged(notificationHealthText); +} + void Settings::setLogLevel(const int newLogLevel) { if(saveInteger(sLogLevel, newLogLevel, logLevel)) emit logLevelChanged(logLevel); From 91e6cad41455811d62d99c04f83182158ae1897f Mon Sep 17 00:00:00 2001 From: "Peter G. (nephros)" Date: Sun, 2 May 2021 17:18:25 +0200 Subject: [PATCH 04/18] Add several strings for health notification --- application/src/settings.cpp | 28 ++++++++++++++++++++++------ application/src/settings.h | 24 ++++++++++++++++++------ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/application/src/settings.cpp b/application/src/settings.cpp index 29bbe64..ebf9e42 100644 --- a/application/src/settings.cpp +++ b/application/src/settings.cpp @@ -45,12 +45,16 @@ Settings::Settings(Logger *newLogger, QObject *parent) : QObject(parent) loadString(sNotificationTitle, notificationTitle); loadString(sNotificationLowText, notificationLowText); loadString(sNotificationHighText, notificationHighText); - loadString(sNotificationHealthText, notificationHealthText); + loadString(sNotificationHealthTitle, notificationHealthTitle); + loadString(sNotificationHealthWarnText, notificationHealthWarnText); + loadString(sNotificationHealthCritText, notificationHealthCritText); saveString(sNotificationTitle, tr("Battery charge %1%"), notificationTitle); saveString(sNotificationLowText, tr("Please connect the charger."), notificationLowText); saveString(sNotificationHighText, tr("Please disconnect the charger."), notificationHighText); - saveString(sNotificationHealthText, tr("Battery health"), notificationHealthText); + saveString(sNotificationHealthTitle, tr("Battery health %1"), notificationHealthTitle); + saveString(sNotificationHealthWarnText, tr("Battery health is not good"), notificationHealthWarnText); + saveString(sNotificationHealthCritText, tr("Battery health is critical"), notificationHealthCritText); } Settings::~Settings() @@ -76,7 +80,9 @@ QString Settings::getLogFilename() { return logFilename; } QString Settings::getNotificationTitle() { return notificationTitle; } QString Settings::getNotificationLowText() { return notificationLowText; } QString Settings::getNotificationHighText() { return notificationHighText; } -QString Settings::getNotificationHealthText() { return notificationHealthText; } +QString Settings::getNotificationHealthTitle() { return notificationHealthTitle; } +QString Settings::getNotificationHealthWarnText() { return notificationHealthWarnText; } +QString Settings::getNotificationHealthCritText() { return notificationHealthCritText; } int Settings::getLogLevel() { return logLevel; } void Settings::setLowAlert(const int newLimit) { @@ -146,9 +152,19 @@ void Settings::setNotificationHighText(const QString newText) { emit notificationHighTextChanged(notificationHighText); } -void Settings::setNotificationHealthText(const QString newText) { - if(saveString(sNotificationHealthText, newText, notificationHealthText)) - emit notificationHealthTextChanged(notificationHealthText); +void Settings::setNotificationHealthTitle(const QString newText) { + if(saveString(sNotificationHealthTitle, newText, notificationTitle)) + emit notificationHealthTitleChanged(notificationTitle); +} + +void Settings::setNotificationHealthWarnText(const QString newText) { + if(saveString(sNotificationHealthWarnText, newText, notificationHealthWarnText)) + emit notificationHealthWarnTextChanged(notificationHealthWarnText); +} + +void Settings::setNotificationHealthCritText(const QString newText) { + if(saveString(sNotificationHealthCritText, newText, notificationHealthCritText)) + emit notificationHealthCritTextChanged(notificationHealthCritText); } void Settings::setLogLevel(const int newLogLevel) { diff --git a/application/src/settings.h b/application/src/settings.h index 497ba44..b30fc7d 100644 --- a/application/src/settings.h +++ b/application/src/settings.h @@ -40,7 +40,9 @@ class Settings : public QObject Q_PROPERTY(QString notificationTitle READ getNotificationTitle WRITE setNotificationTitle NOTIFY notificationTitleChanged) Q_PROPERTY(QString notificationLowText READ getNotificationLowText WRITE setNotificationLowText NOTIFY notificationLowTextChanged) Q_PROPERTY(QString notificationHighText READ getNotificationHighText WRITE setNotificationHighText NOTIFY notificationHighTextChanged) - Q_PROPERTY(QString notificationHealthText READ getNotificationHealthText WRITE setNotificationHealthText NOTIFY notificationHealthTextChanged) + Q_PROPERTY(QString notificationHealthTitle READ getNotificationHealthTitle WRITE setNotificationHealthTitle NOTIFY notificationHealthTitleChanged) + Q_PROPERTY(QString notificationHealthWarnText READ getNotificationHealthWarnText WRITE setNotificationHealthWarnText NOTIFY notificationHealthWarnTextChanged) + Q_PROPERTY(QString notificationHealthCritText READ getNotificationHealthCritText WRITE setNotificationHealthCritText NOTIFY notificationHealthCritTextChanged) Q_PROPERTY(QString logFilename READ getLogFilename NOTIFY logFilenameChanged) Q_PROPERTY(int logLevel READ getLogLevel WRITE setLogLevel NOTIFY logLevelChanged) @@ -63,7 +65,9 @@ public: QString getNotificationTitle(); QString getNotificationLowText(); QString getNotificationHighText(); - QString getNotificationHealthText(); + QString getNotificationHealthTitle(); + QString getNotificationHealthWarnText(); + QString getNotificationHealthCritText(); QString getLogFilename(); int getLogLevel(); @@ -79,7 +83,9 @@ public: void setNotificationTitle(const QString newText); void setNotificationLowText(const QString newText); void setNotificationHighText(const QString newText); - void setNotificationHealthText(const QString newText); + void setNotificationHealthTitle(const QString newText); + void setNotificationHealthWarnText(const QString newText); + void setNotificationHealthCritText(const QString newText); void setLogLevel(const int newLogLevel); private: @@ -103,7 +109,9 @@ private: QString notificationTitle; QString notificationLowText; QString notificationHighText; - QString notificationHealthText; + QString notificationHealthTitle; + QString notificationHealthWarnText; + QString notificationHealthCritText; QString logFilename; int logLevel; @@ -123,7 +131,9 @@ private: const char* sNotificationTitle = "notificationTitle"; const char* sNotificationLowText = "notificationLowText"; const char* sNotificationHighText = "notificationHighText"; - const char* sNotificationHealthText = "notificationHealthText"; + const char* sNotificationHealthTitle = "notificationHealthTitle"; + const char* sNotificationHealthWarnText = "notificationHealthWarnText"; + const char* sNotificationHealthCritText = "notificationHealthCritText"; const char* sLogFilename = "logFilename"; const char* sLogLevel = "logLevel"; @@ -149,7 +159,9 @@ signals: void notificationTitleChanged(QString); void notificationLowTextChanged(QString); void notificationHighTextChanged(QString); - void notificationHealthTextChanged(QString); + void notificationHealthTitleChanged(QString); + void notificationHealthWarnTextChanged(QString); + void notificationHealthCritTextChanged(QString); void logFilenameChanged(QString); void logLevelChanged(int); }; From 3ca91d5e071d35f173daaa8c97a0bddef8f915eb Mon Sep 17 00:00:00 2001 From: "Peter G. (nephros)" Date: Sun, 2 May 2021 22:07:55 +0200 Subject: [PATCH 05/18] update German translation --- .../harbour-batterybuddy-de_DE.ts | 77 ++++++++++++++++--- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/application/translations/harbour-batterybuddy-de_DE.ts b/application/translations/harbour-batterybuddy-de_DE.ts index a0bf919..0bb3030 100644 --- a/application/translations/harbour-batterybuddy-de_DE.ts +++ b/application/translations/harbour-batterybuddy-de_DE.ts @@ -156,34 +156,34 @@ LogPage View log - + Logdatei ansehen Update - + Aktualisieren Copy - + Kopieren Log level - + Log Level Quiet Low log setting - + Still Verbose Medium log setting - + Mittel Debug High log setting - + Debug @@ -275,20 +275,43 @@ Current: Strom: + + Good + Battery is OK + die Batterie ist OK + + + Warm + Battery is warm + die Batterie ist warm + + + Overheated + Battery is very hot + die Batterie ist sehr heiss + + + Health: + Zustand: + + + Temperature: + Temperatur: + Settings Battery charge %1% - Akkustand %1% + Akkustand %1% Please connect the charger. - Bitte Ladegerät anschließen. + Bitte Ladegerät anschließen. Please disconnect the charger. - Bitte Ladegerät trennen. + Bitte Ladegerät trennen. @@ -364,7 +387,39 @@ View log - + Logdatei ansehen + + + Health Notification settings + Einstellungen zur Zustandbenachrichtigung + + + Display visual and audible notifications about battery health, when the battery temperature is below or above safe values. + Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald die Temperatur über gewissen Schwellwerten liegt. + + + Battery health notification + Zustandsbenachrichtigung + + + Warn on Health status: + Benachrichtigung bei Zustand: + + + None + Keine + + + Warning + Warnung + + + Critical + Kritisch + + + Battery health warning interval + Zustandsbenachrichtigungsintervall From eec28a8da7153c22f70739e78e46988b1355cd22 Mon Sep 17 00:00:00 2001 From: "Peter G. (nephros)" Date: Sun, 2 May 2021 23:07:50 +0200 Subject: [PATCH 06/18] improve wording --- application/qml/pages/SettingsPage.qml | 10 ++++---- .../harbour-batterybuddy-de_DE.ts | 24 +++++++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/application/qml/pages/SettingsPage.qml b/application/qml/pages/SettingsPage.qml index 040f479..7e71107 100644 --- a/application/qml/pages/SettingsPage.qml +++ b/application/qml/pages/SettingsPage.qml @@ -374,7 +374,7 @@ Page { color: Theme.highlightColor } Label { - text: qsTr("Display visual and audible notifications about battery health, when the battery temperature is below or above safe values.") + text: qsTr("Display visual and audible notifications about battery health, when the battery status exceeds safe values.
This usually means high temperature but can be affected by other factors depending on the hardware.") anchors { left: parent.left right: parent.right @@ -386,15 +386,15 @@ Page { wrapMode: Text.Wrap } - SectionHeader { text: qsTr("Battery health notification") } + SectionHeader { text: qsTr("Health notification") } ComboBox { id: healthSelector width: parent.width - label: qsTr("Warn on Health status" + ":") + label: qsTr("Notify on Health status" + ":") currentIndex: settings.healthAlert menu: ContextMenu { - MenuItem { text: qsTr("None") } + MenuItem { text: qsTr("Never") } MenuItem { text: qsTr("Warning") } MenuItem { text: qsTr("Critical") } } @@ -404,7 +404,7 @@ Page { } } - SectionHeader { text: qsTr("Battery health warning interval") } + SectionHeader { text: qsTr("Health notification interval") } MySlider { id: healthIntervalSlider diff --git a/application/translations/harbour-batterybuddy-de_DE.ts b/application/translations/harbour-batterybuddy-de_DE.ts index 0bb3030..758b046 100644 --- a/application/translations/harbour-batterybuddy-de_DE.ts +++ b/application/translations/harbour-batterybuddy-de_DE.ts @@ -395,19 +395,19 @@ Display visual and audible notifications about battery health, when the battery temperature is below or above safe values. - Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald die Temperatur über gewissen Schwellwerten liegt. + Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald die Temperatur über gewissen Schwellwerten liegt. Battery health notification - Zustandsbenachrichtigung + Zustandsbenachrichtigung Warn on Health status: - Benachrichtigung bei Zustand: + Benachrichtigung bei Zustand: None - Keine + Keine Warning @@ -419,6 +419,22 @@ Battery health warning interval + Zustandsbenachrichtigungsintervall + + + Display visual and audible notifications about battery health, when the battery status exceeds safe values.<br />This usually means high temperature but can be affected by other factors depending on the hardware. + Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald gewisse Schwellwerte erreicht werden.<br />Das betrifft meist die Temperatur, kann aber je nach Hardware auch andere Faktoren beinhalten. + + + Health notification + Zustandsbenachrichtigung + + + Notify on Health status: + Benachrichtigung zum Zustand: + + + Health notification interval Zustandsbenachrichtigungsintervall From c9281ccabdf8b6bebbb3ee22b71fe41e30f0fb52 Mon Sep 17 00:00:00 2001 From: "Peter G. (nephros)" Date: Sun, 2 May 2021 17:18:25 +0200 Subject: [PATCH 07/18] Add several strings for health notification update German translation improve wording --- application/qml/pages/SettingsPage.qml | 10 +- application/src/settings.cpp | 28 ++++-- application/src/settings.h | 24 +++-- .../harbour-batterybuddy-de_DE.ts | 93 ++++++++++++++++--- 4 files changed, 127 insertions(+), 28 deletions(-) diff --git a/application/qml/pages/SettingsPage.qml b/application/qml/pages/SettingsPage.qml index 040f479..7e71107 100644 --- a/application/qml/pages/SettingsPage.qml +++ b/application/qml/pages/SettingsPage.qml @@ -374,7 +374,7 @@ Page { color: Theme.highlightColor } Label { - text: qsTr("Display visual and audible notifications about battery health, when the battery temperature is below or above safe values.") + text: qsTr("Display visual and audible notifications about battery health, when the battery status exceeds safe values.
This usually means high temperature but can be affected by other factors depending on the hardware.") anchors { left: parent.left right: parent.right @@ -386,15 +386,15 @@ Page { wrapMode: Text.Wrap } - SectionHeader { text: qsTr("Battery health notification") } + SectionHeader { text: qsTr("Health notification") } ComboBox { id: healthSelector width: parent.width - label: qsTr("Warn on Health status" + ":") + label: qsTr("Notify on Health status" + ":") currentIndex: settings.healthAlert menu: ContextMenu { - MenuItem { text: qsTr("None") } + MenuItem { text: qsTr("Never") } MenuItem { text: qsTr("Warning") } MenuItem { text: qsTr("Critical") } } @@ -404,7 +404,7 @@ Page { } } - SectionHeader { text: qsTr("Battery health warning interval") } + SectionHeader { text: qsTr("Health notification interval") } MySlider { id: healthIntervalSlider diff --git a/application/src/settings.cpp b/application/src/settings.cpp index 29bbe64..ebf9e42 100644 --- a/application/src/settings.cpp +++ b/application/src/settings.cpp @@ -45,12 +45,16 @@ Settings::Settings(Logger *newLogger, QObject *parent) : QObject(parent) loadString(sNotificationTitle, notificationTitle); loadString(sNotificationLowText, notificationLowText); loadString(sNotificationHighText, notificationHighText); - loadString(sNotificationHealthText, notificationHealthText); + loadString(sNotificationHealthTitle, notificationHealthTitle); + loadString(sNotificationHealthWarnText, notificationHealthWarnText); + loadString(sNotificationHealthCritText, notificationHealthCritText); saveString(sNotificationTitle, tr("Battery charge %1%"), notificationTitle); saveString(sNotificationLowText, tr("Please connect the charger."), notificationLowText); saveString(sNotificationHighText, tr("Please disconnect the charger."), notificationHighText); - saveString(sNotificationHealthText, tr("Battery health"), notificationHealthText); + saveString(sNotificationHealthTitle, tr("Battery health %1"), notificationHealthTitle); + saveString(sNotificationHealthWarnText, tr("Battery health is not good"), notificationHealthWarnText); + saveString(sNotificationHealthCritText, tr("Battery health is critical"), notificationHealthCritText); } Settings::~Settings() @@ -76,7 +80,9 @@ QString Settings::getLogFilename() { return logFilename; } QString Settings::getNotificationTitle() { return notificationTitle; } QString Settings::getNotificationLowText() { return notificationLowText; } QString Settings::getNotificationHighText() { return notificationHighText; } -QString Settings::getNotificationHealthText() { return notificationHealthText; } +QString Settings::getNotificationHealthTitle() { return notificationHealthTitle; } +QString Settings::getNotificationHealthWarnText() { return notificationHealthWarnText; } +QString Settings::getNotificationHealthCritText() { return notificationHealthCritText; } int Settings::getLogLevel() { return logLevel; } void Settings::setLowAlert(const int newLimit) { @@ -146,9 +152,19 @@ void Settings::setNotificationHighText(const QString newText) { emit notificationHighTextChanged(notificationHighText); } -void Settings::setNotificationHealthText(const QString newText) { - if(saveString(sNotificationHealthText, newText, notificationHealthText)) - emit notificationHealthTextChanged(notificationHealthText); +void Settings::setNotificationHealthTitle(const QString newText) { + if(saveString(sNotificationHealthTitle, newText, notificationTitle)) + emit notificationHealthTitleChanged(notificationTitle); +} + +void Settings::setNotificationHealthWarnText(const QString newText) { + if(saveString(sNotificationHealthWarnText, newText, notificationHealthWarnText)) + emit notificationHealthWarnTextChanged(notificationHealthWarnText); +} + +void Settings::setNotificationHealthCritText(const QString newText) { + if(saveString(sNotificationHealthCritText, newText, notificationHealthCritText)) + emit notificationHealthCritTextChanged(notificationHealthCritText); } void Settings::setLogLevel(const int newLogLevel) { diff --git a/application/src/settings.h b/application/src/settings.h index 497ba44..b30fc7d 100644 --- a/application/src/settings.h +++ b/application/src/settings.h @@ -40,7 +40,9 @@ class Settings : public QObject Q_PROPERTY(QString notificationTitle READ getNotificationTitle WRITE setNotificationTitle NOTIFY notificationTitleChanged) Q_PROPERTY(QString notificationLowText READ getNotificationLowText WRITE setNotificationLowText NOTIFY notificationLowTextChanged) Q_PROPERTY(QString notificationHighText READ getNotificationHighText WRITE setNotificationHighText NOTIFY notificationHighTextChanged) - Q_PROPERTY(QString notificationHealthText READ getNotificationHealthText WRITE setNotificationHealthText NOTIFY notificationHealthTextChanged) + Q_PROPERTY(QString notificationHealthTitle READ getNotificationHealthTitle WRITE setNotificationHealthTitle NOTIFY notificationHealthTitleChanged) + Q_PROPERTY(QString notificationHealthWarnText READ getNotificationHealthWarnText WRITE setNotificationHealthWarnText NOTIFY notificationHealthWarnTextChanged) + Q_PROPERTY(QString notificationHealthCritText READ getNotificationHealthCritText WRITE setNotificationHealthCritText NOTIFY notificationHealthCritTextChanged) Q_PROPERTY(QString logFilename READ getLogFilename NOTIFY logFilenameChanged) Q_PROPERTY(int logLevel READ getLogLevel WRITE setLogLevel NOTIFY logLevelChanged) @@ -63,7 +65,9 @@ public: QString getNotificationTitle(); QString getNotificationLowText(); QString getNotificationHighText(); - QString getNotificationHealthText(); + QString getNotificationHealthTitle(); + QString getNotificationHealthWarnText(); + QString getNotificationHealthCritText(); QString getLogFilename(); int getLogLevel(); @@ -79,7 +83,9 @@ public: void setNotificationTitle(const QString newText); void setNotificationLowText(const QString newText); void setNotificationHighText(const QString newText); - void setNotificationHealthText(const QString newText); + void setNotificationHealthTitle(const QString newText); + void setNotificationHealthWarnText(const QString newText); + void setNotificationHealthCritText(const QString newText); void setLogLevel(const int newLogLevel); private: @@ -103,7 +109,9 @@ private: QString notificationTitle; QString notificationLowText; QString notificationHighText; - QString notificationHealthText; + QString notificationHealthTitle; + QString notificationHealthWarnText; + QString notificationHealthCritText; QString logFilename; int logLevel; @@ -123,7 +131,9 @@ private: const char* sNotificationTitle = "notificationTitle"; const char* sNotificationLowText = "notificationLowText"; const char* sNotificationHighText = "notificationHighText"; - const char* sNotificationHealthText = "notificationHealthText"; + const char* sNotificationHealthTitle = "notificationHealthTitle"; + const char* sNotificationHealthWarnText = "notificationHealthWarnText"; + const char* sNotificationHealthCritText = "notificationHealthCritText"; const char* sLogFilename = "logFilename"; const char* sLogLevel = "logLevel"; @@ -149,7 +159,9 @@ signals: void notificationTitleChanged(QString); void notificationLowTextChanged(QString); void notificationHighTextChanged(QString); - void notificationHealthTextChanged(QString); + void notificationHealthTitleChanged(QString); + void notificationHealthWarnTextChanged(QString); + void notificationHealthCritTextChanged(QString); void logFilenameChanged(QString); void logLevelChanged(int); }; diff --git a/application/translations/harbour-batterybuddy-de_DE.ts b/application/translations/harbour-batterybuddy-de_DE.ts index a0bf919..758b046 100644 --- a/application/translations/harbour-batterybuddy-de_DE.ts +++ b/application/translations/harbour-batterybuddy-de_DE.ts @@ -156,34 +156,34 @@ LogPage View log - + Logdatei ansehen Update - + Aktualisieren Copy - + Kopieren Log level - + Log Level Quiet Low log setting - + Still Verbose Medium log setting - + Mittel Debug High log setting - + Debug @@ -275,20 +275,43 @@ Current: Strom: + + Good + Battery is OK + die Batterie ist OK + + + Warm + Battery is warm + die Batterie ist warm + + + Overheated + Battery is very hot + die Batterie ist sehr heiss + + + Health: + Zustand: + + + Temperature: + Temperatur: + Settings Battery charge %1% - Akkustand %1% + Akkustand %1% Please connect the charger. - Bitte Ladegerät anschließen. + Bitte Ladegerät anschließen. Please disconnect the charger. - Bitte Ladegerät trennen. + Bitte Ladegerät trennen. @@ -364,7 +387,55 @@ View log - + Logdatei ansehen + + + Health Notification settings + Einstellungen zur Zustandbenachrichtigung + + + Display visual and audible notifications about battery health, when the battery temperature is below or above safe values. + Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald die Temperatur über gewissen Schwellwerten liegt. + + + Battery health notification + Zustandsbenachrichtigung + + + Warn on Health status: + Benachrichtigung bei Zustand: + + + None + Keine + + + Warning + Warnung + + + Critical + Kritisch + + + Battery health warning interval + Zustandsbenachrichtigungsintervall + + + Display visual and audible notifications about battery health, when the battery status exceeds safe values.<br />This usually means high temperature but can be affected by other factors depending on the hardware. + Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald gewisse Schwellwerte erreicht werden.<br />Das betrifft meist die Temperatur, kann aber je nach Hardware auch andere Faktoren beinhalten. + + + Health notification + Zustandsbenachrichtigung + + + Notify on Health status: + Benachrichtigung zum Zustand: + + + Health notification interval + Zustandsbenachrichtigungsintervall From 343f0b73c8f621411369d04aa90c0cd09003bc1d Mon Sep 17 00:00:00 2001 From: "Peter G. (nephros)" Date: Sun, 2 May 2021 21:14:29 +0200 Subject: [PATCH 08/18] Add health and temperature support to service Preparing and cleaning up for PR: reword, update German fix log output units printf debugging fix loading config imperial measurement in notification for some reason notification does not work on pre-Koli: /usr/bin/harbour-batterybuddy-daemon: symbol lookup error: /usr/bin/harbour-batterybuddy-daemon: undefined symbol: _ZN12Notification8setSoundERK7QString --- application/qml/pages/MainPage.qml | 2 + application/qml/pages/SettingsPage.qml | 2 +- .../harbour-batterybuddy-de_DE.ts | 16 ++- service/src/battery.cpp | 97 ++++++++++++++++++- service/src/battery.h | 15 +++ service/src/settings.cpp | 42 +++++--- service/src/settings.h | 19 ++++ 7 files changed, 177 insertions(+), 16 deletions(-) diff --git a/application/qml/pages/MainPage.qml b/application/qml/pages/MainPage.qml index abfc258..c260d8d 100644 --- a/application/qml/pages/MainPage.qml +++ b/application/qml/pages/MainPage.qml @@ -35,6 +35,8 @@ Page { "good": qsTr("Good", "Battery is OK"), "warm": qsTr("Warm", "Battery is warm"), "overheat": qsTr("Overheated", "Battery is very hot"), + "cool": qsTr("Cool", "Battery is cool"), + "cold": qsTr("Cold", "Battery is very cold"), } property bool serviceRunning: true diff --git a/application/qml/pages/SettingsPage.qml b/application/qml/pages/SettingsPage.qml index 7e71107..60525cc 100644 --- a/application/qml/pages/SettingsPage.qml +++ b/application/qml/pages/SettingsPage.qml @@ -374,7 +374,7 @@ Page { color: Theme.highlightColor } Label { - text: qsTr("Display visual and audible notifications about battery health, when the battery status exceeds safe values.
This usually means high temperature but can be affected by other factors depending on the hardware.") + text: qsTr("Display visual and audible notifications when the battery status exceeds safe values.
This usually means high (or low) temperature but can include other parameters depending on the hardware.") anchors { left: parent.left right: parent.right diff --git a/application/translations/harbour-batterybuddy-de_DE.ts b/application/translations/harbour-batterybuddy-de_DE.ts index 758b046..a3f8595 100644 --- a/application/translations/harbour-batterybuddy-de_DE.ts +++ b/application/translations/harbour-batterybuddy-de_DE.ts @@ -298,6 +298,16 @@ Temperature: Temperatur: + + Cool + Battery is cool + der Batterie ist kalt + + + Cold + Battery is very cold + der Batterie ist sehr kalt + Settings @@ -423,7 +433,7 @@ Display visual and audible notifications about battery health, when the battery status exceeds safe values.<br />This usually means high temperature but can be affected by other factors depending on the hardware. - Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald gewisse Schwellwerte erreicht werden.<br />Das betrifft meist die Temperatur, kann aber je nach Hardware auch andere Faktoren beinhalten. + Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald gewisse Schwellwerte erreicht werden.<br />Das betrifft meist die Temperatur, kann aber je nach Hardware auch andere Faktoren beinhalten. Health notification @@ -437,5 +447,9 @@ Health notification interval Zustandsbenachrichtigungsintervall + + Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. + Visuelle und akustische Benachrichtigungen anzeigen, wenn gewissen Schwellwerte erreicht werden. Meistens gilt das fuer die Temperatur, aber je nach Hardware koennen auch andere Faktoren zu einer Meldung fuehren. + diff --git a/service/src/battery.cpp b/service/src/battery.cpp index 5078293..1d9cad9 100644 --- a/service/src/battery.cpp +++ b/service/src/battery.cpp @@ -33,6 +33,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject updateTimer = new QTimer(this); highNotifyTimer = new QTimer(this); lowNotifyTimer = new QTimer(this); + healthNotifyTimer = new QTimer(this); notification = new MyNotification(this); // Number: charge percentage, e.g. 42 @@ -47,6 +48,14 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject chargerConnectedFile = new QFile("/sys/class/power_supply/usb/present", this); logE("Charger status file: " + chargerConnectedFile->fileName()); + // Number: temperature + temperatureFile = new QFile("/sys/class/power_supply/battery/temp", this); + logE("Temperature file: " + temperatureFile->fileName()); + + // String: Good, Warm, Overheat, (others?) + healthFile = new QFile("/sys/class/power_supply/battery/health", this); + logE("Health state file: " + healthFile->fileName()); + // ENABLE/DISABLE CHARGING QString filename; @@ -97,6 +106,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject connect(settings, SIGNAL(resetTimers()), this, SLOT(resetTimers())); connect(highNotifyTimer, SIGNAL(timeout()), this, SLOT(showHighNotification())); connect(lowNotifyTimer, SIGNAL(timeout()), this, SLOT(showLowNotification())); + connect(healthNotifyTimer, SIGNAL(timeout()), this, SLOT(showHealthNotification())); updateData(); updateTimer->start(5000); @@ -105,7 +115,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject // aka. "charging" status didn't change // (or if both times are disabled, actually) // manually trigger the timer startup. - if(!highNotifyTimer->isActive() && !lowNotifyTimer->isActive()) { + if(!highNotifyTimer->isActive() && !lowNotifyTimer->isActive() && !healthNotifyTimer->isActive()) { resetTimers(); } } @@ -145,6 +155,28 @@ void Battery::updateData() stateFile->close(); } + if(temperatureFile->open(QIODevice::ReadOnly)) { + nextTemperature = temperatureFile->readLine().trimmed().toInt(); + if(nextTemperature != temperature) { + temperature = nextTemperature; + emit temperatureChanged(temperature); + logV(QString("Temperature: %1°C").arg(temperature / 10)); + } + temperatureFile->close(); + } + if(healthFile->open(QIODevice::ReadOnly)) { + nextHealth = (QString(healthFile->readLine().trimmed().toLower())); + if(nextHealth != health) { + health = nextHealth; + emit healthChanged(health); + logV("Health: " + health); + + // Hide/show notification right away + resetTimers(); + } + healthFile->close(); + } + if(chargingEnabledFile && settings->getLimitEnabled()) { if(chargingEnabled && charge >= settings->getHighLimit()) { logD("Disabling charging..."); @@ -160,8 +192,10 @@ void Battery::updateData() void Battery::resetTimers() { highNotifyTimer->stop(); lowNotifyTimer->stop(); + healthNotifyTimer->stop(); highNotifyTimer->setInterval(settings->getHighNotificationsInterval() * 1000); lowNotifyTimer->setInterval(settings->getLowNotificationsInterval() * 1000); + healthNotifyTimer->setInterval(settings->getHealthNotificationsInterval() * 1000); if(settings->getHighNotificationsInterval() < 610) { logD("Starting high battery timer"); @@ -180,6 +214,15 @@ void Battery::resetTimers() { else { logD("Low battery timer not started"); } + + if(settings->getHealthNotificationsInterval() < 610) { + logD("Start health timer"); + healthNotifyTimer->start(); + showHealthNotification(); + } + else { + logD("Health timer not started"); + } } void Battery::showHighNotification() { @@ -213,10 +256,58 @@ void Battery::showLowNotification() { } } +void Battery::showHealthNotification() { + // set up alert categories + // TODO: manage this more globally, use better data types(?), align with QML/Settings part + static const QMap HealthThresh { + { "ok" , 0}, + { "warn" , 1}, + { "crit" , 2}, + }; + // map string values from sysfs file to alert category + static const QMap HealthState { + { "good" , HealthThresh["ok"] }, + { "warm" , HealthThresh["warn"] }, + { "cool" , HealthThresh["warn"] }, + { "overheat" , HealthThresh["crit"] }, + { "cold" , HealthThresh["crit"] } + }; + if(settings->getHealthNotificationsInterval() < 610 && ( HealthState[health] != HealthThresh["ok"] && HealthState[health] >= settings->getHealthAlert() ) ) { + QString displayTemp = QString::number(temperature / 10.0); + if (QLocale().measurementSystem() == QLocale::ImperialUSSystem) + displayTemp = QString::number((temperature / 10) * 1.8 + 32) + " F"; + + QString titleArgs; + titleArgs = health + " (" + displayTemp + "), " + state; // might show other things in the future + + // show different test depending on severity + QString notificationText = ""; + if (HealthState[health] == HealthThresh["warn"]) { + notificationText = settings->getNotificationHealthWarnText(); + } else if (HealthState[health] == HealthThresh["crit"]) { + notificationText = settings->getNotificationHealthCritText(); + } + logD(QString("Notification: %1").arg(settings->getNotificationHealthTitle().arg(titleArgs))); + notification->send(settings->getNotificationHealthTitle().arg(titleArgs), notificationText, settings->getHealthAlertFile()); + if(settings->getHealthNotificationsInterval() == 50) { + logD("Stop health timer"); + healthNotifyTimer->stop(); + } + } + else if(HealthState[health] == HealthThresh["ok"] || HealthState[health] < settings->getHealthAlert()) { + logD("Close health notification"); + notification->close(); + } +} + int Battery::getCharge() { return charge; } QString Battery::getState() { return state; } +int Battery::getTemperature() { return temperature; } + +QString Battery::getHealth() { return health; } + bool Battery::getChargingEnabled() { return chargingEnabled; } bool Battery::setChargingEnabled(const bool isEnabled) { @@ -267,6 +358,10 @@ void Battery::shutdown() { lowNotifyTimer->stop(); logD("Low battery notification stopped"); } + if(healthNotifyTimer) { + healthNotifyTimer->stop(); + logD("Health notification stopped"); + } // ENABLE/DISABLE CHARGING if(!setChargingEnabled(true) && !QHostInfo::localHostName().contains("SailfishEmul")) { logE("ERROR! Could not restore charger status! Your device " diff --git a/service/src/battery.h b/service/src/battery.h index 33533c7..a47b94b 100644 --- a/service/src/battery.h +++ b/service/src/battery.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "settings.h" #include "mynotification.h" #include "logger.h" @@ -44,6 +45,9 @@ public: bool getChargingEnabled(); bool setChargingEnabled(const bool isEnabled); + int getTemperature(); + QString getHealth(); + public slots: void updateData(); void shutdown(); @@ -54,17 +58,23 @@ private: QFile *chargerConnectedFile = nullptr; QFile *stateFile = nullptr; QFile *chargingEnabledFile = nullptr; + QFile *temperatureFile = nullptr; + QFile *healthFile = nullptr; Settings *settings = nullptr; QTimer *updateTimer = nullptr; QTimer *highNotifyTimer = nullptr; QTimer *lowNotifyTimer = nullptr; + QTimer *healthNotifyTimer = nullptr; MyNotification *notification = nullptr; + // Default values: int charge = 100; // 100% full bool chargerConnected = false; // Charger plugged in QString state = "idle"; // dis/charging, idle, unknown bool chargingEnabled = true; // Only ever disabled manually + int temperature = 0; // freezing + QString health = "Good"; // good, warm, overheat, possibly more int enableChargingValue = 1; int disableChargingValue = 0; @@ -74,6 +84,8 @@ private: bool nextChargerConnected = chargerConnected; QString nextState = state; bool nextChargingEnabled = chargingEnabled; + int nextTemperature = temperature; + QString nextHealth = health; QFileDevice::Permissions originalPerms; // Updated in constructor QFileDevice::Permissions customPerms = static_cast(0x0666); @@ -83,11 +95,14 @@ signals: void stateChanged(QString); void chargingEnabledChanged(bool); void chargerConnectedChanged(bool); + void temperatureChanged(int); + void healthChanged(QString); public slots: void resetTimers(); void showHighNotification(); void showLowNotification(); + void showHealthNotification(); }; #endif // BATTERY_H diff --git a/service/src/settings.cpp b/service/src/settings.cpp index 6f6d990..ac206c0 100644 --- a/service/src/settings.cpp +++ b/service/src/settings.cpp @@ -92,6 +92,9 @@ Settings::Settings(Logger* newLogger, QObject *parent) : QObject(parent) notificationTitle = "Battery charge %1%"; notificationLowText = "Please connect the charger."; notificationHighText = "Please disconnect the charger."; + notificationHealthTitle = "Battery health %1"; + notificationHealthWarnText = "Battery health is not good"; + notificationHealthCritText = "Battery health is critical"; // Do this here, because... watcher = new QFileSystemWatcher(QStringList(mySettings->fileName()), this); @@ -129,8 +132,10 @@ void Settings::updateConfig(const QString path) { loadInteger(sLowAlert, lowAlert, 5, 99); loadInteger(sHighAlert, highAlert, 6, 100); + loadInteger(sHealthAlert, healthAlert, 0, 2); restartTimers |= loadInteger(sHighNotificationsInterval, highNotificationsInterval, 50, 610); restartTimers |= loadInteger(sLowNotificationsInterval, lowNotificationsInterval, 50, 610); + restartTimers |= loadInteger(sHealthNotificationsInterval, healthNotificationsInterval, 50, 610); loadInteger(sLimitEnabled, limitEnabled, 0, 1); loadInteger(sLowLimit, lowLimit, 5, 99); loadInteger(sHighLimit, highLimit, 6, 100); @@ -139,6 +144,11 @@ void Settings::updateConfig(const QString path) { notificationLowText = mySettings->value(sNotificationLowText, notificationLowText).toString(); notificationHighText = mySettings->value(sNotificationHighText, notificationHighText).toString(); + notificationHealthTitle = mySettings->value(sNotificationHealthTitle, notificationHealthTitle).toString(); + notificationHealthWarnText = mySettings->value(sNotificationHealthWarnText, notificationHealthWarnText).toString(); + notificationHealthCritText = mySettings->value(sNotificationHealthCritText, notificationHealthCritText).toString(); + + // Update log level int oldLogLevel = logLevel; loadInteger(sLogLevel, logLevel, 0, 2); @@ -168,16 +178,22 @@ void Settings::updateConfig(const QString path) { } // Getters condensed -int Settings::getLowAlert() { return lowAlert; } -int Settings::getHighAlert() { return highAlert; } -int Settings::getHighNotificationsInterval() { return highNotificationsInterval; } -int Settings::getLowNotificationsInterval() { return lowNotificationsInterval; } -int Settings::getLowLimit() { return lowLimit; } -int Settings::getHighLimit() { return highLimit; } -bool Settings::getLimitEnabled() { return limitEnabled == 1; } -QString Settings::getLowAlertFile() { return lowAlertFile; } -QString Settings::getHighAlertFile() { return highAlertFile; } -QString Settings::getNotificationTitle() { return notificationTitle; } -QString Settings::getNotificationLowText() { return notificationLowText; } -QString Settings::getNotificationHighText() { return notificationHighText; } -int Settings::getLogLevel() { return logLevel; } +int Settings::getLowAlert() { return lowAlert; } +int Settings::getHighAlert() { return highAlert; } +int Settings::getHealthAlert() { return healthAlert; } +int Settings::getHighNotificationsInterval() { return highNotificationsInterval; } +int Settings::getLowNotificationsInterval() { return lowNotificationsInterval; } +int Settings::getHealthNotificationsInterval() { return healthNotificationsInterval; } +int Settings::getLowLimit() { return lowLimit; } +int Settings::getHighLimit() { return highLimit; } +bool Settings::getLimitEnabled() { return limitEnabled == 1; } +QString Settings::getLowAlertFile() { return lowAlertFile; } +QString Settings::getHighAlertFile() { return highAlertFile; } +QString Settings::getHealthAlertFile() { return healthAlertFile; } +QString Settings::getNotificationTitle() { return notificationTitle; } +QString Settings::getNotificationLowText() { return notificationLowText; } +QString Settings::getNotificationHighText() { return notificationHighText; } +QString Settings::getNotificationHealthTitle() { return notificationHealthTitle; } +QString Settings::getNotificationHealthWarnText() { return notificationHealthWarnText; } +QString Settings::getNotificationHealthCritText() { return notificationHealthCritText; } +int Settings::getLogLevel() { return logLevel; } diff --git a/service/src/settings.h b/service/src/settings.h index a7e4320..55c39f3 100644 --- a/service/src/settings.h +++ b/service/src/settings.h @@ -36,17 +36,24 @@ public: int getHighAlert(); int getHighNotificationsInterval(); int getLowNotificationsInterval(); + int getHealthAlert(); + int getHealthNotificationsInterval(); int getLowLimit(); int getHighLimit(); int getLogLevel(); bool getLimitEnabled(); bool getHighNotificationsEnabled(); bool getLowNotificationsEnabled(); + bool getHealthNotificationsEnabled(); QString getLowAlertFile(); QString getHighAlertFile(); + QString getHealthAlertFile(); QString getNotificationTitle(); QString getNotificationLowText(); QString getNotificationHighText(); + QString getNotificationHealthTitle(); + QString getNotificationHealthWarnText(); + QString getNotificationHealthCritText(); private: Logger* logger; @@ -63,8 +70,10 @@ private: // Default values int lowAlert = 25; int highAlert = 75; + int healthAlert = 1; // 0=off, 1=warn, 2=crit int highNotificationsInterval = 60; int lowNotificationsInterval = 60; + int healthNotificationsInterval = 60; // Converted to boolean for QML int limitEnabled = 1; @@ -74,23 +83,33 @@ private: int highLimit = 70; QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav"; QString highAlertFile = "/usr/share/sounds/jolla-ambient/stereo/positive_confirmation.wav"; + QString healthAlertFile = "/usr/share/sounds/jolla-ambient/stereo/battery_low.wav"; QString notificationTitle; QString notificationLowText; QString notificationHighText; + QString notificationHealthTitle; + QString notificationHealthWarnText; + QString notificationHealthCritText; // To avoid repeating the same string over and over and over... const char* sLowAlert = "lowAlert"; const char* sHighAlert = "highAlert"; + const char* sHealthAlert = "healthAlert"; const char* sHighNotificationsInterval = "highNotificationsInterval"; const char* sLowNotificationsInterval = "lowNotificationsInterval"; + const char* sHealthNotificationsInterval = "healthNotificationsInterval"; const char* sLimitEnabled = "limitEnabled"; const char* sLowLimit = "lowLimit"; const char* sHighLimit = "highLimit"; const char* sLowAlertFile = "lowAlertFile"; const char* sHighAlertFile = "highAlertFile"; + const char* sHealthAlertFile = "healthAlertFile"; const char* sNotificationTitle = "notificationTitle"; const char* sNotificationLowText = "notificationLowText"; const char* sNotificationHighText = "notificationHighText"; + const char* sNotificationHealthTitle = "notificationHealthTitle"; + const char* sNotificationHealthWarnText = "notificationHealthWarnText"; + const char* sNotificationHealthCritText = "notificationHealthCritText"; const char* sLogFilename = "logFilename"; const char* sLogLevel = "logLevel"; From 5c5aa961e78693d39ca2fdec2bd5ca190f59f095 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sat, 22 May 2021 22:58:05 +0300 Subject: [PATCH 09/18] Default to unknown state --- application/qml/pages/MainPage.qml | 1 + application/src/battery.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/application/qml/pages/MainPage.qml b/application/qml/pages/MainPage.qml index c260d8d..54121c6 100644 --- a/application/qml/pages/MainPage.qml +++ b/application/qml/pages/MainPage.qml @@ -37,6 +37,7 @@ Page { "overheat": qsTr("Overheated", "Battery is very hot"), "cool": qsTr("Cool", "Battery is cool"), "cold": qsTr("Cold", "Battery is very cold"), + "unknown": qsTr("unknown", "Battery not detected, or faulty, or something") } property bool serviceRunning: true diff --git a/application/src/battery.h b/application/src/battery.h index 2e05717..d634ea5 100644 --- a/application/src/battery.h +++ b/application/src/battery.h @@ -77,7 +77,7 @@ private: bool chargingEnabled = true; // Only ever disabled manually - QString health = "Good"; // Good, Warm, Overheat. Might have Cold or Overvoltage depending on driver + QString health = "unknown"; // Good, warm, overheat. Might have Cold or Overvoltage depending on driver int temperature = 0; // freezing int enableChargingValue = 1; From e939c2d9cee46e6c11b6d7e61c0ff6119a5438f0 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sat, 22 May 2021 23:00:48 +0300 Subject: [PATCH 10/18] Use uint_max as "unknown" placeholder --- application/src/battery.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/battery.h b/application/src/battery.h index d634ea5..82fd6c0 100644 --- a/application/src/battery.h +++ b/application/src/battery.h @@ -78,7 +78,7 @@ private: QString health = "unknown"; // Good, warm, overheat. Might have Cold or Overvoltage depending on driver - int temperature = 0; // freezing + int temperature = 0x7FFFFFFF; // This value means "unknown" (32-bit INT_MAX) int enableChargingValue = 1; int disableChargingValue = 0; From 843cfa8db75e27aadfa7f23237f5f1b365f5cc35 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sat, 22 May 2021 23:02:25 +0300 Subject: [PATCH 11/18] Make temperature formatting prettier --- application/qml/pages/MainPage.qml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/application/qml/pages/MainPage.qml b/application/qml/pages/MainPage.qml index 54121c6..0f6c833 100644 --- a/application/qml/pages/MainPage.qml +++ b/application/qml/pages/MainPage.qml @@ -180,7 +180,14 @@ Page { } MyDetailItem { label: qsTr("Temperature:") - value: (Qt.locale().measurementSystem == Locale.ImperialUSSystem) ? Math.floor((battery.temperature / 10) * 1.8 + 32) + " F" : Math.floor(battery.temperature / 10) + " °C" + value: battery.temperature === 0x7FFFFFFF ? healthText["unknown"] : formatTemperature(battery.temperature) + + function formatTemperature(temp) { + if(Qt.locale().measurementSystem === Locale.ImperialUSSystem) { + return Math.floor((battery.temperature / 10) * 1.8 + 32) + " °F" + } + return Math.floor(battery.temperature / 10) + " °C" + } } } } From d3f1297afdf99cb57c9d4b31b9102db926cc7471 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sat, 22 May 2021 23:42:57 +0300 Subject: [PATCH 12/18] Use the unknown values in service, too --- service/src/battery.cpp | 3 ++- service/src/battery.h | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/service/src/battery.cpp b/service/src/battery.cpp index 1d9cad9..777b97f 100644 --- a/service/src/battery.cpp +++ b/service/src/battery.cpp @@ -266,13 +266,14 @@ void Battery::showHealthNotification() { }; // map string values from sysfs file to alert category static const QMap HealthState { + { "unknown" , HealthThresh["ok"] }, { "good" , HealthThresh["ok"] }, { "warm" , HealthThresh["warn"] }, { "cool" , HealthThresh["warn"] }, { "overheat" , HealthThresh["crit"] }, { "cold" , HealthThresh["crit"] } }; - if(settings->getHealthNotificationsInterval() < 610 && ( HealthState[health] != HealthThresh["ok"] && HealthState[health] >= settings->getHealthAlert() ) ) { + if(settings->getHealthNotificationsInterval() < 610 && temperature != 0x7FFFFFFF && ( HealthState[health] != HealthThresh["ok"] && HealthState[health] >= settings->getHealthAlert() ) ) { QString displayTemp = QString::number(temperature / 10.0); if (QLocale().measurementSystem() == QLocale::ImperialUSSystem) displayTemp = QString::number((temperature / 10) * 1.8 + 32) + " F"; diff --git a/service/src/battery.h b/service/src/battery.h index a47b94b..eff3c61 100644 --- a/service/src/battery.h +++ b/service/src/battery.h @@ -73,8 +73,9 @@ private: bool chargerConnected = false; // Charger plugged in QString state = "idle"; // dis/charging, idle, unknown bool chargingEnabled = true; // Only ever disabled manually - int temperature = 0; // freezing - QString health = "Good"; // good, warm, overheat, possibly more + + QString health = "unknown"; // Good, warm, overheat. Might have Cold or Overvoltage depending on driver + int temperature = 0x7FFFFFFF; // This value means "unknown" (32-bit INT_MAX) int enableChargingValue = 1; int disableChargingValue = 0; From 40363f1285a3505b9e0ee550825bd80151f3a3bb Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 23 May 2021 00:03:19 +0300 Subject: [PATCH 13/18] Adjust translations --- application/qml/pages/SettingsPage.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/qml/pages/SettingsPage.qml b/application/qml/pages/SettingsPage.qml index 60525cc..a47fd00 100644 --- a/application/qml/pages/SettingsPage.qml +++ b/application/qml/pages/SettingsPage.qml @@ -370,7 +370,7 @@ Page { Label { x: Theme.paddingLarge - text: qsTr("Health Notification settings") + text: qsTr("Health notification settings") color: Theme.highlightColor } Label { @@ -386,12 +386,12 @@ Page { wrapMode: Text.Wrap } - SectionHeader { text: qsTr("Health notification") } + SectionHeader { text: qsTr("Battery health notification") } ComboBox { id: healthSelector width: parent.width - label: qsTr("Notify on Health status" + ":") + label: qsTr("Notification treshold") currentIndex: settings.healthAlert menu: ContextMenu { MenuItem { text: qsTr("Never") } From da7499641a7d2258147ae942a797eca3efb268a2 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 23 May 2021 00:04:41 +0300 Subject: [PATCH 14/18] Update translations, complete Finnish translation --- .../harbour-batterybuddy-de_DE.ts | 56 ++++++-------- .../translations/harbour-batterybuddy-fi.ts | 73 +++++++++++++++++++ .../translations/harbour-batterybuddy-fr.ts | 73 +++++++++++++++++++ .../translations/harbour-batterybuddy-hu.ts | 73 +++++++++++++++++++ .../translations/harbour-batterybuddy-pl.ts | 73 +++++++++++++++++++ .../translations/harbour-batterybuddy-sv.ts | 73 +++++++++++++++++++ .../harbour-batterybuddy-zh_CN.ts | 73 +++++++++++++++++++ .../translations/harbour-batterybuddy.ts | 73 +++++++++++++++++++ 8 files changed, 535 insertions(+), 32 deletions(-) diff --git a/application/translations/harbour-batterybuddy-de_DE.ts b/application/translations/harbour-batterybuddy-de_DE.ts index 0e79355..df7968d 100644 --- a/application/translations/harbour-batterybuddy-de_DE.ts +++ b/application/translations/harbour-batterybuddy-de_DE.ts @@ -313,15 +313,27 @@ Settings Battery charge %1% - Akkustand %1% + Akkustand %1% Please connect the charger. - Bitte Ladegerät anschließen. + Bitte Ladegerät anschließen. Please disconnect the charger. - Bitte Ladegerät trennen. + Bitte Ladegerät trennen. + + + Battery health %1 + + + + Battery health is not good + + + + Battery health is critical + @@ -399,25 +411,9 @@ View log Logdatei ansehen - - Health Notification settings - Einstellungen zur Zustandbenachrichtigung - - - Display visual and audible notifications about battery health, when the battery temperature is below or above safe values. - Visuelle und akustische Benachrichtigungen zum Batteriezustand anzeigen, sobald die Temperatur über gewissen Schwellwerten liegt. - Battery health notification - Zustandsbenachrichtigung - - - Warn on Health status: - Benachrichtigung bei Zustand: - - - None - Keine + Zustandsbenachrichtigung Warning @@ -427,18 +423,6 @@ Critical Kritisch - - Battery health warning interval - Zustandsbenachrichtigungsintervall - - - Health notification - Zustandsbenachrichtigung - - - Notify on Health status: - Benachrichtigung zum Zustand: - Health notification interval Zustandsbenachrichtigungsintervall @@ -447,5 +431,13 @@ Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. Visuelle und akustische Benachrichtigungen anzeigen, wenn gewissen Schwellwerte erreicht werden. Meistens gilt das fuer die Temperatur, aber je nach Hardware koennen auch andere Faktoren zu einer Meldung fuehren. + + Health notification settings + + + + Notification treshold + + diff --git a/application/translations/harbour-batterybuddy-fi.ts b/application/translations/harbour-batterybuddy-fi.ts index 2a36e3a..07e609c 100644 --- a/application/translations/harbour-batterybuddy-fi.ts +++ b/application/translations/harbour-batterybuddy-fi.ts @@ -273,6 +273,39 @@ Current: Virta: + + Good + Battery is OK + Hyvä + + + Warm + Battery is warm + Lämmin + + + Overheated + Battery is very hot + Ylikuumentunut + + + Cool + Battery is cool + Viileä + + + Cold + Battery is very cold + Kylmä + + + Health: + Kunto: + + + Temperature: + Lämpötila: + Settings @@ -288,6 +321,18 @@ Please disconnect the charger. Ole hyvä ja irrota laturi. + + Battery health %1 + Akun kunto: %1 + + + Battery health is not good + Akun tila ei ole normaali + + + Battery health is critical + Akun tila on kriittinen + SettingsPage @@ -364,5 +409,33 @@ View log Näytä loki + + Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. + Näytä ilmoitukset ja toista hälytysääni, kun akun kunto ylittää normaalit rahat.<br />Yleensä tämä tarkoittaa liian korkeaa (tai matalaa) lämpötilaa, mutta syitä voi olla muitakin, laitteistosta riippuen. + + + Warning + Varoitue + + + Critical + Kriittinen + + + Health notification interval + Akun kuntoilmoitusten aikaväli + + + Battery health notification + Akun kunnon ilmoitukset + + + Health notification settings + Akun tilan ilmoitusten aikaväli + + + Notification treshold + Ilmoitusten taso + diff --git a/application/translations/harbour-batterybuddy-fr.ts b/application/translations/harbour-batterybuddy-fr.ts index 57bf644..d1056c1 100644 --- a/application/translations/harbour-batterybuddy-fr.ts +++ b/application/translations/harbour-batterybuddy-fr.ts @@ -273,6 +273,39 @@ Current: Courant: + + Good + Battery is OK + + + + Warm + Battery is warm + + + + Overheated + Battery is very hot + + + + Cool + Battery is cool + + + + Cold + Battery is very cold + + + + Health: + + + + Temperature: + + Settings @@ -288,6 +321,18 @@ Please disconnect the charger. Merci de débrancher le chargeur. + + Battery health %1 + + + + Battery health is not good + + + + Battery health is critical + + SettingsPage @@ -364,5 +409,33 @@ View log + + Health notification settings + + + + Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. + + + + Battery health notification + + + + Notification treshold + + + + Warning + + + + Critical + + + + Health notification interval + + diff --git a/application/translations/harbour-batterybuddy-hu.ts b/application/translations/harbour-batterybuddy-hu.ts index 037d5d8..386decc 100644 --- a/application/translations/harbour-batterybuddy-hu.ts +++ b/application/translations/harbour-batterybuddy-hu.ts @@ -273,6 +273,39 @@ Current: Jelenleg: + + Good + Battery is OK + + + + Warm + Battery is warm + + + + Overheated + Battery is very hot + + + + Cool + Battery is cool + + + + Cold + Battery is very cold + + + + Health: + + + + Temperature: + + Settings @@ -288,6 +321,18 @@ Please disconnect the charger. Kérlek húzd ki a töltőt. + + Battery health %1 + + + + Battery health is not good + + + + Battery health is critical + + SettingsPage @@ -364,5 +409,33 @@ View log Napló megtekintése + + Health notification settings + + + + Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. + + + + Battery health notification + + + + Notification treshold + + + + Warning + + + + Critical + + + + Health notification interval + + diff --git a/application/translations/harbour-batterybuddy-pl.ts b/application/translations/harbour-batterybuddy-pl.ts index 78b9273..6e0af67 100644 --- a/application/translations/harbour-batterybuddy-pl.ts +++ b/application/translations/harbour-batterybuddy-pl.ts @@ -273,6 +273,39 @@ Current: Prąd: + + Good + Battery is OK + + + + Warm + Battery is warm + + + + Overheated + Battery is very hot + + + + Cool + Battery is cool + + + + Cold + Battery is very cold + + + + Health: + + + + Temperature: + + Settings @@ -288,6 +321,18 @@ Please disconnect the charger. Odłącz ładowarkę. + + Battery health %1 + + + + Battery health is not good + + + + Battery health is critical + + SettingsPage @@ -364,5 +409,33 @@ View log Pokaż logi + + Health notification settings + + + + Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. + + + + Battery health notification + + + + Notification treshold + + + + Warning + + + + Critical + + + + Health notification interval + + diff --git a/application/translations/harbour-batterybuddy-sv.ts b/application/translations/harbour-batterybuddy-sv.ts index eefd74b..78c0024 100644 --- a/application/translations/harbour-batterybuddy-sv.ts +++ b/application/translations/harbour-batterybuddy-sv.ts @@ -273,6 +273,39 @@ Current: Ström: + + Good + Battery is OK + + + + Warm + Battery is warm + + + + Overheated + Battery is very hot + + + + Cool + Battery is cool + + + + Cold + Battery is very cold + + + + Health: + + + + Temperature: + + Settings @@ -288,6 +321,18 @@ Please disconnect the charger. Koppla ifrån laddaren. + + Battery health %1 + + + + Battery health is not good + + + + Battery health is critical + + SettingsPage @@ -364,5 +409,33 @@ View log Visa logg + + Health notification settings + + + + Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. + + + + Battery health notification + + + + Notification treshold + + + + Warning + + + + Critical + + + + Health notification interval + + diff --git a/application/translations/harbour-batterybuddy-zh_CN.ts b/application/translations/harbour-batterybuddy-zh_CN.ts index 40e5856..1e42a0e 100644 --- a/application/translations/harbour-batterybuddy-zh_CN.ts +++ b/application/translations/harbour-batterybuddy-zh_CN.ts @@ -275,6 +275,39 @@ Current: 当前状态: + + Good + Battery is OK + + + + Warm + Battery is warm + + + + Overheated + Battery is very hot + + + + Cool + Battery is cool + + + + Cold + Battery is very cold + + + + Health: + + + + Temperature: + + Settings @@ -290,6 +323,18 @@ Please disconnect the charger. 请断开充电器 + + Battery health %1 + + + + Battery health is not good + + + + Battery health is critical + + SettingsPage @@ -366,5 +411,33 @@ View log 查看日志 + + Health notification settings + + + + Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. + + + + Battery health notification + + + + Notification treshold + + + + Warning + + + + Critical + + + + Health notification interval + + diff --git a/application/translations/harbour-batterybuddy.ts b/application/translations/harbour-batterybuddy.ts index e39464c..11aa9f6 100644 --- a/application/translations/harbour-batterybuddy.ts +++ b/application/translations/harbour-batterybuddy.ts @@ -273,6 +273,39 @@ Current: + + Good + Battery is OK + + + + Warm + Battery is warm + + + + Overheated + Battery is very hot + + + + Cool + Battery is cool + + + + Cold + Battery is very cold + + + + Health: + + + + Temperature: + + Settings @@ -288,6 +321,18 @@ Please disconnect the charger. + + Battery health %1 + + + + Battery health is not good + + + + Battery health is critical + + SettingsPage @@ -364,5 +409,33 @@ View log + + Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware. + + + + Warning + + + + Critical + + + + Health notification interval + + + + Battery health notification + + + + Health notification settings + + + + Notification treshold + + From 645d919457a04d962785eb1aac712584e20b881f Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 23 May 2021 01:15:40 +0300 Subject: [PATCH 15/18] Use separate notification for health/status --- service/src/battery.cpp | 17 +++++++++-------- service/src/battery.h | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/service/src/battery.cpp b/service/src/battery.cpp index 777b97f..97695ef 100644 --- a/service/src/battery.cpp +++ b/service/src/battery.cpp @@ -34,7 +34,8 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject highNotifyTimer = new QTimer(this); lowNotifyTimer = new QTimer(this); healthNotifyTimer = new QTimer(this); - notification = new MyNotification(this); + chargeNotification = new MyNotification(this); + healthNotification = new MyNotification(this); // Number: charge percentage, e.g. 42 chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this); @@ -229,7 +230,7 @@ void Battery::showHighNotification() { if(settings->getHighNotificationsInterval() < 610 && (charge >= settings->getHighAlert() && state != "discharging") && !(charge == 100 && state == "idle")) { logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge))); - notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile()); + chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile()); if(settings->getHighNotificationsInterval() == 50) { logD("Stop high battery timer"); highNotifyTimer->stop(); @@ -237,14 +238,14 @@ void Battery::showHighNotification() { } else if(charge > settings->getLowAlert()) { logD("Close high battery notification"); - notification->close(); + chargeNotification->close(); } } void Battery::showLowNotification() { if(settings->getLowNotificationsInterval() < 610 && charge <= settings->getLowAlert() && state != "charging") { logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge))); - notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile()); + chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile()); if(settings->getLowNotificationsInterval() == 50) { logD("Stop low battery timer"); lowNotifyTimer->stop(); @@ -252,7 +253,7 @@ void Battery::showLowNotification() { } else if(charge < settings->getHighAlert()) { logD("Close low battery notification"); - notification->close(); + chargeNotification->close(); } } @@ -289,7 +290,7 @@ void Battery::showHealthNotification() { notificationText = settings->getNotificationHealthCritText(); } logD(QString("Notification: %1").arg(settings->getNotificationHealthTitle().arg(titleArgs))); - notification->send(settings->getNotificationHealthTitle().arg(titleArgs), notificationText, settings->getHealthAlertFile()); + healthNotification->send(settings->getNotificationHealthTitle().arg(titleArgs), notificationText, settings->getHealthAlertFile()); if(settings->getHealthNotificationsInterval() == 50) { logD("Stop health timer"); healthNotifyTimer->stop(); @@ -297,7 +298,7 @@ void Battery::showHealthNotification() { } else if(HealthState[health] == HealthThresh["ok"] || HealthState[health] < settings->getHealthAlert()) { logD("Close health notification"); - notification->close(); + healthNotification->close(); } } @@ -345,7 +346,7 @@ bool Battery::getChargerConnected() { void Battery::shutdown() { logV("Shutting down..."); - notification->close(); + chargeNotification->close(); blockSignals(true); if(updateTimer) { updateTimer->stop(); diff --git a/service/src/battery.h b/service/src/battery.h index eff3c61..cb45d2f 100644 --- a/service/src/battery.h +++ b/service/src/battery.h @@ -65,7 +65,8 @@ private: QTimer *highNotifyTimer = nullptr; QTimer *lowNotifyTimer = nullptr; QTimer *healthNotifyTimer = nullptr; - MyNotification *notification = nullptr; + MyNotification *chargeNotification = nullptr; + MyNotification *healthNotification = nullptr; // Default values: From c6f9000aa9d451b700f9515161c5972b26ac08a1 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 23 May 2021 14:25:24 +0300 Subject: [PATCH 16/18] Hide unavailable health/temp data --- application/qml/pages/MainPage.qml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/qml/pages/MainPage.qml b/application/qml/pages/MainPage.qml index 0f6c833..deff4be 100644 --- a/application/qml/pages/MainPage.qml +++ b/application/qml/pages/MainPage.qml @@ -177,10 +177,12 @@ Page { MyDetailItem { label: qsTr("Health:") value: healthText[battery.health] + visible: value !== "unknown" } MyDetailItem { label: qsTr("Temperature:") value: battery.temperature === 0x7FFFFFFF ? healthText["unknown"] : formatTemperature(battery.temperature) + visible: battery.temperature !== 0x7FFFFFFF function formatTemperature(temp) { if(Qt.locale().measurementSystem === Locale.ImperialUSSystem) { From f0dd0e501897eb5a447d3a464f483b7162ce6ba0 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 23 May 2021 14:26:42 +0300 Subject: [PATCH 17/18] Better handle non-existent files --- application/src/battery.cpp | 16 ++++++++++------ service/src/battery.cpp | 34 ++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/application/src/battery.cpp b/application/src/battery.cpp index 8ae2ee0..3afd098 100644 --- a/application/src/battery.cpp +++ b/application/src/battery.cpp @@ -38,15 +38,19 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO chargerConnectedFile = new QFile("/sys/class/power_supply/usb/present", this); logE("Reading charger status from" + chargerConnectedFile->fileName()); + QString filename; + // Number: temperature - temperatureFile = new QFile("/sys/class/power_supply/battery/temp", this); - logE("Temperature file: " + temperatureFile->fileName()); + filename = "/sys/class/power_supply/battery/temp"; + if(!temperatureFile && QFile::exists(filename)) { + temperatureFile = new QFile(filename, this); + } // String: health state - healthFile = new QFile("/sys/class/power_supply/battery/health", this); - logE("Health file: " + healthFile->fileName()); - - QString filename; + filename = "/sys/class/power_supply/battery/health"; + if(!healthFile && QFile::exists(filename)) { + healthFile = new QFile(filename, this); + } // e.g. for Sony Xperia XA2 filename = "/sys/class/power_supply/battery/input_suspend"; diff --git a/service/src/battery.cpp b/service/src/battery.cpp index 97695ef..88799f6 100644 --- a/service/src/battery.cpp +++ b/service/src/battery.cpp @@ -39,26 +39,31 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject // Number: charge percentage, e.g. 42 chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this); - logE("Capacity file: " + chargeFile->fileName()); + logE("Capacity file: " + chargeFile->fileName() + (chargeFile->exists() ? " OK" : " doesn't exist")); // String: charging, discharging, full, empty, unknown (others?) stateFile = new QFile("/sys/class/power_supply/battery/status", this); - logE("Charge state file: " + stateFile->fileName()); + logE("Charge state file: " + stateFile->fileName() + (stateFile->exists() ? " OK" : " doesn't exist")); // Number: 0 or 1 chargerConnectedFile = new QFile("/sys/class/power_supply/usb/present", this); - logE("Charger status file: " + chargerConnectedFile->fileName()); + logE("Charger status file: " + chargerConnectedFile->fileName() + (chargerConnectedFile->exists() ? " OK" : " doesn't exist")); + + QString filename; // Number: temperature - temperatureFile = new QFile("/sys/class/power_supply/battery/temp", this); - logE("Temperature file: " + temperatureFile->fileName()); + filename = "/sys/class/power_supply/battery/temp"; + if(!temperatureFile && QFile::exists(filename)) { + temperatureFile = new QFile(filename, this); + } + logE("Temperature file: " + filename + (QFile::exists(filename) ? " OK" : " doesn't exist")); - // String: Good, Warm, Overheat, (others?) - healthFile = new QFile("/sys/class/power_supply/battery/health", this); - logE("Health state file: " + healthFile->fileName()); - - // ENABLE/DISABLE CHARGING - QString filename; + // String: health state + filename = "/sys/class/power_supply/battery/health"; + if(!healthFile && QFile::exists(filename)) { + healthFile = new QFile(filename, this); + } + logE("Battery health file: " + filename + (QFile::exists(filename) ? " OK" : " doesn't exist")); // e.g. for Sony Xperia XA2 filename = "/sys/class/power_supply/battery/input_suspend"; @@ -86,7 +91,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject // If we found a usable file, check that it is writable if(chargingEnabledFile) { - logE("Charger control file: " + chargingEnabledFile->fileName()); + logE("Charger control file: " + chargingEnabledFile->fileName() + (chargingEnabledFile->exists() ? " OK" : " doesn't exist")); if(chargingEnabledFile->open(QIODevice::WriteOnly)) { chargingEnabledFile->close(); } @@ -156,7 +161,7 @@ void Battery::updateData() stateFile->close(); } - if(temperatureFile->open(QIODevice::ReadOnly)) { + if(temperatureFile && temperatureFile->open(QIODevice::ReadOnly)) { nextTemperature = temperatureFile->readLine().trimmed().toInt(); if(nextTemperature != temperature) { temperature = nextTemperature; @@ -165,7 +170,8 @@ void Battery::updateData() } temperatureFile->close(); } - if(healthFile->open(QIODevice::ReadOnly)) { + + if(healthFile && healthFile->open(QIODevice::ReadOnly)) { nextHealth = (QString(healthFile->readLine().trimmed().toLower())); if(nextHealth != health) { health = nextHealth; From f8c017ead1253f2aa5e2824ee422898946755506 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 23 May 2021 15:04:57 +0300 Subject: [PATCH 18/18] Typo fix --- application/translations/harbour-batterybuddy-fi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/translations/harbour-batterybuddy-fi.ts b/application/translations/harbour-batterybuddy-fi.ts index 07e609c..fdcdae0 100644 --- a/application/translations/harbour-batterybuddy-fi.ts +++ b/application/translations/harbour-batterybuddy-fi.ts @@ -415,7 +415,7 @@ Warning - Varoitue + Varoitus Critical