power: fix LBC charger FSM, BMS-VM fuel gauge, WCN36xx BMPS, WCD clock gating, and battery UI
This commit is contained in:
1 parent
ebdb0f8ee2
commit
06d991d4fa
47 files changed
+727
-45
No files matched your search
@@ -98,9 +98,11 @@ void blankScreenBacklight() {
|
||||
writeSysfsStr("/sys/class/leds/white:kbd_backlight/brightness", "0");
|
||||
writeSysfsStr("/sys/class/backlight/backlight/brightness", "0");
|
||||
writeSysfsStr("/sys/class/backlight/backlight/bl_power", "4");
|
||||
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", "powersave");
|
||||
}
|
||||
|
||||
void wakeScreenBacklight() {
|
||||
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", "schedutil");
|
||||
std::string cur = readSmallFileTrimmed("/tmp/sxmo_saved_brightness");
|
||||
int val = std::atoi(cur.c_str());
|
||||
if (val < 1) {
|
||||
@@ -124,6 +126,33 @@ void wakeScreenBacklight() {
|
||||
kbd.empty() ? "255" : kbd.c_str());
|
||||
}
|
||||
|
||||
const char* pickBatteryIcon(int pct, bool charging) {
|
||||
if (charging) {
|
||||
if (pct < 10) return "\xf3\xb0\xa2\x9f";
|
||||
if (pct < 20) return "\xf3\xb0\xa2\x9c";
|
||||
if (pct < 30) return "\xf3\xb0\x82\x86";
|
||||
if (pct < 40) return "\xf3\xb0\x82\x87";
|
||||
if (pct < 50) return "\xf3\xb0\x82\x88";
|
||||
if (pct < 60) return "\xf3\xb0\xa2\x9d";
|
||||
if (pct < 70) return "\xf3\xb0\x82\x89";
|
||||
if (pct < 80) return "\xf3\xb0\xa2\x9e";
|
||||
if (pct < 90) return "\xf3\xb0\x82\x8a";
|
||||
if (pct < 95) return "\xf3\xb0\x82\x8b";
|
||||
return "\xf3\xb0\x82\x85";
|
||||
}
|
||||
if (pct < 10) return "\xf3\xb1\x83\x8d";
|
||||
if (pct < 20) return "\xf3\xb0\x81\xba";
|
||||
if (pct < 30) return "\xf3\xb0\x81\xbb";
|
||||
if (pct < 40) return "\xf3\xb0\x81\xbc";
|
||||
if (pct < 50) return "\xf3\xb0\x81\xbd";
|
||||
if (pct < 60) return "\xf3\xb0\x81\xbe";
|
||||
if (pct < 70) return "\xf3\xb0\x81\xbf";
|
||||
if (pct < 80) return "\xf3\xb0\x82\x80";
|
||||
if (pct < 90) return "\xf3\xb0\x82\x81";
|
||||
if (pct < 95) return "\xf3\xb0\x82\x82";
|
||||
return "\xf3\xb0\x81\xb9";
|
||||
}
|
||||
|
||||
void setSxmoStateFile(const char* st) {
|
||||
std::string path = getRuntimeFile("sxmo.state");
|
||||
std::string content = std::string(st) + "\n";
|
||||
@@ -404,6 +433,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
PasscodeVerifier verifier;
|
||||
verifier.refreshIfNeeded();
|
||||
|
||||
constexpr int64_t kLockerIdleBlankMs = 30000;
|
||||
bool visible = false;
|
||||
bool grabHeld = false;
|
||||
std::string passcode;
|
||||
@@ -413,6 +443,8 @@ int locker_run_main(int argc, char** argv) {
|
||||
int64_t cooldownUntilMs = 0;
|
||||
int64_t statusClearAtMs = 0;
|
||||
int64_t lockActivatedMs = 0;
|
||||
int64_t lastActivityMs = 0;
|
||||
int lastRenderedMin = -1;
|
||||
|
||||
auto grabLockerInput = [&]() {
|
||||
if (!visible || isCallActiveOrRingingFast()) {
|
||||
@@ -475,17 +507,32 @@ int locker_run_main(int argc, char** argv) {
|
||||
neo.drawPango(layoutIcon, &theme.colYellow, 8, 0, 24, kIconLock);
|
||||
neo.drawPango(layoutSmall, &theme.colLight, 26, 0, 24, "Locked");
|
||||
|
||||
std::string cap = readSmallFileTrimmed("/sys/class/power_supply/battery/capacity");
|
||||
std::string batStatus = readSmallFileTrimmed("/sys/class/power_supply/battery/status");
|
||||
std::string batText = cap.empty() ? "" : (cap + "%");
|
||||
if (batStatus == "Charging") {
|
||||
batText = std::string(kIconFlash) + " " + batText;
|
||||
std::string cap = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/capacity");
|
||||
if (cap.empty()) {
|
||||
cap = readSmallFileTrimmed("/sys/class/power_supply/battery/capacity");
|
||||
}
|
||||
if (!batText.empty()) {
|
||||
std::string batStatus = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/status");
|
||||
if (batStatus.empty()) {
|
||||
batStatus = readSmallFileTrimmed("/sys/class/power_supply/battery/status");
|
||||
}
|
||||
std::string chgrOnline = readSmallFileTrimmed("/sys/class/power_supply/pm8916-lbc-chgr/online");
|
||||
int pctVal = cap.empty() ? -1 : std::clamp(std::atoi(cap.c_str()), 0, 100);
|
||||
bool isCharging = (batStatus == "Charging" || batStatus == "Full" || chgrOnline == "1");
|
||||
if (chgrOnline == "0") {
|
||||
isCharging = false;
|
||||
}
|
||||
if (pctVal >= 0) {
|
||||
std::string batText = std::string(pickBatteryIcon(pctVal, isCharging)) +
|
||||
" " + std::to_string(pctVal) + "%";
|
||||
int bw = neo.pangoWidth(layoutSmall, batText);
|
||||
XftColor* batCol = (std::atoi(cap.c_str()) <= 15 && batStatus != "Charging")
|
||||
? &theme.colRed
|
||||
: &theme.colMuted;
|
||||
XftColor* batCol = &theme.colLight;
|
||||
if (isCharging && pctVal >= 95) {
|
||||
batCol = &theme.colGreen;
|
||||
} else if (!isCharging && pctVal < 20) {
|
||||
batCol = &theme.colRed;
|
||||
} else if (!isCharging && pctVal < 50) {
|
||||
batCol = &theme.colYellow;
|
||||
}
|
||||
neo.drawPango(layoutSmall, batCol, kScreenWidth - bw - 8, 0, 24, batText);
|
||||
}
|
||||
|
||||
@@ -493,6 +540,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
std::time_t t = std::time(nullptr);
|
||||
struct tm tmNow {};
|
||||
localtime_r(&t, &tmNow);
|
||||
lastRenderedMin = tmNow.tm_hour * 60 + tmNow.tm_min;
|
||||
char timeBuf[32];
|
||||
char dateBuf[64];
|
||||
std::strftime(timeBuf, sizeof(timeBuf), "%H:%M", &tmNow);
|
||||
@@ -589,7 +637,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
passcode.empty() ? "Sleep" : "Clear",
|
||||
&theme.colYellow);
|
||||
|
||||
if (!isCallActiveOrRingingFast()) {
|
||||
if (!grabHeld && !isCallActiveOrRingingFast()) {
|
||||
grabLockerInput();
|
||||
}
|
||||
neo.present();
|
||||
@@ -634,6 +682,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
lockActivatedMs = nowMs();
|
||||
lastActivityMs = lockActivatedMs;
|
||||
writeSoftkeySuppress(lockActivatedMs + 400);
|
||||
if (!visible) {
|
||||
XMapRaised(dpy, win);
|
||||
@@ -737,7 +786,9 @@ int locker_run_main(int argc, char** argv) {
|
||||
lockPhone(false);
|
||||
} else {
|
||||
closeOtherOverlays();
|
||||
setSxmoStateFile("lock");
|
||||
wakeScreenBacklight();
|
||||
lastActivityMs = nowMs();
|
||||
grabLockerInput();
|
||||
render();
|
||||
}
|
||||
@@ -813,7 +864,9 @@ int locker_run_main(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
int64_t now = nowMs();
|
||||
lastActivityMs = now;
|
||||
if (isScreenBlanked()) {
|
||||
setSxmoStateFile("lock");
|
||||
wakeScreenBacklight();
|
||||
lockActivatedMs = now;
|
||||
render();
|
||||
@@ -898,10 +951,29 @@ int locker_run_main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
if (visible && !isScreenBlanked()) {
|
||||
if (!isCallActiveOrRingingFast() && !grabHeld) {
|
||||
grabLockerInput();
|
||||
int64_t now = nowMs();
|
||||
if (lastActivityMs <= 0) {
|
||||
lastActivityMs = now;
|
||||
}
|
||||
if (now - lastActivityMs >= kLockerIdleBlankMs) {
|
||||
passcode.clear();
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
} else {
|
||||
if (!isCallActiveOrRingingFast() && !grabHeld) {
|
||||
grabLockerInput();
|
||||
}
|
||||
std::time_t t = std::time(nullptr);
|
||||
struct tm tmNow {};
|
||||
localtime_r(&t, &tmNow);
|
||||
int curMin = tmNow.tm_hour * 60 + tmNow.tm_min;
|
||||
if (curMin != lastRenderedMin || cooldownUntilMs > now ||
|
||||
(statusClearAtMs > 0 && now >= statusClearAtMs)) {
|
||||
render();
|
||||
}
|
||||
}
|
||||
render();
|
||||
}
|
||||
|
||||
int timeoutMs = -1;
|
||||
@@ -910,6 +982,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
timeoutMs = 35;
|
||||
} else if (visible && !isScreenBlanked()) {
|
||||
int64_t now = nowMs();
|
||||
int64_t idleRemMs = std::max<int64_t>(50, (lastActivityMs + kLockerIdleBlankMs) - now);
|
||||
if (cooldownUntilMs > now) {
|
||||
timeoutMs = 250;
|
||||
} else if (statusClearAtMs > now) {
|
||||
@@ -921,6 +994,9 @@ int locker_run_main(int argc, char** argv) {
|
||||
localtime_r(&t, &tmNow);
|
||||
timeoutMs = std::max(1, 60 - tmNow.tm_sec) * 1000;
|
||||
}
|
||||
if (idleRemMs < timeoutMs) {
|
||||
timeoutMs = static_cast<int>(idleRemMs);
|
||||
}
|
||||
}
|
||||
|
||||
struct pollfd pfds[2] {};
|
||||
|
||||
Reference in new issue
Block a user