Log target voltage (Vreg)
This commit is contained in:
parent
dceefffd45
commit
c14454d53c
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2262,7 +2262,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tesla-charge-controller"
|
name = "tesla-charge-controller"
|
||||||
version = "0.1.15"
|
version = "0.1.16"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-channel",
|
"async-channel",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tesla-charge-controller"
|
name = "tesla-charge-controller"
|
||||||
version = "0.1.15"
|
version = "0.1.16"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MITNFA"
|
license = "MITNFA"
|
||||||
description = "Controls Tesla charge rate based on solar charge data"
|
description = "Controls Tesla charge rate based on solar charge data"
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub struct Pli {
|
||||||
pub state: Arc<RwLock<PlState>>,
|
pub state: Arc<RwLock<PlState>>,
|
||||||
port: Box<dyn SerialPort>,
|
port: Box<dyn SerialPort>,
|
||||||
voltage_gauge: Gauge,
|
voltage_gauge: Gauge,
|
||||||
|
target_voltage_gauge: Gauge,
|
||||||
duty_cycle: Gauge,
|
duty_cycle: Gauge,
|
||||||
internal_charge_current: Gauge,
|
internal_charge_current: Gauge,
|
||||||
internal_load_current: Gauge,
|
internal_load_current: Gauge,
|
||||||
|
@ -23,6 +24,7 @@ pub struct Pli {
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
pub struct PlState {
|
pub struct PlState {
|
||||||
pub battery_voltage: f64,
|
pub battery_voltage: f64,
|
||||||
|
pub target_voltage: f64,
|
||||||
pub duty_cycle: f64,
|
pub duty_cycle: f64,
|
||||||
pub internal_charge_current: f64,
|
pub internal_charge_current: f64,
|
||||||
pub internal_load_current: f64,
|
pub internal_load_current: f64,
|
||||||
|
@ -33,6 +35,7 @@ impl Default for PlState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
battery_voltage: Default::default(),
|
battery_voltage: Default::default(),
|
||||||
|
target_voltage: Default::default(),
|
||||||
duty_cycle: Default::default(),
|
duty_cycle: Default::default(),
|
||||||
internal_charge_current: Default::default(),
|
internal_charge_current: Default::default(),
|
||||||
internal_load_current: Default::default(),
|
internal_load_current: Default::default(),
|
||||||
|
@ -126,6 +129,8 @@ impl Pli {
|
||||||
|
|
||||||
describe_gauge!("pl_battery_voltage", "Battery voltage");
|
describe_gauge!("pl_battery_voltage", "Battery voltage");
|
||||||
let voltage_gauge = gauge!("pl_battery_voltage");
|
let voltage_gauge = gauge!("pl_battery_voltage");
|
||||||
|
describe_gauge!("pl_target_voltage", "Target voltage");
|
||||||
|
let target_voltage_gauge = gauge!("pl_target_voltage");
|
||||||
describe_gauge!("pl_duty_cycle", "Duty cycle");
|
describe_gauge!("pl_duty_cycle", "Duty cycle");
|
||||||
let duty_cycle = gauge!("pl_duty_cycle");
|
let duty_cycle = gauge!("pl_duty_cycle");
|
||||||
describe_gauge!("pl_internal_charge_current", "Internal charge current");
|
describe_gauge!("pl_internal_charge_current", "Internal charge current");
|
||||||
|
@ -137,6 +142,7 @@ impl Pli {
|
||||||
state: Arc::new(RwLock::new(Default::default())),
|
state: Arc::new(RwLock::new(Default::default())),
|
||||||
port,
|
port,
|
||||||
voltage_gauge,
|
voltage_gauge,
|
||||||
|
target_voltage_gauge,
|
||||||
duty_cycle,
|
duty_cycle,
|
||||||
internal_charge_current,
|
internal_charge_current,
|
||||||
internal_load_current,
|
internal_load_current,
|
||||||
|
@ -147,6 +153,7 @@ impl Pli {
|
||||||
pub fn refresh(&mut self) {
|
pub fn refresh(&mut self) {
|
||||||
if let Ok(new_state) = self.read_state() {
|
if let Ok(new_state) = self.read_state() {
|
||||||
self.voltage_gauge.set(new_state.battery_voltage);
|
self.voltage_gauge.set(new_state.battery_voltage);
|
||||||
|
self.target_voltage_gauge.set(new_state.target_voltage);
|
||||||
self.duty_cycle.set(new_state.duty_cycle);
|
self.duty_cycle.set(new_state.duty_cycle);
|
||||||
self.internal_charge_current
|
self.internal_charge_current
|
||||||
.set(new_state.internal_charge_current);
|
.set(new_state.internal_charge_current);
|
||||||
|
@ -181,6 +188,7 @@ impl Pli {
|
||||||
fn read_state(&mut self) -> anyhow::Result<PlState> {
|
fn read_state(&mut self) -> anyhow::Result<PlState> {
|
||||||
Ok(PlState {
|
Ok(PlState {
|
||||||
battery_voltage: (self.read_ram(PlRamAddress::Batv)? as f64) * (4. / 10.),
|
battery_voltage: (self.read_ram(PlRamAddress::Batv)? as f64) * (4. / 10.),
|
||||||
|
target_voltage: (self.read_ram(PlRamAddress::Vreg)? as f64) * (4. / 10.),
|
||||||
duty_cycle: (self.read_ram(PlRamAddress::Dutycyc)? as f64) / 255.,
|
duty_cycle: (self.read_ram(PlRamAddress::Dutycyc)? as f64) / 255.,
|
||||||
internal_charge_current: (self.read_ram(PlRamAddress::Cint)? as f64) * (4. / 10.),
|
internal_charge_current: (self.read_ram(PlRamAddress::Cint)? as f64) * (4. / 10.),
|
||||||
internal_load_current: (self.read_ram(PlRamAddress::Lint)? as f64) * (4. / 10.),
|
internal_load_current: (self.read_ram(PlRamAddress::Lint)? as f64) * (4. / 10.),
|
||||||
|
@ -218,6 +226,7 @@ enum PlRamAddress {
|
||||||
Dutycyc,
|
Dutycyc,
|
||||||
Batv,
|
Batv,
|
||||||
Rstate,
|
Rstate,
|
||||||
|
Vreg,
|
||||||
Cint,
|
Cint,
|
||||||
Lint,
|
Lint,
|
||||||
}
|
}
|
||||||
|
@ -228,6 +237,7 @@ impl From<PlRamAddress> for u8 {
|
||||||
PlRamAddress::Dutycyc => 39,
|
PlRamAddress::Dutycyc => 39,
|
||||||
PlRamAddress::Batv => 50,
|
PlRamAddress::Batv => 50,
|
||||||
PlRamAddress::Rstate => 101,
|
PlRamAddress::Rstate => 101,
|
||||||
|
PlRamAddress::Vreg => 105,
|
||||||
PlRamAddress::Cint => 213,
|
PlRamAddress::Cint => 213,
|
||||||
PlRamAddress::Lint => 217,
|
PlRamAddress::Lint => 217,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue