[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,7 +2,7 @@
<service name="tar_git">
<param name="url">https://gitlab.com/takimata/harbour-battery-charging-control.git</param>
<param name="branch">master</param>
- <param name="revision">v0.2.1-2</param>
+ <param name="revision">v0.3.0-1</param>
<param name="token"/>
<param name="debian">N</param>
<param name="dumb">N</param>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/helpers/cli/chargecontroller.cpp
^
|
@@ -1,8 +1,9 @@
-#include <iostream>
-#include <fstream>
#include <cstring>
-#include <string_view>
+#include <cerrno>
#include <filesystem>
+#include <fstream>
+#include <iostream>
+#include <string_view>
#include <string>
#include "chargecontroller.hpp"
@@ -10,12 +11,16 @@
using namespace std;
constexpr string_view BATT_CHG_ENABLE_XPERIA_X = "/sys/class/power_supply/battery/battery_charging_enabled";
-constexpr string_view BATT_CHG_ENABLE_XPERIA_10_II = "/sys/class/power_supply/battery/charging_enabled";
+constexpr string_view BATT_CHG_ENABLE_XPERIA_10_PLUS = "/sys/class/power_supply/battery/charging_enabled";
+constexpr string_view BATT_CHG_ENABLE_XPERIA_10_II = "/sys/class/power_supply/battery/charging_enabled";
+
+// devices where power supply doesn't supply power without charging:
+// XPERIA_10_II
-constexpr string_view LRC_ENABLE_XPERIA_X = "/sys/class/power_supply/battery/lrc_enable";
+constexpr string_view LRC_ENABLE_XPERIA_X = "/sys/class/power_supply/battery/lrc_enable";
constexpr string_view LRC_ENABLE_XPERIA_10_II = "/sys/class/power_supply/battery_ext/lrc_enable";
-constexpr string_view LRC_SOCMAX_XPERIA_X = "/sys/class/power_supply/battery/lrc_socmax";
+constexpr string_view LRC_SOCMAX_XPERIA_X = "/sys/class/power_supply/battery/lrc_socmax";
constexpr string_view LRC_SOCMAX_XPERIA_10_II = "/sys/class/power_supply/battery_ext/lrc_socmax";
int set_property_value(std::string_view sysfspath, std::string_view value) {
@@ -35,21 +40,23 @@
}
}
-ChargeControllerI::ChargeControllerI(const std::string_view batt_chg_enable, const std::string_view lrc_enable,
- const std::string_view lrc_socmax) :
- BATT_CHG_ENABLE(batt_chg_enable), LRC_ENABLE(lrc_enable), LRC_SOCMAX(lrc_socmax) {
+ChargeControllerI::ChargeControllerI(const std::string_view batt_chg_enable, const std::optional<const struct LRC> lrc) :
+ BATT_CHG_ENABLE(batt_chg_enable), lrc(lrc) {
}
ChargeControllerXperia_X::ChargeControllerXperia_X() :
ChargeControllerI(BATT_CHG_ENABLE_XPERIA_X,
- LRC_ENABLE_XPERIA_X,
- LRC_SOCMAX_XPERIA_X) {
+ std::optional<struct LRC>{{.ENABLE = LRC_ENABLE_XPERIA_X, .SOCMAX = LRC_SOCMAX_XPERIA_X}}) {
}
ChargeControllerXperia_10_II::ChargeControllerXperia_10_II() :
ChargeControllerI(BATT_CHG_ENABLE_XPERIA_10_II,
- LRC_ENABLE_XPERIA_10_II,
- LRC_SOCMAX_XPERIA_10_II ) {
+ std::optional<struct LRC>{{.ENABLE = LRC_ENABLE_XPERIA_10_II, .SOCMAX = LRC_SOCMAX_XPERIA_10_II}}) {
+}
+
+ChargeControllerXperia_10_Plus::ChargeControllerXperia_10_Plus() :
+ ChargeControllerI(BATT_CHG_ENABLE_XPERIA_10_PLUS,
+ std::nullopt) {
}
bool ChargeControllerXperia_X::matchDevice() {
@@ -60,19 +67,37 @@
return std::filesystem::exists(BATT_CHG_ENABLE_XPERIA_10_II) && std::filesystem::exists(LRC_ENABLE_XPERIA_10_II);
}
+bool ChargeControllerXperia_10_Plus::matchDevice() {
+ return std::filesystem::exists(BATT_CHG_ENABLE_XPERIA_10_PLUS) &&
+ !std::filesystem::exists("/sys/class/power_supply/battery_ext/") &&
+ !std::filesystem::exists("/sys/class/power_supply/battery/lrc_enable");
+}
+
int ChargeControllerI::toggle_charging(bool enable) {
return set_property_value(BATT_CHG_ENABLE, enable ? "1" : "0");
}
int ChargeControllerI::limited_range_charge_charging(unsigned int upper_limit) {
- int rc = this->toggle_charging(true); // required for LRC to be effective
- rc |= set_property_value(LRC_SOCMAX, std::to_string(upper_limit));
- // need to re-enable LRC so that the kernel picks up a new (possibly higher) limit
- rc |= set_property_value(LRC_ENABLE, "0");
- rc |= set_property_value(LRC_ENABLE, "1");
- return rc;
+ if (lrc.has_value()) {
+ int rc = this->toggle_charging(true); // required for LRC to be effective
+ rc |= set_property_value(lrc.value().SOCMAX, std::to_string(upper_limit));
+ // need to re-enable LRC so that the kernel picks up a new (possibly higher) limit
+ rc |= set_property_value(lrc.value().ENABLE, "0");
+ rc |= set_property_value(lrc.value().ENABLE, "1");
+ return rc;
+ } else {
+ return ENOTSUP;
+ }
}
int ChargeControllerI::limited_range_charge_disable() {
- return set_property_value(LRC_ENABLE, "0");
+ if (lrc.has_value()) {
+ return set_property_value(lrc.value().ENABLE, "0");
+ } else {
+ return ENOTSUP;
+ }
+}
+
+bool ChargeControllerI::supports_kernel_lrc() {
+ return lrc.has_value();
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/helpers/cli/chargecontroller.hpp
^
|
@@ -1,8 +1,16 @@
#ifndef CHARGECONTROLLER_HPP
#define CHARGECONTROLLER_HPP
+#include <optional>
#include <string>
#include <string_view>
+#include <utility>
+
+struct LRC {
+ // sysfs paths for limited range charging
+ std::string_view ENABLE;
+ std::string_view SOCMAX;
+};
class ChargeControllerI {
public:
@@ -12,17 +20,18 @@
* @param lrc_enable
* @param lrc_socmax
*/
- ChargeControllerI(const std::string_view batt_chg_enable, const std::string_view lrc_enable, const std::string_view lrc_socmax);
+ ChargeControllerI(const std::string_view batt_chg_enable, const std::optional<const struct LRC> lrc);
virtual int toggle_charging(bool enable);
virtual int limited_range_charge_charging(unsigned int upper_limit);
virtual int limited_range_charge_disable();
+ virtual bool supports_kernel_lrc();
protected:
// sysfs paths
const std::string_view BATT_CHG_ENABLE;
- const std::string_view LRC_ENABLE;
- const std::string_view LRC_SOCMAX;
+ // if no value present, kernel doesn't support range limited charging
+ const std::optional<LRC> lrc;
};
class ChargeControllerXperia_X : public ChargeControllerI {
@@ -43,6 +52,17 @@
/**
* @brief matchDevice
+ * @return whether this controller is capable of controlling this device
+ */
+ static bool matchDevice();
+};
+
+class ChargeControllerXperia_10_Plus : public ChargeControllerI {
+ public:
+ ChargeControllerXperia_10_Plus();
+
+ /**
+ * @brief matchDevice
* @return whether this controller is capable of controlling this device
*/
static bool matchDevice();
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/helpers/cli/cli.cpp
^
|
@@ -1,10 +1,11 @@
-#include <iostream>
-#include <fstream>
+#include <charconv>
#include <cstring>
-#include <string_view>
+#include <cerrno>
#include <filesystem>
+#include <fstream>
+#include <iostream>
#include <string>
-#include <charconv>
+#include <string_view>
#include "chargecontroller.hpp"
using namespace std;
@@ -14,6 +15,8 @@
return std::make_unique<ChargeControllerXperia_X>();
} else if (ChargeControllerXperia_10_II::matchDevice()) {
return std::make_unique<ChargeControllerXperia_10_II>();
+ } else if (ChargeControllerXperia_10_Plus::matchDevice()) {
+ return std::make_unique<ChargeControllerXperia_10_Plus>();
} else {
std::cerr << "Could not determine device model" << std::endl;
exit(EXIT_FAILURE);
@@ -33,13 +36,21 @@
int main(int argc, char *argv[]) {
if (argc != 2) {
- std::cerr << "Usage: " << ((argc > 0) ? argv[0] : "") << " on || off || <LRC_MAX_LIMIT_IN_PERCENT> || lrcoff " << std::endl;
+ std::cerr << "Usage: " << ((argc > 0) ? argv[0] : "") << " OPTION" << std::endl;
+ std::cerr << "where OPTION can be: " << std::endl;
+ std::cerr << " has-kernel-lrc exit code is 0 if device supports kernel-controlled charge limit" << std::endl;
+ std::cerr << " on enable charging" << std::endl;
+ std::cerr << " off disable charging" << std::endl;
+ std::cerr << " <LRC_MAX_LIMIT_IN_PERCENT> percentage where to stop charging" << std::endl;
+ std::cerr << " lrcoff disable kernel-controlled charging" << std::endl;
exit(EXIT_FAILURE);
}
unsigned int lrc_max_percentage = 0;
- if (std::strcmp(argv[1], "on") == 0) {
+ if (std::strcmp(argv[1], "has-kernel-lrc") == 0) {
+ return getController()->supports_kernel_lrc() ? 0 : ENOTSUP;
+ } else if (std::strcmp(argv[1], "on") == 0) {
return toggle_charging(true);
} else if (std::strcmp(argv[1], "off") == 0) {
return toggle_charging(false);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/helpers/cli/cli.pro
^
|
@@ -9,7 +9,8 @@
QMAKE_CXXFLAGS += -Wall -Wextra -Werror -Wmissing-include-dirs -Wredundant-decls -Woverloaded-virtual -Wundef -Wctor-dtor-privacy -Wcast-align -Wcast-qual -Wswitch-default -Wswitch-enum -Wfloat-equal -Wold-style-cast
#CONFIG += c++17 # doesn't work with current Qt
-QMAKE_CXXFLAGS += -std=c++17
+# TODO: change c++2a to c++20 with gcc 9
+QMAKE_CXXFLAGS += -std=c++2a
# TODO can be removed with GCC 9:
LIBS += -lstdc++fs
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/main.pro
^
|
@@ -16,8 +16,9 @@
#CONFIG += c++17 # doesn't work with current Qt
QMAKE_CXXFLAGS += -std=c++17
QMAKE_CXXFLAGS += -Wall -Wextra -Werror -Wmissing-include-dirs -Wredundant-decls -Woverloaded-virtual -Wundef -Wctor-dtor-privacy -Wcast-align -Wcast-qual -Wswitch-default -Wswitch-enum -Wfloat-equal -Wold-style-cast
-
QMAKE_CXXFLAGS += -lstdc++fs
+LIBS += -lkeepalive
+DEFINES += APPLICATION_NAME=\'\"$$TARGET\"\'
HEADERS += \
src/controllerModel.hpp \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/qml/cover/CoverPage.qml
^
|
@@ -34,7 +34,7 @@
Label {
font.pixelSize: Theme.fontSizeLarge
anchors.horizontalCenter: parent.horizontalCenter
- text: cppModel.currentValue + "%"
+ text: cppModel.currentSoC + "%"
}
Label {
@@ -48,7 +48,7 @@
Label {
font.pixelSize: Theme.fontSizeLarge
anchors.horizontalCenter: parent.horizontalCenter
- text: cppModel.upperLimit + "%"
+ text: cppModel.upperSoCLimit + "%"
visible: cppModel.charging & cppModel.automaticMode
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/qml/pages/AutomaticMode.qml
^
|
@@ -12,8 +12,8 @@
SilicaFlickable {
anchors.fill: parent
- contentHeight: (page.orientation === Orientation.Landscape
- || page.orientation === Orientation.LandscapeInverted) ? content.height : 0
+ // content.height includes pageheader.height, so don't add it here
+ contentHeight: content.height
VerticalScrollDecorator {}
PullDownMenu {
@@ -29,6 +29,7 @@
}
PageHeader {
+ id: pageheader
title: qsTr("Automatic charging control")
}
@@ -50,8 +51,7 @@
// use this as workaround for now
Rectangle {
width: parent.width
- height: ((page.orientation != Orientation.Landscape
- && page.orientation != Orientation.LandscapeInverted) ? 0.2 : 0.1) * page.height
+ height: pageheader.height + Theme.paddingMedium
opacity: 0
}
@@ -59,10 +59,39 @@
width: parent.width - 2 * Theme.horizontalPageMargin
wrapMode: Text.Wrap
anchors.horizontalCenter: parent.horizontalCenter
+ horizontalAlignment: Text.AlignHCenter
text: qsTr(
"Charging will be automatically disabled if the battery level reaches the upper limit and enabled if it drops below this limit.")
}
+ // would fit better here but label text is not centered
+ // ProgressBar {
+ // width: parent.width
+ // anchors.horizontalCenter: parent.horizontalCenter
+ // minimumValue: 0
+ // maximumValue: 100
+ // value: cppModel.currentSoC
+ // valueText: value + "%"
+ // label: qsTr("Current battery level")
+ // }
+ ContextProperty {
+ id: listener_current
+ key: "Battery.Current"
+ value: 0
+ onValueChanged: notChargingInfo.opacity = (Math.round(
+ value / 1000) === 0 ? 1 : 0)
+ }
+
+ Label {
+ id: notChargingInfo
+ width: parent.width - 2 * Theme.horizontalPageMargin
+ wrapMode: Text.Wrap
+ anchors.horizontalCenter: parent.horizontalCenter
+ horizontalAlignment: Text.AlignHCenter
+ text: qsTr(
+ "The external power source will continue to feed your device - only battery charging is stopped.")
+ }
+
Slider {
id: sliderUpperLimit
label: qsTr("Upper Limit")
@@ -74,10 +103,10 @@
maximumValue: 100
stepSize: 1
// set initial value
- Component.onCompleted: value = cppModel.upperLimit
+ Component.onCompleted: value = cppModel.upperSoCLimit
valueText: value + "%"
onReleased: {
- cppModel.upperLimit = this.value
+ cppModel.upperSoCLimit = this.value
settings.upperLimit = this.value
}
}
@@ -90,41 +119,23 @@
minimumValue: 0
maximumValue: 100
stepSize: 1
- value: cppModel.currentValue
- valueText: cppModel.currentValue + "%"
+ value: cppModel.currentSoC
+ valueText: cppModel.currentSoC + "%"
label: qsTr("Current battery level")
}
- // would fit better here but label text is not centered
- // ProgressBar {
- // width: parent.width
- // anchors.horizontalCenter: parent.horizontalCenter
- // minimumValue: 0
- // maximumValue: 100
- // value: cppModel.currentValue
- // valueText: value + "%"
- // label: qsTr("Current battery level")
- // }
- ContextProperty {
- id: listener_current
- key: "Battery.Current"
- value: 0
- onValueChanged: notChargingInfo.opacity = (Math.round(
- value / 1000) === 0 ? 1 : 0)
+ BatteryInfo {
+ anchors.horizontalCenter: parent.horizontalCenter
}
Label {
- id: notChargingInfo
width: parent.width - 2 * Theme.horizontalPageMargin
wrapMode: Text.Wrap
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
- text: qsTr(
- "The external power source will continue to feed your device - only battery charging is stopped.")
- }
-
- BatteryInfo {
- anchors.horizontalCenter: parent.horizontalCenter
+ text: cppModel.kernelSupportsLRC ? qsTr(
+ "You can close the app now, your device will stop charging by itself until next reboot.") : qsTr(
+ "This device doesn't support automatic charge control, so please keep the app running.")
}
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/src/controllerModel.cpp
^
|
@@ -1,18 +1,29 @@
-#include <QtDebug>
-#include <QList>
-#include <unistd.h>
+#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
+
+#include <QtDebug>
+#include <QList>
-#include <iostream>
#include "controllerModel.hpp"
constexpr char const *CLI_BIN_NAME = "harbour-battery-charging-control-cli";
-ControllerModel::ControllerModel(const Settings& seed, QObject *parent) :
+ControllerModel::ControllerModel(Settings& cfg, QObject *parent) :
QObject(parent),
- upperLimit(seed.getUpperLimit()),
- automaticMode(seed.getAutomaticMode()) {
+ upperSoCLimit(cfg.getUpperLimit()),
+ automaticMode(cfg.getAutomaticMode()),
+ kernelSupportsLRC(lazy_value_or_else(cfg.getCachedKernelSupportsLRC(), [] {return isKernelSupportsLRC();})),
+ chargeActivity(this) {
+ chargeActivity.setWakeupFrequency(BackgroundActivity::TenMinutes);
+ connect(&chargeActivity, SIGNAL(running()), this, SLOT(bg_activity()));
+
+ if (!cfg.getCachedKernelSupportsLRC()) {
+ cfg.setCachedKernelSupportsLRC(kernelSupportsLRC);
+ }
+
+ applyCurrentChargingPolicy();
}
int ControllerModel::call_cli(const char *const argv[]) {
@@ -34,28 +45,52 @@
}
}
+bool ControllerModel::isKernelSupportsLRC() {
+ int ret = call_cli((const char *const[]) {CLI_BIN_NAME, "has-kernel-lrc", NULL});
+ return (ret == 0) ? true : false;
+}
+
int ControllerModel::enableCharging(bool enable) {
qDebug() << "Charging enabled: " << enable;
const char *const argv[] = {CLI_BIN_NAME, enable ? "on" : "off", NULL};
- return this->call_cli(argv);
+ return call_cli(argv);
}
int ControllerModel::limited_range_charge_charging(unsigned int upper_limit) {
std::string limit = std::to_string(upper_limit);
const char *const argv[] = {CLI_BIN_NAME, limit.c_str(), NULL};
- return this->call_cli(argv);
+ return call_cli(argv);
}
int ControllerModel::limited_range_charge_disable() {
- return this->call_cli((const char *const[]) {CLI_BIN_NAME, "lrcoff", NULL});
+ return call_cli((const char *const[]) {CLI_BIN_NAME, "lrcoff", NULL});
+}
+
+void ControllerModel::bg_activity() {
+ if (currentSoC >= upperSoCLimit) {
+ enableCharging(false);
+ chargeActivity.stop();
+ } else {
+ enableCharging(true);
+ chargeActivity.wait();
+ }
}
/** Enables or disables charging depending on the current state
- * @brief ControllerModel::applyChargingPolicy
+ * @brief ControllerModel::applyCurrentChargingPolicy
*/
-void ControllerModel::applyChargingPolicy() {
+void ControllerModel::applyCurrentChargingPolicy() {
if (automaticMode) {
- this->limited_range_charge_charging(upperLimit);
+ if (kernelSupportsLRC) {
+ this->limited_range_charge_charging(upperSoCLimit);
+ } else {
+ bg_activity();
+ }
+ } else {
+ if (kernelSupportsLRC) {
+ // manual mode enabled
+ this->limited_range_charge_disable();
+ }
}
}
@@ -75,9 +110,16 @@
bool powerSupplyPreviouslyPresent = powerSupplyPresent;
if (powerSupply == "None") {
powerSupplyPresent = false; // empty charger type means no power source
+ if (!kernelSupportsLRC) {
+ qDebug() << "chargeActivity stopped";
+ chargeActivity.stop();
+ }
} else {
powerSupplyPresent = true;
- applyChargingPolicy();
+ if (!kernelSupportsLRC) {
+ qDebug() << "chargeActivity enabled";
+ chargeActivity.wait();
+ }
}
if (powerSupplyPreviouslyPresent != powerSupplyPresent) {
emit chargerConnectedChanged();
@@ -85,41 +127,39 @@
}
void ControllerModel::setAutomaticMode(bool value) {
- if (value != automaticMode) {
- automaticMode = value;
- emit automaticModeChanged();
-
- if (automaticMode) {
- // was enabled
-
- } else { // manual mode enabled
- this->limited_range_charge_disable();
- }
-
- applyChargingPolicy();
+ if (value == automaticMode) {
+ return;
}
+ automaticMode = value;
+ applyCurrentChargingPolicy();
+ emit automaticModeChanged();
}
-void ControllerModel::setUpperLimit(uint value) {
- if (upperLimit == value) {
+void ControllerModel::setUpperLimit(uint soc_percentage) {
+ if (upperSoCLimit == soc_percentage) {
return;
}
-
- value = limitValue(value);
-
- upperLimit = value;
- applyChargingPolicy();
+ soc_percentage = (soc_percentage > 100) ? 100 : soc_percentage;
+ upperSoCLimit = soc_percentage;
+ applyCurrentChargingPolicy();
emit upperLimitChanged();
}
-void ControllerModel::setCurrentChargePercentage(uint percentage) {
- qDebug() << "setCurrentChargePercentage: " << percentage;
- percentage = limitValue(percentage);
- if (currentValue == percentage) {
+void ControllerModel::setCurrentChargePercentage(uint new_soc_percentage) {
+ qDebug() << "setCurrentChargePercentage: " << new_soc_percentage;
+ new_soc_percentage = (new_soc_percentage > 100) ? 100 : new_soc_percentage;
+ /* In case we are satisfactorily charged, the BackgroundActivity is stopped.
+ * If we now temporarily loose some charge due to heavy load, we might want to charge again.
+ * As all of this can happen while connected to a charger, we have to look at the current SOC.
+ */
+ if (!kernelSupportsLRC && (new_soc_percentage < currentSoC)) {
+ bg_activity();
+ }
+
+ if (currentSoC == new_soc_percentage) {
return;
}
- currentValue = percentage;
- // applyChargingPolicy();
+ currentSoC = new_soc_percentage;
emit currentValueChanged();
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/src/controllerModel.hpp
^
|
@@ -1,25 +1,33 @@
#ifndef CONTROLLERMODEL_H
#define CONTROLLERMODEL_H
+#include <memory>
#include <QtCore>
#include <QMap>
-#include <memory>
-
#include <QtDebug>
+
+#include <keepalive/backgroundactivity.h> // see https://github.com/sailfishos/nemo-keepalive for doc
+
#include "settings.hpp"
+template<typename T, typename F>
+T lazy_value_or_else(const std::optional<T> &opt, F fn) {
+ return (opt) ? opt.value() : fn();
+}
+
class ControllerModel : public QObject {
Q_OBJECT
- Q_PROPERTY(uint upperLimit READ getUpperLimit WRITE setUpperLimit NOTIFY upperLimitChanged)
- Q_PROPERTY(uint currentValue READ getCurrentValue NOTIFY currentValueChanged)
+ Q_PROPERTY(uint upperSoCLimit READ getUpperLimit WRITE setUpperLimit NOTIFY upperLimitChanged)
+ Q_PROPERTY(uint currentSoC READ getCurrentValue NOTIFY currentValueChanged)
Q_PROPERTY(bool charging READ isCharging WRITE enableCharging NOTIFY isChargingChanged)
Q_PROPERTY(bool automaticMode READ getAutomaticMode WRITE setAutomaticMode NOTIFY automaticModeChanged)
+ Q_PROPERTY(bool kernelSupportsLRC READ getKernelSupportsLRC NOTIFY kernelSupportsLRCChanged)
Q_PROPERTY(bool chargerConnected READ isChargerConnected NOTIFY chargerConnectedChanged)
Q_PROPERTY(int batteryTemperatureInDecaCelsius READ getBatteryTemperatureInDecaCelsius NOTIFY batteryTemperatureInDecaCelsiusChanged)
private slots:
- void applyChargingPolicy();
+ void bg_activity();
private:
enum ChargingState {Unknown, Charging, Discharging, Idle};
@@ -29,30 +37,19 @@
std::make_pair("idle", ChargingState::Idle)};
ChargingState chargingState = ChargingState::Unknown;
- bool powerSupplyPresent = false;
+ bool powerSupplyPresent = false;
int batteryTemperatureInDecaCelsius = 0;
-
- uint upperLimit = 70, currentValue = 0;
+ // (configured limit of) state of charge in percent
+ uint upperSoCLimit = 80, currentSoC = 0;
bool automaticMode = true;
+ const bool kernelSupportsLRC;
- // void applyChargingPolicy();
- void allowDeepSuspend(bool deepSuspendAllowed);
+ BackgroundActivity chargeActivity;
- /** bound uint to [0, 100]
- * @brief limitValue
- * @param value
- * @return a valid percentage
- */
- uint limitValue(uint value) {
- if (value > 100) {
- return 100;
- } else {
- return value;
- }
- }
+ void applyCurrentChargingPolicy();
public:
- explicit ControllerModel(const Settings& settings, QObject *parent = 0);
+ explicit ControllerModel(Settings& settings, QObject *parent = 0);
bool isCharging() {
return (chargingState == ChargingState::Charging);
@@ -71,10 +68,14 @@
}
uint getUpperLimit() const {
- return upperLimit;
+ return upperSoCLimit;
}
uint getCurrentValue() const {
- return currentValue;
+ return currentSoC;
+ }
+
+ bool getKernelSupportsLRC() {
+ return kernelSupportsLRC;
}
/** Jump through some hoops to avoid system()
@@ -82,11 +83,12 @@
* @param argv
* @return child exir code
*/
- int call_cli(const char *const argv[]);
+ static int call_cli(const char *const argv[]);
- int enableCharging(bool enable);
- int limited_range_charge_charging(unsigned int upper_limit);
- int limited_range_charge_disable();
+ static bool isKernelSupportsLRC();
+ static int enableCharging(bool enable);
+ static int limited_range_charge_charging(unsigned int upper_limit);
+ static int limited_range_charge_disable();
void setAutomaticMode(bool v);
void setUpperLimit(uint value);
@@ -100,7 +102,6 @@
* see https://git.sailfishos.org/mer-core/nemo-qml-plugin-contextkit/blob/master/src/providers/Battery.qml
*/
void setCurrentChargingState(const QString& state);
- ///
/** To be called when external power source changes
* @brief setCurrentExternalPowerSupply
@@ -114,6 +115,7 @@
void currentValueChanged();
void isChargingChanged();
void automaticModeChanged();
+ void kernelSupportsLRCChanged();
void chargerConnectedChanged();
void batteryTemperatureInDecaCelsiusChanged();
};
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/src/harbour-battery-charging-control.cpp
^
|
@@ -1,6 +1,6 @@
+#include <sailfishapp.h>
#include <QtQuick>
#include <QObject>
-#include <sailfishapp.h>
#include <QQmlEngine>
#include <QScopedPointer>
#include "controllerModel.hpp"
@@ -8,6 +8,8 @@
int main(int argc, char *argv[]) {
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
+ app->setOrganizationName(QStringLiteral(APPLICATION_NAME));
+ app->setApplicationName(QStringLiteral(APPLICATION_NAME));
QScopedPointer<QQuickView> view(SailfishApp::createView());
Settings settings;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/src/settings.cpp
^
|
@@ -1,15 +1,18 @@
+#include <optional>
#include "settings.hpp"
// keys for settings
const QString SK_Auto = QStringLiteral("AutomaticMode");
const QString SK_upperLimit = QStringLiteral("StopChargingAt");
+const QString SK_KernelSupportsLRC = QStringLiteral("CachedDeviceKernelSupportsLRC");
-Settings::Settings(QObject *parent) : QObject(parent) {
+Settings::Settings(QObject *parent) : QObject(parent), settings(QStringLiteral(APPLICATION_NAME), QStringLiteral(APPLICATION_NAME), this) {
}
bool Settings::getAutomaticMode() const {
return settings.value(SK_Auto, QVariant(true)).toBool();
}
+
void Settings::setAutomaticMode(bool isAuto) {
bool changed = false;
if (isAuto != getAutomaticMode()) {
@@ -22,8 +25,9 @@
}
uint Settings::getUpperLimit() const {
- return settings.value(SK_upperLimit, QVariant(70)).toUInt();
+ return settings.value(SK_upperLimit, QVariant(80)).toUInt();
}
+
void Settings::setUpperLimit(uint chargeLimit) {
bool changed = false;
if (chargeLimit != getUpperLimit()) {
@@ -34,3 +38,12 @@
emit upperLimitChanged();
}
}
+
+std::optional<bool> Settings::getCachedKernelSupportsLRC() const {
+ QVariant val = settings.value(SK_KernelSupportsLRC);
+ return val.isNull() ? std::nullopt : std::optional<bool>{val.toBool()};
+}
+
+void Settings::setCachedKernelSupportsLRC(bool kernel_supports_lrc) {
+ settings.setValue(SK_KernelSupportsLRC, kernel_supports_lrc);
+}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/src/settings.hpp
^
|
@@ -1,6 +1,7 @@
#ifndef SETTINGS_HPP
#define SETTINGS_HPP
+#include <optional>
#include <QObject>
#include <QSettings>
@@ -23,6 +24,9 @@
uint getUpperLimit() const;
void setUpperLimit(uint chargeLimit);
+ std::optional<bool> getCachedKernelSupportsLRC() const;
+ void setCachedKernelSupportsLRC(bool kernel_supports_lrc);
+
signals:
void automaticModeChanged();
void upperLimitChanged();
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/translations/harbour-battery-charging-control-de.ts
^
|
@@ -27,6 +27,14 @@
<source>The external power source will continue to feed your device - only battery charging is stopped.</source>
<translation>Das Ladegerät versorgt das Gerät weiter mit Strom, nur das Aufladen ist gestoppt.</translation>
</message>
+ <message>
+ <source>This device doesn't support automatic charge control, so please keep the app running.</source>
+ <translation>Dein Gerät unterstützt keine vollautomatische Ladekontrolle, weswegen die App im Hintergrund weiter laufen muss.</translation>
+ </message>
+ <message>
+ <source>You can close the app now, your device will stop charging by itself until next reboot.</source>
+ <translation>Du kannst die App nun schließen, das Laden wird nun vollautomatisch gesteuert (bis zum nächsten Reboot).</translation>
+ </message>
</context>
<context>
<name>BatteryInfo</name>
@@ -60,7 +68,7 @@
</message>
<message>
<source>Please report a bug: Your device is charging but no power supply seems to be connected!</source>
- <translation type="unfinished"></translation>
+ <translation>Bitte melde einen Fehler: Dein Gerät scheint ohne Ladegerät zu laden!</translation>
</message>
</context>
<context>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/translations/harbour-battery-charging-control-sv.ts
^
|
@@ -27,6 +27,14 @@
<source>The external power source will continue to feed your device - only battery charging is stopped.</source>
<translation>Den externa strömkällan fortsätter att mata din enhet. - Endast batteriladdning stoppas.</translation>
</message>
+ <message>
+ <source>This device doesn't support automatic charge control, so please keep the app running.</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>You can close the app now, your device will stop charging by itself until next reboot.</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
<context>
<name>BatteryInfo</name>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control-0.3.0.tar.bz2/main/translations/harbour-battery-charging-control.ts
^
|
@@ -27,6 +27,14 @@
<source>The external power source will continue to feed your device - only battery charging is stopped.</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>This device doesn't support automatic charge control, so please keep the app running.</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>You can close the app now, your device will stop charging by itself until next reboot.</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
<context>
<name>BatteryInfo</name>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-battery-charging-control.yaml
^
|
@@ -1,7 +1,7 @@
Name: harbour-battery-charging-control
Summary: Controls battery charging
-Version: 0.2.1
-Release: 2
+Version: 0.3.0
+Release: 1
# The contents of the Group field should be one of the groups listed here:
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
Group: Applications/System
@@ -31,6 +31,7 @@
# Build dependencies without a pkgconfig setup can be listed here
PkgBR:
- qt5-qttools-linguist
+ - libkeepalive-devel
# Runtime dependencies which are not automatically detected
Requires:
|