Skip to content

Commit 7e9eb5e

Browse files
feat: improve temprature readings
1 parent ac170a2 commit 7e9eb5e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

app/src/main/java/com/rk/taskmanager/screens/cpu/CpuInfoReader.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,35 @@ object CpuInfoReader {
7272
"/sys/devices/platform/s5p-tmu/curr_temp"
7373
)
7474

75+
var maxTemp: Int? = null
76+
7577
for (path in sensorPaths) {
7678
try {
7779
val file = File(path)
7880
if (!file.exists()) continue
7981

8082
val raw = file.readText().trim().toInt()
8183

82-
// Most Android/Linux sensors report millidegrees
83-
return (if (raw > 1000) raw / 1000 else raw).toString()
84+
// Convert millidegrees to degrees if needed
85+
val tempC = when {
86+
raw > 100_000 -> raw / 1000 // safety for weird sensors
87+
raw > 1_000 -> raw / 1000
88+
else -> raw
89+
}
90+
91+
// Filter out obviously broken values
92+
if (tempC in 5..130) {
93+
maxTemp = if (maxTemp == null) tempC else maxOf(maxTemp!!, tempC)
94+
}
8495
} catch (_: Exception) {
85-
// Ignore and try next sensor
96+
// Ignore and continue
8697
}
8798
}
8899

89-
return "N/A"
100+
return maxTemp?.toString() ?: "N/A"
90101
}
91102

103+
92104
fun getUptimeFormatted(): String {
93105
// SystemClock.elapsedRealtime() returns milliseconds since boot
94106
val uptimeMillis = SystemClock.elapsedRealtime()

0 commit comments

Comments
 (0)