WIP Add battery level readout and publish on BLE
TODO: show on display when low battery TODO: ADC readout is not plausible
This commit is contained in:
parent
dc54b55230
commit
0b055900cf
4 changed files with 189 additions and 4 deletions
23
src/main.rs
23
src/main.rs
|
|
@ -59,7 +59,9 @@ mod screen;
|
|||
#[cfg(feature = "gnss_ubx")]
|
||||
mod ubx;
|
||||
mod util;
|
||||
mod xiao;
|
||||
|
||||
const BAT_UPDATE_INTERVAL: esp_hal::time::Duration = esp_hal::time::Duration::from_secs(30);
|
||||
const WIFI_CHANNEL: radio::Channel = 180;
|
||||
const WIFI_TXPOWER: i8 = 10; // dBm, 2..20
|
||||
#[cfg(feature = "spat")]
|
||||
|
|
@ -144,6 +146,9 @@ async fn main(spawner: Spawner) -> ! {
|
|||
|
||||
info!("Embassy initialized!");
|
||||
|
||||
// Setup battery voltage readout (GPIO6 as input and GPIO26 as enable)
|
||||
let mut battery = xiao::Battery::new(peripherals.ADC1, peripherals.GPIO6, peripherals.GPIO26);
|
||||
|
||||
// Setup ST7789 screen
|
||||
// SCL: D8/ GPIO8 (SPI_SCK)
|
||||
// SDA: D10/ GPIO10 (SPI_MOSI)
|
||||
|
|
@ -284,6 +289,13 @@ async fn main(spawner: Spawner) -> ! {
|
|||
#[cfg(feature = "_gnss")]
|
||||
info!("GNSS task started, waiting for GNSS fix...");
|
||||
|
||||
// Setup main loop
|
||||
let (bat_percent, bat_millivolt) = battery.read();
|
||||
log::info!("Battery: {bat_millivolt} mV, {bat_percent} %");
|
||||
#[cfg(feature = "ble")]
|
||||
ble::set(ble::BleSendable::BatteryLevel(bat_percent));
|
||||
let mut last_bat_update = esp_hal::time::Instant::now();
|
||||
|
||||
#[cfg(any(feature = "cam_tx", feature = "uart"))]
|
||||
let (mut seq_no, mac_bytes) = {
|
||||
// unwrap is fine since [`esp_hal::efuse::MacAddress`] is just an `[u8; 6]`
|
||||
|
|
@ -626,6 +638,17 @@ async fn main(spawner: Spawner) -> ! {
|
|||
|
||||
// maintenance
|
||||
state.prune();
|
||||
|
||||
let cpu_now = esp_hal::time::Instant::now();
|
||||
if last_bat_update + BAT_UPDATE_INTERVAL < cpu_now {
|
||||
let (bat_percent, bat_millivolt) = battery.read();
|
||||
log::info!("Battery: {bat_millivolt} mV, {bat_percent} %");
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
ble::set(ble::BleSendable::BatteryLevel(bat_percent));
|
||||
|
||||
last_bat_update = cpu_now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue