Implement BackgroundActivity-based timers
This commit is contained in:
parent
8e89b48f63
commit
5627c5fc47
9 changed files with 166 additions and 109 deletions
|
@ -45,9 +45,9 @@ Page {
|
||||||
highAlertSlider.value = settings.highAlert
|
highAlertSlider.value = settings.highAlert
|
||||||
healthSelector.currentIndex = settings.healthAlert
|
healthSelector.currentIndex = settings.healthAlert
|
||||||
lowAlertSlider.value = settings.lowAlert
|
lowAlertSlider.value = settings.lowAlert
|
||||||
highIntervalSlider.value = settings.highNotificationsInterval
|
highIntervalCombo.currentIndex = settings.highNotificationsInterval
|
||||||
lowIntervalSlider.value = settings.lowNotificationsInterval
|
lowIntervalCombo.currentIndex = settings.lowNotificationsInterval
|
||||||
healthIntervalSlider.value = settings.healthNotificationsInterval
|
healthIntervalCombo.currentIndex = settings.healthNotificationsInterval
|
||||||
if(logger.debug) logger.log("SettingsPage values updated")
|
if(logger.debug) logger.log("SettingsPage values updated")
|
||||||
daemonCheck.start()
|
daemonCheck.start()
|
||||||
}
|
}
|
||||||
|
@ -314,60 +314,52 @@ Page {
|
||||||
|
|
||||||
SectionHeader { text: qsTr("Battery high notification interval") }
|
SectionHeader { text: qsTr("Battery high notification interval") }
|
||||||
|
|
||||||
MySlider {
|
ComboBox {
|
||||||
id: highIntervalSlider
|
id: highIntervalCombo
|
||||||
minimumValue: 50
|
label: qsTr("Battery high notification interval")
|
||||||
maximumValue: 610
|
menu: ContextMenu {
|
||||||
stepSize: 10
|
Repeater {
|
||||||
valueText: updateValueText()
|
model: frequencyNames
|
||||||
onValueChanged: updateValueText()
|
MenuItem {
|
||||||
function updateValueText() {
|
enabled: index > 0
|
||||||
if(value == 50)
|
visible: index > 0
|
||||||
return qsTr("Once")
|
text: modelData
|
||||||
if(value == 610)
|
onClicked: {
|
||||||
return qsTr("Never")
|
highIntervalCombo.currentIndex = index
|
||||||
return Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
|
highIntervalCombo.save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onReleased: save()
|
|
||||||
function save() {
|
function save() {
|
||||||
settings.highNotificationsInterval = value
|
settings.highNotificationsInterval = currentIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AdjustmentButtons {
|
|
||||||
targetSlider: highIntervalSlider
|
|
||||||
smallChange: 10
|
|
||||||
largeChange: 60
|
|
||||||
}
|
|
||||||
|
|
||||||
SectionHeader { text: qsTr("Battery low notification interval") }
|
SectionHeader { text: qsTr("Battery low notification interval") }
|
||||||
|
|
||||||
MySlider {
|
ComboBox {
|
||||||
id: lowIntervalSlider
|
id: lowIntervalCombo
|
||||||
minimumValue: 50
|
label: qsTr("Battery low notification interval")
|
||||||
maximumValue: 610
|
menu: ContextMenu {
|
||||||
stepSize: 10
|
Repeater {
|
||||||
valueText: updateValueText()
|
model: frequencyNames
|
||||||
onValueChanged: updateValueText()
|
MenuItem {
|
||||||
function updateValueText() {
|
enabled: index > 0
|
||||||
if(value == 50)
|
visible: index > 0
|
||||||
return qsTr("Once")
|
text: modelData
|
||||||
if(value == 610)
|
onClicked: {
|
||||||
return qsTr("Never")
|
lowIntervalCombo.currentIndex = index
|
||||||
return Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
|
lowIntervalCombo.save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onReleased: save()
|
|
||||||
function save() {
|
function save() {
|
||||||
settings.lowNotificationsInterval = value
|
settings.lowNotificationsInterval = currentIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AdjustmentButtons {
|
|
||||||
targetSlider: lowIntervalSlider
|
|
||||||
smallChange: 10
|
|
||||||
largeChange: 60
|
|
||||||
}
|
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
x: Theme.paddingLarge
|
x: Theme.paddingLarge
|
||||||
text: qsTr("Health notification settings")
|
text: qsTr("Health notification settings")
|
||||||
|
@ -406,30 +398,26 @@ Page {
|
||||||
|
|
||||||
SectionHeader { text: qsTr("Health notification interval") }
|
SectionHeader { text: qsTr("Health notification interval") }
|
||||||
|
|
||||||
MySlider {
|
ComboBox {
|
||||||
id: healthIntervalSlider
|
id: healthIntervalCombo
|
||||||
minimumValue: 50
|
label: qsTr("Health notification interval")
|
||||||
maximumValue: 610
|
menu: ContextMenu {
|
||||||
stepSize: 10
|
Repeater {
|
||||||
valueText: updateValueText()
|
model: frequencyNames
|
||||||
onValueChanged: updateValueText()
|
MenuItem {
|
||||||
function updateValueText() {
|
enabled: index > 0
|
||||||
if(value == 50)
|
visible: index > 0
|
||||||
return qsTr("Once")
|
text: modelData
|
||||||
if(value == 610)
|
onClicked: {
|
||||||
return qsTr("Never")
|
healthIntervalCombo.currentIndex = index
|
||||||
return Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
|
healthIntervalCombo.save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onReleased: save()
|
|
||||||
function save() {
|
function save() {
|
||||||
settings.healthNotificationsInterval = value
|
settings.healthNotificationsInterval = currentIndex
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
AdjustmentButtons {
|
|
||||||
targetSlider: healthIntervalSlider
|
|
||||||
smallChange: 10
|
|
||||||
largeChange: 60
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <QQuickView>
|
#include <QQuickView>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
|
@ -87,10 +88,28 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
qmlRegisterType<Process>("Process", 1, 0, "Process");
|
qmlRegisterType<Process>("Process", 1, 0, "Process");
|
||||||
|
|
||||||
|
const QStringList frequencyNames = {
|
||||||
|
QObject::tr("Never"),
|
||||||
|
QObject::tr("30 seconds"),
|
||||||
|
QObject::tr("2.5 minutes"),
|
||||||
|
QObject::tr("5 minutes"),
|
||||||
|
QObject::tr("10 minutes"),
|
||||||
|
QObject::tr("15 minutes"),
|
||||||
|
QObject::tr("30 minutes"),
|
||||||
|
QObject::tr("1 hour"),
|
||||||
|
QObject::tr("2 hours"),
|
||||||
|
QObject::tr("4 hours"),
|
||||||
|
QObject::tr("8 hours"),
|
||||||
|
QObject::tr("10 hours"),
|
||||||
|
QObject::tr("12 hours"),
|
||||||
|
QObject::tr("24 hours"),
|
||||||
|
};
|
||||||
|
|
||||||
view->rootContext()->setContextProperty("battery", battery);
|
view->rootContext()->setContextProperty("battery", battery);
|
||||||
view->rootContext()->setContextProperty("settings", settings);
|
view->rootContext()->setContextProperty("settings", settings);
|
||||||
view->rootContext()->setContextProperty("logger", logger);
|
view->rootContext()->setContextProperty("logger", logger);
|
||||||
view->rootContext()->setContextProperty("app_version", APP_VERSION);
|
view->rootContext()->setContextProperty("app_version", APP_VERSION);
|
||||||
|
view->rootContext()->setContextProperty("frequencyNames", frequencyNames);
|
||||||
|
|
||||||
view->setSource(SailfishApp::pathTo("qml/harbour-batterybuddy.qml"));
|
view->setSource(SailfishApp::pathTo("qml/harbour-batterybuddy.qml"));
|
||||||
view->showFullScreen();
|
view->showFullScreen();
|
||||||
|
|
|
@ -32,9 +32,9 @@ Settings::Settings(Logger *newLogger, QObject *parent) : QObject(parent)
|
||||||
loadInteger(sLowAlert, lowAlert, 5, 99);
|
loadInteger(sLowAlert, lowAlert, 5, 99);
|
||||||
loadInteger(sHighAlert, highAlert, 6, 100);
|
loadInteger(sHighAlert, highAlert, 6, 100);
|
||||||
loadInteger(sHealthAlert, healthAlert, 0, 2);
|
loadInteger(sHealthAlert, healthAlert, 0, 2);
|
||||||
loadInteger(sHighNotificationsInterval, highNotificationsInterval, 50, 610);
|
loadInteger(sHighNotificationsInterval, highNotificationsInterval, 0, 13);
|
||||||
loadInteger(sLowNotificationsInterval, lowNotificationsInterval, 50, 610);
|
loadInteger(sLowNotificationsInterval, lowNotificationsInterval, 0, 13);
|
||||||
loadInteger(sHealthNotificationsInterval, healthNotificationsInterval, 50, 610);
|
loadInteger(sHealthNotificationsInterval, healthNotificationsInterval, 0, 13);
|
||||||
loadInteger(sLimitEnabled, limitEnabled, 0, 1);
|
loadInteger(sLimitEnabled, limitEnabled, 0, 1);
|
||||||
loadInteger(sLowLimit, lowLimit, 5, 99);
|
loadInteger(sLowLimit, lowLimit, 5, 99);
|
||||||
loadInteger(sHighLimit, highLimit, 6, 100);
|
loadInteger(sHighLimit, highLimit, 6, 100);
|
||||||
|
|
|
@ -20,13 +20,14 @@ Source0: %{name}-%{version}.tar.bz2
|
||||||
Requires: sailfishsilica-qt5 >= 0.10.9
|
Requires: sailfishsilica-qt5 >= 0.10.9
|
||||||
Requires: nemo-qml-plugin-configuration-qt5
|
Requires: nemo-qml-plugin-configuration-qt5
|
||||||
Requires: nemo-qml-plugin-notifications-qt5
|
Requires: nemo-qml-plugin-notifications-qt5
|
||||||
Requires: libkeepalive-glib-tools
|
Requires: libkeepalive
|
||||||
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
|
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
|
||||||
BuildRequires: pkgconfig(nemonotifications-qt5)
|
BuildRequires: pkgconfig(nemonotifications-qt5)
|
||||||
BuildRequires: pkgconfig(Qt5Core)
|
BuildRequires: pkgconfig(Qt5Core)
|
||||||
BuildRequires: pkgconfig(Qt5Qml)
|
BuildRequires: pkgconfig(Qt5Qml)
|
||||||
BuildRequires: pkgconfig(Qt5Quick)
|
BuildRequires: pkgconfig(Qt5Quick)
|
||||||
BuildRequires: desktop-file-utils
|
BuildRequires: desktop-file-utils
|
||||||
|
BuildRequires: libkeepalive
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Prolong your battery life.
|
Prolong your battery life.
|
||||||
|
|
|
@ -24,6 +24,8 @@ DEFINES += LEGACY_BUILD=$${LEGACY_BUILD}
|
||||||
# See main() and logger.h for details.
|
# See main() and logger.h for details.
|
||||||
DEFINES += QT_NO_DEBUG_OUTPUT
|
DEFINES += QT_NO_DEBUG_OUTPUT
|
||||||
|
|
||||||
|
LIBS += -lkeepalive
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/battery.h \
|
src/battery.h \
|
||||||
src/logger.h \
|
src/logger.h \
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
|
|
||||||
Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject(parent)
|
Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
logger = newLogger;
|
logger = newLogger;
|
||||||
settings = new Settings(logger, this);
|
settings = new Settings(logger, this);
|
||||||
|
@ -30,10 +30,6 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject
|
||||||
logE(QString("Log level set to %1").arg((logLevel == 0 ? "low" : (logLevel == 1 ? "medium" : "high"))));
|
logE(QString("Log level set to %1").arg((logLevel == 0 ? "low" : (logLevel == 1 ? "medium" : "high"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTimer = new QTimer(this);
|
|
||||||
highNotifyTimer = new QTimer(this);
|
|
||||||
lowNotifyTimer = new QTimer(this);
|
|
||||||
healthNotifyTimer = new QTimer(this);
|
|
||||||
#if LEGACY_BUILD == 1
|
#if LEGACY_BUILD == 1
|
||||||
chargeNotification = new MyNotification(logger, this);
|
chargeNotification = new MyNotification(logger, this);
|
||||||
healthNotification = new MyNotification(logger, this);
|
healthNotification = new MyNotification(logger, this);
|
||||||
|
@ -111,26 +107,48 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject
|
||||||
logE("Please contact the developer with your device model!");
|
logE("Please contact the developer with your device model!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateData()));
|
|
||||||
connect(settings, SIGNAL(resetTimers()), this, SLOT(resetTimers()));
|
connect(settings, SIGNAL(resetTimers()), this, SLOT(resetTimers()));
|
||||||
connect(highNotifyTimer, SIGNAL(timeout()), this, SLOT(showHighNotification()));
|
|
||||||
connect(lowNotifyTimer, SIGNAL(timeout()), this, SLOT(showLowNotification()));
|
updateTimer = new BackgroundActivity(app);
|
||||||
connect(healthNotifyTimer, SIGNAL(timeout()), this, SLOT(showHealthNotification()));
|
highNotifyTimer = new BackgroundActivity(app);
|
||||||
|
lowNotifyTimer = new BackgroundActivity(app);
|
||||||
|
healthNotifyTimer = new BackgroundActivity(app);
|
||||||
|
|
||||||
|
connect(updateTimer, SIGNAL(running()), this, SLOT(updateData()));
|
||||||
|
connect(highNotifyTimer, SIGNAL(running()), this, SLOT(showHighNotification()));
|
||||||
|
connect(lowNotifyTimer, SIGNAL(running()), this, SLOT(showLowNotification()));
|
||||||
|
connect(healthNotifyTimer, SIGNAL(running()), this, SLOT(showHealthNotification()));
|
||||||
|
|
||||||
|
connect(updateTimer, SIGNAL(running()), updateTimer, SLOT(wait()));
|
||||||
|
connect(highNotifyTimer, SIGNAL(running()), highNotifyTimer, SLOT(wait()));
|
||||||
|
connect(lowNotifyTimer, SIGNAL(running()), lowNotifyTimer, SLOT(wait()));
|
||||||
|
connect(healthNotifyTimer, SIGNAL(running()), healthNotifyTimer, SLOT(wait()));
|
||||||
|
|
||||||
updateData();
|
updateData();
|
||||||
updateTimer->start(5000);
|
|
||||||
|
updateTimer->setWakeupFrequency(BackgroundActivity::ThirtySeconds);
|
||||||
|
updateTimer->wait();
|
||||||
|
|
||||||
// If updateData() didn't start the timers
|
// If updateData() didn't start the timers
|
||||||
// aka. "charging" status didn't change
|
// aka. "charging" status didn't change
|
||||||
// (or if both times are disabled, actually)
|
// (or if both times are disabled, actually)
|
||||||
// manually trigger the timer startup.
|
// manually trigger the timer startup.
|
||||||
if(!highNotifyTimer->isActive() && !lowNotifyTimer->isActive() && !healthNotifyTimer->isActive()) {
|
if(!highNotifyTimer->isWaiting() && !lowNotifyTimer->isWaiting() && !healthNotifyTimer->isWaiting()) {
|
||||||
resetTimers();
|
resetTimers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Battery::~Battery() { }
|
Battery::~Battery() {
|
||||||
|
updateTimer->stop();
|
||||||
|
highNotifyTimer->stop();
|
||||||
|
lowNotifyTimer->stop();
|
||||||
|
healthNotifyTimer->stop();
|
||||||
|
|
||||||
|
delete updateTimer;
|
||||||
|
delete highNotifyTimer;
|
||||||
|
delete lowNotifyTimer;
|
||||||
|
delete healthNotifyTimer;
|
||||||
|
}
|
||||||
|
|
||||||
void Battery::updateData()
|
void Battery::updateData()
|
||||||
{
|
{
|
||||||
|
@ -204,31 +222,41 @@ void Battery::resetTimers() {
|
||||||
highNotifyTimer->stop();
|
highNotifyTimer->stop();
|
||||||
lowNotifyTimer->stop();
|
lowNotifyTimer->stop();
|
||||||
healthNotifyTimer->stop();
|
healthNotifyTimer->stop();
|
||||||
highNotifyTimer->setInterval(settings->getHighNotificationsInterval() * 1000);
|
|
||||||
lowNotifyTimer->setInterval(settings->getLowNotificationsInterval() * 1000);
|
|
||||||
healthNotifyTimer->setInterval(settings->getHealthNotificationsInterval() * 1000);
|
|
||||||
|
|
||||||
if(settings->getHighNotificationsInterval() < 610) {
|
|
||||||
|
if(settings->getHighNotificationsInterval() > 0) {
|
||||||
|
highNotifyTimer->setWakeupFrequency(frequencies[settings->getHighNotificationsInterval()]);
|
||||||
|
logD(QString("High notifications frequency %1 => %2 seconds")
|
||||||
|
.arg(settings->getHighNotificationsInterval())
|
||||||
|
.arg(static_cast<int>(frequencies[settings->getHighNotificationsInterval()])));
|
||||||
logD("Starting high battery timer");
|
logD("Starting high battery timer");
|
||||||
highNotifyTimer->start();
|
highNotifyTimer->wait();
|
||||||
showHighNotification();
|
showHighNotification();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logD("High battery timer not started");
|
logD("High battery timer not started");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settings->getLowNotificationsInterval() < 610) {
|
if(settings->getLowNotificationsInterval() > 0) {
|
||||||
|
lowNotifyTimer->setWakeupFrequency(frequencies[settings->getLowNotificationsInterval()]);
|
||||||
|
logD(QString("Low notifications frequency %1 => %2 seconds")
|
||||||
|
.arg(settings->getLowNotificationsInterval())
|
||||||
|
.arg(static_cast<int>(frequencies[settings->getLowNotificationsInterval()])));
|
||||||
logD("Start low battery timer");
|
logD("Start low battery timer");
|
||||||
lowNotifyTimer->start();
|
lowNotifyTimer->wait();
|
||||||
showLowNotification();
|
showLowNotification();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logD("Low battery timer not started");
|
logD("Low battery timer not started");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settings->getHealthNotificationsInterval() < 610) {
|
if(settings->getHealthNotificationsInterval() > 0) {
|
||||||
|
healthNotifyTimer->setWakeupFrequency(frequencies[settings->getHealthNotificationsInterval()]);
|
||||||
|
logD(QString("Health notifications frequency %1 => %2 seconds")
|
||||||
|
.arg(settings->getHealthNotificationsInterval())
|
||||||
|
.arg(static_cast<int>(frequencies[settings->getHealthNotificationsInterval()])));
|
||||||
logD("Start health timer");
|
logD("Start health timer");
|
||||||
healthNotifyTimer->start();
|
healthNotifyTimer->wait();
|
||||||
showHealthNotification();
|
showHealthNotification();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -237,7 +265,7 @@ void Battery::resetTimers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battery::showHighNotification() {
|
void Battery::showHighNotification() {
|
||||||
if(settings->getHighNotificationsInterval() < 610 && (charge >= settings->getHighAlert() && state != "discharging")
|
if(settings->getHighNotificationsInterval() > 0 && (charge >= settings->getHighAlert() && state != "discharging")
|
||||||
&& !(charge == 100 && state == "idle")) {
|
&& !(charge == 100 && state == "idle")) {
|
||||||
logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge)));
|
logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge)));
|
||||||
chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile());
|
chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile());
|
||||||
|
@ -253,7 +281,7 @@ void Battery::showHighNotification() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battery::showLowNotification() {
|
void Battery::showLowNotification() {
|
||||||
if(settings->getLowNotificationsInterval() < 610 && charge <= settings->getLowAlert() && state != "charging") {
|
if(settings->getLowNotificationsInterval() > 0 && charge <= settings->getLowAlert() && state != "charging") {
|
||||||
logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge)));
|
logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge)));
|
||||||
chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile());
|
chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile());
|
||||||
if(settings->getLowNotificationsInterval() == 50) {
|
if(settings->getLowNotificationsInterval() == 50) {
|
||||||
|
@ -284,7 +312,7 @@ void Battery::showHealthNotification() {
|
||||||
{ "overheat" , HealthThresh["crit"] },
|
{ "overheat" , HealthThresh["crit"] },
|
||||||
{ "cold" , HealthThresh["crit"] }
|
{ "cold" , HealthThresh["crit"] }
|
||||||
};
|
};
|
||||||
if(settings->getHealthNotificationsInterval() < 610 && temperature != 0x7FFFFFFF && ( HealthState[health] != HealthThresh["ok"] && HealthState[health] >= settings->getHealthAlert() ) ) {
|
if(settings->getHealthNotificationsInterval() > 0 && temperature != 0x7FFFFFFF && ( HealthState[health] != HealthThresh["ok"] && HealthState[health] >= settings->getHealthAlert() ) ) {
|
||||||
QString displayTemp = QString::number(temperature / 10.0);
|
QString displayTemp = QString::number(temperature / 10.0);
|
||||||
if (QLocale().measurementSystem() == QLocale::ImperialUSSystem)
|
if (QLocale().measurementSystem() == QLocale::ImperialUSSystem)
|
||||||
displayTemp = QString::number((temperature / 10) * 1.8 + 32) + " F";
|
displayTemp = QString::number((temperature / 10) * 1.8 + 32) + " F";
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <keepalive/backgroundactivity.h>
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#if LEGACY_BUILD == 1
|
#if LEGACY_BUILD == 1
|
||||||
#include "mynotification_sfos2.h"
|
#include "mynotification_sfos2.h"
|
||||||
|
@ -38,7 +40,7 @@ class Battery : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Battery(Logger* newLogger, bool loglevelSet, QObject *parent = nullptr);
|
Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QObject *parent = nullptr);
|
||||||
~Battery();
|
~Battery();
|
||||||
|
|
||||||
int getCharge();
|
int getCharge();
|
||||||
|
@ -57,6 +59,24 @@ public slots:
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
BackgroundActivity::Frequency frequencies[14] = {
|
||||||
|
BackgroundActivity::Range,
|
||||||
|
BackgroundActivity::ThirtySeconds,
|
||||||
|
BackgroundActivity::TwoAndHalfMinutes,
|
||||||
|
BackgroundActivity::FiveMinutes,
|
||||||
|
BackgroundActivity::TenMinutes,
|
||||||
|
BackgroundActivity::FifteenMinutes,
|
||||||
|
BackgroundActivity::ThirtyMinutes,
|
||||||
|
BackgroundActivity::OneHour,
|
||||||
|
BackgroundActivity::TwoHours,
|
||||||
|
BackgroundActivity::FourHours,
|
||||||
|
BackgroundActivity::EightHours,
|
||||||
|
BackgroundActivity::TenHours,
|
||||||
|
BackgroundActivity::TwelveHours,
|
||||||
|
BackgroundActivity::TwentyFourHours
|
||||||
|
};
|
||||||
|
|
||||||
Logger *logger;
|
Logger *logger;
|
||||||
QFile *chargeFile = nullptr;
|
QFile *chargeFile = nullptr;
|
||||||
QFile *chargerConnectedFile = nullptr;
|
QFile *chargerConnectedFile = nullptr;
|
||||||
|
@ -65,10 +85,10 @@ private:
|
||||||
QFile *temperatureFile = nullptr;
|
QFile *temperatureFile = nullptr;
|
||||||
QFile *healthFile = nullptr;
|
QFile *healthFile = nullptr;
|
||||||
Settings *settings = nullptr;
|
Settings *settings = nullptr;
|
||||||
QTimer *updateTimer = nullptr;
|
BackgroundActivity *updateTimer = nullptr;
|
||||||
QTimer *highNotifyTimer = nullptr;
|
BackgroundActivity *highNotifyTimer = nullptr;
|
||||||
QTimer *lowNotifyTimer = nullptr;
|
BackgroundActivity *lowNotifyTimer = nullptr;
|
||||||
QTimer *healthNotifyTimer = nullptr;
|
BackgroundActivity *healthNotifyTimer = nullptr;
|
||||||
MyNotification *chargeNotification = nullptr;
|
MyNotification *chargeNotification = nullptr;
|
||||||
MyNotification *healthNotification = nullptr;
|
MyNotification *healthNotification = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
|
@ -71,7 +70,7 @@ int main(int argc, char** argv)
|
||||||
Logger* logger = new Logger(verbose, debug, logfile);
|
Logger* logger = new Logger(verbose, debug, logfile);
|
||||||
logE(QString("%1 %2").arg(APP_NAME, APP_VERSION));
|
logE(QString("%1 %2").arg(APP_NAME, APP_VERSION));
|
||||||
|
|
||||||
Battery* battery = new Battery(logger, logLevelSet);
|
Battery* battery = new Battery(logger, logLevelSet, &app);
|
||||||
|
|
||||||
// Exit gracefully on Ctrl-C and service stop
|
// Exit gracefully on Ctrl-C and service stop
|
||||||
QObject::connect(&app, SIGNAL(aboutToQuit()), battery, SLOT(shutdown()));
|
QObject::connect(&app, SIGNAL(aboutToQuit()), battery, SLOT(shutdown()));
|
||||||
|
|
|
@ -53,8 +53,8 @@ Settings::Settings(Logger* newLogger, QObject *parent) : QObject(parent)
|
||||||
key = "notificationsEnabled";
|
key = "notificationsEnabled";
|
||||||
if(mySettings->contains(key)) {
|
if(mySettings->contains(key)) {
|
||||||
if(mySettings->value(key).toInt() == 0) {
|
if(mySettings->value(key).toInt() == 0) {
|
||||||
mySettings->setValue(sHighNotificationsInterval, 610);
|
mySettings->setValue(sHighNotificationsInterval, 2);
|
||||||
mySettings->setValue(sLowNotificationsInterval, 610);
|
mySettings->setValue(sLowNotificationsInterval, 2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mySettings->setValue(sHighNotificationsInterval, highNotificationsInterval);
|
mySettings->setValue(sHighNotificationsInterval, highNotificationsInterval);
|
||||||
|
@ -75,7 +75,7 @@ Settings::Settings(Logger* newLogger, QObject *parent) : QObject(parent)
|
||||||
key = "highNotificationsEnabled";
|
key = "highNotificationsEnabled";
|
||||||
if(mySettings->contains(key)) {
|
if(mySettings->contains(key)) {
|
||||||
if(mySettings->value(key).toInt() == 0)
|
if(mySettings->value(key).toInt() == 0)
|
||||||
mySettings->setValue(sHighNotificationsInterval, 610);
|
mySettings->setValue(sHighNotificationsInterval, 2);
|
||||||
mySettings->remove(key);
|
mySettings->remove(key);
|
||||||
logV(migrate.arg(key));
|
logV(migrate.arg(key));
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ Settings::Settings(Logger* newLogger, QObject *parent) : QObject(parent)
|
||||||
key = "lowNotificationsEnabled";
|
key = "lowNotificationsEnabled";
|
||||||
if(mySettings->contains(key)) {
|
if(mySettings->contains(key)) {
|
||||||
if(mySettings->value(key).toInt() == 0)
|
if(mySettings->value(key).toInt() == 0)
|
||||||
mySettings->setValue(sLowNotificationsInterval, 610);
|
mySettings->setValue(sLowNotificationsInterval, 2);
|
||||||
mySettings->remove(key);
|
mySettings->remove(key);
|
||||||
logV(migrate.arg(key));
|
logV(migrate.arg(key));
|
||||||
}
|
}
|
||||||
|
@ -133,9 +133,9 @@ void Settings::updateConfig(const QString path) {
|
||||||
loadInteger(sLowAlert, lowAlert, 5, 99);
|
loadInteger(sLowAlert, lowAlert, 5, 99);
|
||||||
loadInteger(sHighAlert, highAlert, 6, 100);
|
loadInteger(sHighAlert, highAlert, 6, 100);
|
||||||
loadInteger(sHealthAlert, healthAlert, 0, 2);
|
loadInteger(sHealthAlert, healthAlert, 0, 2);
|
||||||
restartTimers |= loadInteger(sHighNotificationsInterval, highNotificationsInterval, 50, 610);
|
restartTimers |= loadInteger(sHighNotificationsInterval, highNotificationsInterval, 0, 13);
|
||||||
restartTimers |= loadInteger(sLowNotificationsInterval, lowNotificationsInterval, 50, 610);
|
restartTimers |= loadInteger(sLowNotificationsInterval, lowNotificationsInterval, 0, 13);
|
||||||
restartTimers |= loadInteger(sHealthNotificationsInterval, healthNotificationsInterval, 50, 610);
|
restartTimers |= loadInteger(sHealthNotificationsInterval, healthNotificationsInterval, 0, 13);
|
||||||
loadInteger(sLimitEnabled, limitEnabled, 0, 1);
|
loadInteger(sLimitEnabled, limitEnabled, 0, 1);
|
||||||
loadInteger(sLowLimit, lowLimit, 5, 99);
|
loadInteger(sLowLimit, lowLimit, 5, 99);
|
||||||
loadInteger(sHighLimit, highLimit, 6, 100);
|
loadInteger(sHighLimit, highLimit, 6, 100);
|
||||||
|
|
Loading…
Reference in a new issue