28 lines
1.4 KiB
Diff
28 lines
1.4 KiB
Diff
From 03d01afed688fdba0c7cd31934373c277d615606 Mon Sep 17 00:00:00 2001
|
|
From: classabbyamp <dev@placeviolette.net>
|
|
Date: Sun, 24 Mar 2024 17:16:29 -0400
|
|
Subject: [PATCH] fix(modules/battery): make rate positive if negative
|
|
|
|
on the Lenovo X13s, the battery firmware returns a negative value for
|
|
power_now, which is interpreted by the battery module as 0 because it
|
|
converts the string to unsigned long. This should be read as a long
|
|
instead, as the kernel specifies that power_now is an int:
|
|
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/power_supply.h?h=v6.0.11#n99
|
|
---
|
|
src/modules/battery.cpp | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp
|
|
index 4d966adca..7d7ac3799 100644
|
|
--- a/src/modules/battery.cpp
|
|
+++ b/src/modules/battery.cpp
|
|
@@ -65,7 +65,7 @@ namespace modules {
|
|
}
|
|
|
|
m_rate_reader = make_unique<rate_reader>([this] {
|
|
- unsigned long rate{std::strtoul(file_util::contents(m_frate).c_str(), nullptr, 10)};
|
|
+ unsigned long rate{static_cast<unsigned long>(std::abs(std::strtol(file_util::contents(m_frate).c_str(), nullptr, 10)))};
|
|
unsigned long volt{std::strtoul(file_util::contents(m_fvoltage).c_str(), nullptr, 10) / 1000UL};
|
|
unsigned long now{std::strtoul(file_util::contents(m_fcapnow).c_str(), nullptr, 10)};
|
|
unsigned long max{std::strtoul(file_util::contents(m_fcapfull).c_str(), nullptr, 10)};
|