forked from M-Labs/thermostat
fix tec_i calculation
This commit is contained in:
parent
0bc0af7487
commit
28a71d34d7
|
@ -147,7 +147,7 @@ fn main() -> ! {
|
||||||
let dac_i = dac_feedback / Ohms(5.0);
|
let dac_i = dac_feedback / Ohms(5.0);
|
||||||
|
|
||||||
let itec = channels.read_itec(channel);
|
let itec = channels.read_itec(channel);
|
||||||
let tec_i = Amps((itec.0 - 1.5) / 8.0);
|
let tec_i = (itec - Volts(1.5)) / Ohms(0.4);
|
||||||
|
|
||||||
let state = channels.channel_state(channel);
|
let state = channels.channel_state(channel);
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
|
|
23
src/units.rs
23
src/units.rs
|
@ -1,10 +1,29 @@
|
||||||
use core::{
|
use core::{
|
||||||
fmt,
|
fmt,
|
||||||
ops::Div,
|
ops::{Add, Div, Sub},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
macro_rules! impl_add_sub {
|
||||||
|
($Type: ident) => {
|
||||||
|
impl Add<$Type> for $Type {
|
||||||
|
type Output = $Type;
|
||||||
|
fn add(self, rhs: $Type) -> $Type {
|
||||||
|
$Type(self.0 + rhs.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub<$Type> for $Type {
|
||||||
|
type Output = $Type;
|
||||||
|
fn sub(self, rhs: $Type) -> $Type {
|
||||||
|
$Type(self.0 - rhs.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||||
pub struct Volts(pub f64);
|
pub struct Volts(pub f64);
|
||||||
|
impl_add_sub!(Volts);
|
||||||
|
|
||||||
impl fmt::Display for Volts {
|
impl fmt::Display for Volts {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
@ -21,6 +40,7 @@ impl Div<Ohms> for Volts {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||||
pub struct Amps(pub f64);
|
pub struct Amps(pub f64);
|
||||||
|
impl_add_sub!(Amps);
|
||||||
|
|
||||||
impl fmt::Display for Amps {
|
impl fmt::Display for Amps {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
@ -29,6 +49,7 @@ impl fmt::Display for Amps {
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||||
pub struct Ohms(pub f64);
|
pub struct Ohms(pub f64);
|
||||||
|
impl_add_sub!(Ohms);
|
||||||
|
|
||||||
impl fmt::Display for Ohms {
|
impl fmt::Display for Ohms {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
|
Loading…
Reference in New Issue