From 590ba8171c4fea78bb5f1dfa9ed9642868acf2bd Mon Sep 17 00:00:00 2001 From: linuswck Date: Tue, 9 Jan 2024 15:53:24 +0800 Subject: [PATCH] Add high level ld_drive mod - Use current_source driver to interface with the board --- src/laser_diode/ld_drive.rs | 51 +++++++++++++++++++++++++++++++++++++ src/laser_diode/mod.rs | 3 ++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/laser_diode/ld_drive.rs diff --git a/src/laser_diode/ld_drive.rs b/src/laser_diode/ld_drive.rs new file mode 100644 index 0000000..d6643d2 --- /dev/null +++ b/src/laser_diode/ld_drive.rs @@ -0,0 +1,51 @@ +use miniconf::Miniconf; +use crate::laser_diode::current_sources::CurrentSource; + +use uom::si::{ + electric_current::{milliampere}, + f64::ElectricCurrent, +}; + +#[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::(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(); + } + +} \ No newline at end of file diff --git a/src/laser_diode/mod.rs b/src/laser_diode/mod.rs index dfe83da..4b01d25 100644 --- a/src/laser_diode/mod.rs +++ b/src/laser_diode/mod.rs @@ -1,2 +1,3 @@ pub mod current_sources; -pub mod max5719; \ No newline at end of file +pub mod max5719; +pub mod ld_drive; \ No newline at end of file