feature-out some battery testing code in hosted mode

This commit is contained in:
bunnie 2025-05-07 23:10:04 +08:00
parent 231aff1f80
commit 399742a3d4

View file

@ -70,19 +70,26 @@ fn main() {
log::set_max_level(log::LevelFilter::Debug);
modals::tests::spawn_test();
}
use cramium_api::I2cApi;
let mut i2c = cram_hal_service::I2c::new();
use cramium_hal::axp2101::*;
let measurements = [("VBAT", REG_VBAT_H), ("VBUS", REG_VBUS_H), ("VSYS", REG_VSYS_H)];
let mut buf = [0u8, 0u8];
loop {
tt.sleep_ms(2_000).ok();
for (name, offset) in measurements {
i2c.i2c_read(AXP2101_DEV, offset, &mut buf, false).unwrap();
let v: u32 = (((buf[0] as u32) & 0x3F) << 8) | buf[1] as u32;
log::info!("{}: {:0.3}V", name, v as f32 / 1000.0);
i2c.i2c_read(AXP2101_DEV, REG_SOC, &mut buf[0..1], false).unwrap();
log::info!("SOC: {}%", buf[0]);
#[cfg(not(feature = "hosted-baosec"))]
{
use cramium_api::I2cApi;
let mut i2c = cram_hal_service::I2c::new();
use cramium_hal::axp2101::*;
let measurements = [("VBAT", REG_VBAT_H), ("VBUS", REG_VBUS_H), ("VSYS", REG_VSYS_H)];
let mut buf = [0u8, 0u8];
loop {
tt.sleep_ms(2_000).ok();
for (name, offset) in measurements {
i2c.i2c_read(AXP2101_DEV, offset, &mut buf, false).unwrap();
let v: u32 = (((buf[0] as u32) & 0x3F) << 8) | buf[1] as u32;
log::info!("{}: {:0.3}V", name, v as f32 / 1000.0);
i2c.i2c_read(AXP2101_DEV, REG_SOC, &mut buf[0..1], false).unwrap();
log::info!("SOC: {}%", buf[0]);
}
}
}
#[cfg(feature = "hosted-baosec")]
loop {
tt.sleep_ms(2_000).ok();
}
}