Merge branch 'develop' of ssh://git.mannheim.ccc.de:1337/C3MA/PlantCtrl into develop

This commit is contained in:
2026-03-15 20:02:05 +01:00
4 changed files with 60 additions and 19 deletions

View File

@@ -1,11 +1,13 @@
use crate::hal::Box;
use crate::fat_error::{FatError, FatResult};
use crate::hal::Box;
use async_trait::async_trait;
use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use esp_hal::i2c::master::I2c;
use esp_hal::Blocking;
use lib_bms_protocol::{BatteryState as bstate, BmsReadable, Config, FirmwareVersion, ProtocolVersion};
use lib_bms_protocol::{
BatteryState as bstate, BmsReadable, Config, FirmwareVersion, ProtocolVersion,
};
use serde::Serialize;
#[async_trait(?Send)]
@@ -59,18 +61,17 @@ impl BatteryInteraction for NoBatteryMonitor {
pub struct WchI2cSlave {}
pub struct WCHI2CSlave<'a> {
pub(crate) i2c: I2cDevice<'a, CriticalSectionRawMutex, I2c<'a, Blocking>>
pub(crate) i2c: I2cDevice<'a, CriticalSectionRawMutex, I2c<'a, Blocking>>,
}
#[async_trait(?Send)]
impl BatteryInteraction for WCHI2CSlave<'_> {
async fn get_state(&mut self) -> FatResult<BatteryState> {
let state = bstate::read_from_i2c(&mut self.i2c)?;
let config = Config::read_from_i2c(&mut self.i2c)?;
let state_of_charge = (state.remaining_capacity_mah * 100 / state.lifetime_capacity_mah) as u8;
let state_of_charge =
(state.remaining_capacity_mah * 100 / state.lifetime_capacity_mah) as u8;
let state_of_health = state.lifetime_capacity_mah / config.capacity_mah * 100;
Ok(BatteryState::Info(BatteryInfo {
@@ -95,4 +96,4 @@ impl BatteryInteraction for WCHI2CSlave<'_> {
async fn reset(&mut self) -> FatResult<()> {
todo!()
}
}
}

View File

@@ -186,6 +186,8 @@ pub(crate) async fn create_v4(
let pump_device = I2cDevice::new(I2C_DRIVER.get().await);
let mut pump_expander = Pca9535Immediate::new(pump_device, 32);
for pin in 0..8 {
let _ = pump_expander.pin_set_low(GPIOBank::Bank0, pin);
let _ = pump_expander.pin_set_low(GPIOBank::Bank1, pin);
let _ = pump_expander.pin_into_output(GPIOBank::Bank0, pin);
let _ = pump_expander.pin_into_output(GPIOBank::Bank1, pin);
let _ = pump_expander.pin_set_low(GPIOBank::Bank0, pin);