summaryrefslogtreecommitdiffstats
path: root/health/LearnedCapacityBackupRestore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'health/LearnedCapacityBackupRestore.cpp')
-rw-r--r--health/LearnedCapacityBackupRestore.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/health/LearnedCapacityBackupRestore.cpp b/health/LearnedCapacityBackupRestore.cpp
index cf8de8d3..a3111d38 100644
--- a/health/LearnedCapacityBackupRestore.cpp
+++ b/health/LearnedCapacityBackupRestore.cpp
@@ -21,6 +21,7 @@ namespace google {
namespace wahoo {
namespace health {
+static constexpr char kChgFullDesignFile[] = "sys/class/power_supply/bms/charge_full_design";
static constexpr char kChgFullFile[] = "sys/class/power_supply/bms/charge_full";
static constexpr char kSysCFPersistFile[] = "/persist/battery/qcom_charge_full";
static constexpr int kBuffSize = 256;
@@ -29,13 +30,15 @@ LearnedCapacityBackupRestore::LearnedCapacityBackupRestore() : sw_cap_(0), hw_ca
void LearnedCapacityBackupRestore::Restore() {
ReadFromStorage();
+ ReadNominalCapacity();
ReadFromSRAM();
if (sw_cap_ == 0) {
// First backup
sw_cap_ = hw_cap_;
SaveToStorage();
- } else {
- // Always restore backup value
+ } else if (hw_cap_ == nom_cap_) {
+ // Restore backup value when capacity is reset to nominal
+ hw_cap_ = sw_cap_;
SaveToSRAM();
}
}
@@ -74,11 +77,27 @@ void LearnedCapacityBackupRestore::SaveToStorage() {
LOG(ERROR) << "Write file error: " << strerror(errno);
}
+void LearnedCapacityBackupRestore::ReadNominalCapacity() {
+ std::string buffer;
+
+ if (!android::base::ReadFileToString(std::string(kChgFullDesignFile), &buffer)) {
+ LOG(ERROR) << "Read nominal capacity error: " << strerror(errno);
+ return;
+ }
+
+ buffer = android::base::Trim(buffer);
+
+ if (sscanf(buffer.c_str(), "%d", &nom_cap_) < 1)
+ LOG(ERROR) << "Failed to parse nominal capacity: " << buffer;
+ else
+ LOG(INFO) << "nominal capacity: " << buffer;
+}
+
void LearnedCapacityBackupRestore::ReadFromSRAM() {
std::string buffer;
if (!android::base::ReadFileToString(std::string(kChgFullFile), &buffer)) {
- LOG(ERROR) << "Read cycle counter error: " << strerror(errno);
+ LOG(ERROR) << "Read capacity error: " << strerror(errno);
return;
}