ccs: tristar: remove useless Option around scaling

This commit is contained in:
Alex Janka 2025-01-09 11:23:03 +11:00
parent 9d8b4b23b1
commit 20a7ad6ddd

View file

@ -55,9 +55,9 @@ pub struct Tristar {
scaling: Option<Scaling>,
}
#[derive(Default, Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub struct TristarState {
scaling: Option<Scaling>,
scaling: Scaling,
battery_voltage: f64,
target_voltage: f64,
input_current: f64,
@ -86,7 +86,7 @@ impl TristarState {
fn from_ram(ram: &[u16]) -> Self {
let scaling = Scaling::from(ram);
Self {
scaling: Some(scaling),
scaling,
battery_voltage: scaling.get_voltage(ram[TristarRamAddress::AdcVbFMed]),
target_voltage: scaling.get_voltage(ram[TristarRamAddress::VbRef]),
input_current: scaling.get_current(ram[TristarRamAddress::AdcIaFShadow]),
@ -266,6 +266,7 @@ impl Tristar {
let modbus_serial = tokio_serial::SerialStream::open(
&tokio_serial::new(port, *baud_rate).timeout(std::time::Duration::from_secs(3)),
)?;
tokio_modbus::client::rtu::attach_slave(modbus_serial, slave)
}
crate::config::Transport::Tcp { ip, port } => {
@ -287,7 +288,7 @@ impl Tristar {
pub async fn refresh(&mut self) -> eyre::Result<crate::controller::CommonData> {
let new_state = self.get_data().await?;
self.scaling = new_state.scaling;
self.scaling = Some(new_state.scaling);
self.consecutive_errors = 0;
BATTERY_VOLTAGE
.with_label_values(&[&self.friendly_name])