Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions platform/platform-common/src/mock/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,34 @@ use static_cell::StaticCell;

/// The fuel gauge, behind a mutex so the service and the driving task can share it.
type FuelGauge = Mutex<GlobalRawMutex, MockFuelGauge>;
/// A single registered fuel gauge, which becomes battery `0`.
type Reg = bs::ArrayRegistration<'static, FuelGauge, 1>;
/// Two registered fuel gauges: battery `0` is a 3S pack, battery `1` a 2S pack.
type Reg = bs::ArrayRegistration<'static, FuelGauge, 2>;
pub type BatteryService = bs::Service<'static, Reg>;

pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService {
info!("Initializing battery service...");

static FUEL_GAUGE: StaticCell<FuelGauge> = StaticCell::new();
let fuel_gauge: &'static FuelGauge = FUEL_GAUGE.init(Mutex::new(MockFuelGauge::new()));
static FUEL_GAUGE_0: StaticCell<FuelGauge> = StaticCell::new();
let fuel_gauge_0: &'static FuelGauge = FUEL_GAUGE_0.init(Mutex::new(MockFuelGauge::new()));

static FUEL_GAUGE_1: StaticCell<FuelGauge> = StaticCell::new();
let fuel_gauge_1: &'static FuelGauge = FUEL_GAUGE_1.init(Mutex::new(MockFuelGauge::new_2s()));

let service = bs::Service::new(bs::ArrayRegistration {
fuel_gauges: [fuel_gauge],
fuel_gauges: [fuel_gauge_0, fuel_gauge_1],
});

bs::mock::init_state_machine(fuel_gauge)
.await
.expect("Failed to initialize battery state machine");
spawner.spawn(update_data_task(fuel_gauge).expect("Failed to spawn battery update data task"));
for fuel_gauge in [fuel_gauge_0, fuel_gauge_1] {
bs::mock::init_state_machine(fuel_gauge)
.await
.expect("Failed to initialize battery state machine");
spawner.spawn(update_data_task(fuel_gauge).expect("Failed to spawn battery update data task"));
}
Comment on lines +28 to +33

service
}

#[embassy_executor::task]
#[embassy_executor::task(pool_size = 2)]
pub async fn update_data_task(fuel_gauge: &'static FuelGauge) -> ! {
let mut failures: u32 = 0;
let mut count: usize = 0;
Expand Down
Loading