aboutsummaryrefslogtreecommitdiff
path: root/hw/hank/emisar-d3aa/hwdef.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2024-03-26 04:31:04 -0600
committerSelene ToyKeeper2024-03-26 04:31:04 -0600
commit39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413 (patch)
treefd29c395b561959508e9af3d68bd9a0bfb6cd9a2 /hw/hank/emisar-d3aa/hwdef.c
parentd3aa: got weak battery detection actually working, (diff)
downloadanduril-39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413.tar.gz
anduril-39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413.tar.bz2
anduril-39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413.zip
weak battery detection: use different thresholds for AA and Li-Ion
(also, fixed bug where a totally empty li-ion didn't get limited)
Diffstat (limited to '')
-rw-r--r--hw/hank/emisar-d3aa/hwdef.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/hw/hank/emisar-d3aa/hwdef.c b/hw/hank/emisar-d3aa/hwdef.c
index d6cb2fd..8aaa893 100644
--- a/hw/hank/emisar-d3aa/hwdef.c
+++ b/hw/hank/emisar-d3aa/hwdef.c
@@ -138,22 +138,26 @@ void detect_weak_battery() {
//resting = voltage_raw2cooked(adc_smooth[0]); // probably not settled yet
resting = quick_volt_measurement();
+ // set thresholds per cell type
+ uint8_t sag_limit, crit_voltage;
+ if (resting > DUAL_VOLTAGE_FLOOR) {
+ sag_limit = WEAK_BATTERY_SAG_THRESHOLD_LIION;
+ crit_voltage = VOLTAGE_LOW;
+ } else {
+ sag_limit = WEAK_BATTERY_SAG_THRESHOLD_AA;
+ crit_voltage = DUAL_VOLTAGE_LOW_LOW;
+ }
+
// progressively turn up the power until sag threshold is hit,
// or critical voltage, or max testing level is reached
for (uint8_t l=1; l<WEAK_BATTERY_TEST_MAX_LEVEL; l++) {
set_level(l);
loaded = quick_volt_measurement();
int16_t sag = resting - loaded;
- if (
- // AA/NiMH critical voltage
- (loaded <= DUAL_VOLTAGE_LOW_LOW) ||
- // weak battery chemistry, can't handle much power
- (sag > WEAK_BATTERY_SAG_THRESHOLD) ||
- // Li-ion critical voltage
- ((resting > VOLTAGE_LOW) && (loaded < VOLTAGE_LOW))
- ) {
- ramp_level_hard_limit = l;
- break;
+ if ( (loaded <= crit_voltage) || (sag > sag_limit) ) {
+ // battery empty or weak
+ ramp_level_hard_limit = l;
+ break;
}
}
set_level(0);