kirdy/src/laser_diode/ld_drive.rs

88 lines
2.1 KiB
Rust

use miniconf::Miniconf;
use crate::laser_diode::current_sources::CurrentSource;
use core::marker::PhantomData;
use uom::si::{
electric_current::{milliampere},
f64::{ElectricPotential, ElectricCurrent, ElectricalResistance},
};
use uom::{si::{ISQ, SI, Quantity}, typenum::*};
// Volt / Ampere
pub type transimpedance_unit = Quantity<ISQ<P2, P1, N3, N2, Z0, Z0, Z0>, SI<f64>, f64>;
// Ampere / Volt
type transconductance_unit = Quantity<ISQ<N2, N1, P3, P2, Z0, Z0, Z0>, SI<f64>, f64>;
// Watt / Ampere
pub type i_to_power_unit = Quantity<ISQ<P2, P1, N3, N1, Z0, Z0, Z0>, SI<f64>, f64>;
impl Settings{
pub const R_SENSE: ElectricalResistance = ElectricalResistance {
dimension: PhantomData,
units: PhantomData,
value: 10.0,
};
pub const DAC_OUT_V_MAX: ElectricPotential = ElectricPotential {
dimension: PhantomData,
units: PhantomData,
value: 4.096,
};
// Unit: A/V
const PD_MON_TRANSCONDUCTANCE: transconductance_unit = transconductance_unit {
dimension: PhantomData,
units: PhantomData,
value: 0.001,
};
const LD_DRIVE_TRANSIMPEDANCE: transimpedance_unit = transimpedance_unit {
dimension: PhantomData,
units: PhantomData,
value: 10.0 / 0.75,
};
}
#[derive(Clone, Debug, Miniconf)]
pub struct Settings {
pub ld_drive_current: ElectricCurrent,
}
impl Default for Settings {
fn default() -> Self {
Self {
ld_drive_current: ElectricCurrent::new::<milliampere>(0.0),
}
}
}
pub struct LD_Drive{
ctrl: CurrentSource,
settings: Settings,
}
impl LD_Drive{
pub fn new(current_source: CurrentSource)-> Self{
LD_Drive {
ctrl: current_source,
settings: Settings::default()
}
}
pub fn power_up(&mut self){
self.ctrl.power_up();
}
pub fn power_down(&mut self){
self.ctrl.power_down();
}
pub fn ld_short(&mut self) {
self.ctrl.ld_short_enable();
}
pub fn ld_open(&mut self) {
self.ctrl.ld_short_disable();
}
}