Skip to content

Commit 5ea441b

Browse files
JohnAZoidbergclaude
andcommitted
--smartbattery: Check time above 45C using the temperature ranges
The high temperature check counted the HT and OT rows of the time in ranges table. What they mean depends on the pack: with TI's defaults HT starts at 30C, on FRANDBAT01 at 52C, so time at 45-52C (STH) didn't count. When the thresholds are known (unsealed, or a known pack), count the ranges that start at 45C or above instead. Our packs reduce charging above 45C and the EC doesn't start charging above 45C on most packs. Otherwise keep counting HT and OT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5bdef4e commit 5ea441b

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

‎framework_lib/src/smart_battery.rs‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,9 @@ const KNOWN_TEMP_RANGES: &[(&str, &str, [i16; 7])] = &[
16361636
),
16371637
];
16381638

1639+
/// Temperature above which time spent counts as aging the battery faster
1640+
const HOT_TEMP_C: f32 = 45.0;
1641+
16391642
struct TempRanges {
16401643
/// Thresholds in C, in ascending order (T1, T2, T5, T6, T3, T4),
16411644
/// which separate the TEMP_RANGES
@@ -2783,14 +2786,27 @@ pub fn health_findings(data: &BatteryData) -> Vec<Finding> {
27832786
// Usage: high temperature and high charge speed up aging
27842787
if let Some(hours) = lifetime_temp_soc_hours(data) {
27852788
let total: f64 = hours.iter().flatten().sum();
2786-
// HT and OT rows
2787-
let hot: f64 = hours[5..].iter().flatten().sum();
2789+
// With known thresholds, count the ranges starting at 45C or above.
2790+
// Our packs reduce charging above 45C (T5/T6) and the EC doesn't
2791+
// start charging above 45C on most packs.
2792+
// Otherwise fall back to the HT and OT rows.
2793+
let (hot_rows, description) = match temp_range_thresholds(data) {
2794+
Some(ranges) => (
2795+
(1..TEMP_RANGES.len())
2796+
.filter(|&i| ranges.thresholds[i - 1] >= HOT_TEMP_C)
2797+
.collect::<Vec<_>>(),
2798+
format!("above {:.0}C", HOT_TEMP_C),
2799+
),
2800+
None => (vec![5, 6], "in high temperature ranges".to_string()),
2801+
};
2802+
let hot: f64 = hot_rows.iter().flat_map(|&i| hours[i].iter()).sum();
27882803
if total > 0.0 && hot / total >= 0.05 {
27892804
add(
27902805
Severity::Warning,
27912806
format!(
2792-
"Spent {:.0}% of the time in high temperature ranges",
2793-
hot / total * 100.0
2807+
"Spent {:.0}% of the time {}",
2808+
hot / total * 100.0,
2809+
description
27942810
),
27952811
);
27962812
}
@@ -3306,6 +3322,21 @@ mod tests {
33063322
messages(&data, Severity::Warning),
33073323
["Spent 73% of the time above 90% charge, consider setting a charge limit"]
33083324
);
3325+
3326+
// 1000h in STH (>=60% charge), which is 45-52C on FRANDBAT01
3327+
let mut data = healthy_data();
3328+
data.lifetime_temp_soc[4][12..16].copy_from_slice(&(1000 * 3600u32).to_le_bytes());
3329+
// Unknown thresholds: Only HT and OT count as hot
3330+
assert!(messages(&data, Severity::Warning).is_empty());
3331+
data.manufacturer_name = "NVT".to_string();
3332+
data.device_name = "FRANDBAT01".to_string();
3333+
let warnings = messages(&data, Severity::Warning);
3334+
assert_eq!(warnings.len(), 1, "{:?}", warnings);
3335+
assert!(
3336+
warnings[0].starts_with("Spent ") && warnings[0].ends_with("% of the time above 45C"),
3337+
"{}",
3338+
warnings[0]
3339+
);
33093340
}
33103341

33113342
#[test]

0 commit comments

Comments
 (0)