Skip to content

Commit 21dd85d

Browse files
committed
add runtime threshold for battery low
1 parent ac77d98 commit 21dd85d

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Kconfig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ config BATTERY_NO_MAPPING
3434

3535
endchoice
3636

37+
config BATTERY_LOW_RUNTIME_THRESHOLD
38+
int "Low battery runtime threshold (ms)"
39+
default 10800000
40+
help
41+
Trigger low battery when estimated runtime falls below threshold.
42+
If estimated runtime is not available, low battery will trigger under 10% estimated state of charge.
43+
3744
choice
3845
prompt "Status LED color mapping"
3946
default LED_TRI_COLOR
@@ -168,7 +175,7 @@ config USE_ACTIVE_TIMEOUT
168175
help
169176
Delay IMU wake up state or user shutdown during activity.
170177

171-
choice
178+
choice
172179
prompt "Activity timeout mode"
173180
default SLEEP_ON_ACTIVE_TIMEOUT
174181
depends on USE_ACTIVE_TIMEOUT

src/config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const char *config_settings_names[] = {
4949
"imu_timeout_ramp_max",
5050
"active_timeout_threshold",
5151
"active_timeout_delay",
52+
"battery_low_runtime_threshold"
5253
};
5354

5455
const bool config_0_settings_defaults[16] = {
@@ -133,6 +134,7 @@ const int32_t config_3_settings_defaults[16] = {
133134
#else
134135
900000,
135136
#endif
137+
CONFIG_BATTERY_LOW_RUNTIME_THRESHOLD,
136138
};
137139

138140
LOG_MODULE_REGISTER(config, LOG_LEVEL_INF);

src/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ enum config_3_settings_id {
6363
CONFIG_3_IMU_TIMEOUT_RAMP_MAX,
6464
CONFIG_3_ACTIVE_TIMEOUT_THRESHOLD,
6565
CONFIG_3_ACTIVE_TIMEOUT_DELAY,
66+
CONFIG_3_BATTERY_LOW_RUNTIME_THRESHOLD,
6667
CONFIG_3_SETTINGS_END
6768
};
6869

src/system/power.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,14 @@ static void power_thread(void)
521521
// will update average_pptt, and current_battery_pptt
522522
update_battery(battery_pptt);
523523

524-
if (battery_available && !battery_low && current_battery_pptt < 1000)
524+
// use estimated remaining runtime or pptt for battery_low
525+
uint64_t runtime = sys_get_battery_remaining_time_estimate();
526+
bool runtime_valid = runtime;
527+
bool runtime_low = k_ticks_to_us_floor64(runtime) < CONFIG_3_SETTINGS_READ(CONFIG_3_BATTERY_LOW_RUNTIME_THRESHOLD);
528+
bool pptt_low = current_battery_pptt < 1000;
529+
if (battery_available && !battery_low && (runtime_valid ? runtime_low : pptt_low))
525530
battery_low = true;
526-
else if (!battery_available || (battery_low && current_battery_pptt > 1000)) // hysteresis alrerady provided
531+
else if (!battery_available || (battery_low && (runtime_valid ? !runtime_low : !pptt_low))) // hysteresis already provided
527532
battery_low = false;
528533

529534
sys_update_battery_tracker_voltage(battery_mV, device_plugged);

0 commit comments

Comments
 (0)