forked from M-Labs/thermostat
fix tec_i calculation, add units::{Amps, Ohms}
This commit is contained in:
parent
fb5c7a84e9
commit
38a220ce4e
15
src/main.rs
15
src/main.rs
|
@ -43,6 +43,7 @@ mod command_parser;
|
|||
use command_parser::{Command, ShowCommand, PwmPin};
|
||||
mod timer;
|
||||
mod units;
|
||||
use units::{Amps, Ohms};
|
||||
mod pid;
|
||||
mod steinhart_hart;
|
||||
mod channels;
|
||||
|
@ -143,17 +144,17 @@ fn main() -> ! {
|
|||
for channel in 0..CHANNELS {
|
||||
if let Some(adc_data) = channels.channel_state(channel).adc_data {
|
||||
let dac_loopback = channels.read_dac_loopback(channel);
|
||||
let dac_i = dac_loopback.clone() / Ohms(5.0);
|
||||
|
||||
let itec = channels.read_itec(channel);
|
||||
let itec_u = itec.0;
|
||||
let tec_u = (itec_u - 1.5) / 8.0;
|
||||
let tec_r = 5.0;
|
||||
let tec_i = tec_u / tec_r;
|
||||
let tec_i = Amps((itec.0 - 1.5) / 8.0);
|
||||
|
||||
let state = channels.channel_state(channel);
|
||||
let _ = writeln!(
|
||||
socket, "t={} raw{}=0x{:06X} dac_loopback={} itec={} tec={:.3}V/{:.3}A",
|
||||
socket, "t={} raw{}=0x{:06X} dac_loopback={}/{} itec={} tec={}",
|
||||
state.adc_time, channel, adc_data,
|
||||
dac_loopback, itec,
|
||||
tec_u, tec_i,
|
||||
dac_loopback, dac_i,
|
||||
itec, tec_i,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
29
src/units.rs
29
src/units.rs
|
@ -1,4 +1,7 @@
|
|||
use core::fmt;
|
||||
use core::{
|
||||
fmt,
|
||||
ops::Div,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd)]
|
||||
pub struct Volts(pub f64);
|
||||
|
@ -8,3 +11,27 @@ impl fmt::Display for Volts {
|
|||
write!(f, "{:.3}V", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<Ohms> for Volts {
|
||||
type Output = Amps;
|
||||
fn div(self, rhs: Ohms) -> Amps {
|
||||
Amps(self.0 / rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd)]
|
||||
pub struct Amps(pub f64);
|
||||
|
||||
impl fmt::Display for Amps {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:.3}A", self.0)
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd)]
|
||||
pub struct Ohms(pub f64);
|
||||
|
||||
impl fmt::Display for Ohms {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:.3}Ω", self.0)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue