Skip to content

Commit

Permalink
charging: improve LED behavior
Browse files Browse the repository at this point in the history
Add threshold voltage above which a charging error
is acceptable. Also delay charging LED driving by 7 seconds
after start.
  • Loading branch information
surban committed Jul 3, 2024
1 parent d4240e9 commit c4d8ef8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions openemc-firmware/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ pub trait Board {
/// Battery voltage in mV that is used for switching charging LED from blinking to steady.
const CHARGING_LED_END_VOLTAGE: u32 = 10000;

/// Battery voltage in mV that is used for switching charging LED from blinking to steady,
/// when charging current is below [`CHARGING_LED_MIN_CURRENT`](Self::CHARGING_LED_MIN_CURRENT).
const CHARGING_LED_NOT_CHARGING_ACCEPTABLE_VOLTAGE: u32 = Self::CHARGING_LED_END_VOLTAGE;

/// Battery current in mA that is used to indicate charging error if fallen below.
const CHARGING_LED_MIN_CURRENT: i32 = 0;

Expand Down
11 changes: 7 additions & 4 deletions openemc-firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ mod app {
};

// Drive charging LED.
unwrap!(charge_led::spawn());
unwrap!(charge_led::spawn_after(7u64.secs()));

// Call board-specific periodic function for first time.
unwrap!(board_periodic::spawn());
Expand Down Expand Up @@ -1239,10 +1239,13 @@ mod app {
let (should_charge, charging_error) = battery
.as_ref()
.map(|b| {
let voltage_mv = b.voltage_mv.unwrap_or_default();
let current_ma = b.current_ma.unwrap_or_default();
(
b.voltage_mv.unwrap_or_default() < ThisBoard::CHARGING_LED_END_VOLTAGE,
!b.charging.is_charging()
|| b.current_ma.unwrap_or_default() < ThisBoard::CHARGING_LED_MIN_CURRENT,
voltage_mv < ThisBoard::CHARGING_LED_END_VOLTAGE
&& !(voltage_mv >= ThisBoard::CHARGING_LED_NOT_CHARGING_ACCEPTABLE_VOLTAGE
&& current_ma < ThisBoard::CHARGING_LED_MIN_CURRENT),
!b.charging.is_charging() || current_ma < ThisBoard::CHARGING_LED_MIN_CURRENT,
)
})
.unwrap_or_default();
Expand Down

0 comments on commit c4d8ef8

Please sign in to comment.