diff options
author | iximeow <me@iximeow.net> | 2020-10-19 00:01:18 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2020-10-19 00:01:18 -0700 |
commit | af13b8c588ca7b5e4f761c4bd3baf03807e7d61b (patch) | |
tree | 0cf91a3e409e34cf059cd9f3c3673f4ce5d28870 /src | |
parent | c3f1887b4e9b1a4eaf42b51bcbdbe92e888f96d7 (diff) |
dewarn
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 97 | ||||
-rw-r--r-- | src/qhyccd/mod.rs | 44 |
2 files changed, 50 insertions, 91 deletions
diff --git a/src/main.rs b/src/main.rs index c892d97..e874594 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use crossbeam_channel::{Sender, Receiver}; use crossbeam_channel::unbounded; use std::time::Duration; -use std::time::Instant; +// use std::time::Instant; use crate::asicam::ASICamera2::{ControlType, ImageType}; use crate::asicam::Camera; @@ -60,13 +60,12 @@ fn record_image(data: &[u8], dimensions: Dimensions, target: &'static str, image println!("image written!"); println!(".. writing raw"); let raw_path = format!("{}_{}.raw", target, image_id); - let raw_dest = Path::new(&raw_path); + // let raw_dest = Path::new(&raw_path); // let mut file = File::create(raw_dest).unwrap(); // file.write(data); } fn main() { - let test = true; println!("Doing qhy..."); let (image_writer, image_reader) = unbounded(); let (frame_sender, free_frames) = unbounded(); @@ -129,17 +128,18 @@ fn main() { if scale_factor != 1 { let downscaled = downscale(data.as_slice(), dimensions.width, dimensions.height, scale_factor); let image_info = show_image::ImageInfo::mono8(dimensions.width as usize / scale_factor as usize, dimensions.height as usize / scale_factor as usize); - window.set_image(&(downscaled.as_slice(), image_info), "image-001"); + let _ = window.set_image(&(downscaled.as_slice(), image_info), "image-001"); } else { let image_info = show_image::ImageInfo::mono8(dimensions.width as usize, dimensions.height as usize); - window.set_image(&(data.as_slice(), image_info), "image-001"); + let _ = window.set_image(&(data.as_slice(), image_info), "image-001"); } record_image(data.as_slice(), dimensions, target, image_id, &properties); println!("pretend i wrote image {}_{}", target, image_id); frame_sender.send(data).unwrap(); } - Err(RecvError) => { + Err(recv_error) => { + eprintln!("recv error: {:?}", recv_error); // something in the application has crashed. time 2 die return; } @@ -155,7 +155,7 @@ fn main() { } #[derive(Debug, Copy, Clone)] -struct Dimensions { +pub struct Dimensions { width: u32, height: u32, bpp: u8, @@ -169,7 +169,7 @@ impl Dimensions { } #[derive(Debug)] -struct Properties { +pub struct Properties { pub device: &'static str, pub exposure_ms: u32, pub gain: u16, @@ -206,10 +206,11 @@ enum ImageWriter { fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<Vec<u8>>, image_writer: Sender<ImageInfo>) { use crate::qhyccd::Control; println!("Operating on qhy camera ... or i'll die trying"); - let (mut camera_rx, mut camera_tx) = qhyccd::connect(0).unwrap(); + let (camera_rx, camera_tx) = qhyccd::connect(0).unwrap(); let mut image_id = 0u32; let mut settings_copy = qhyccd::Settings::default(); + eprintln!("settings initialized: {:?}", settings_copy); // qhy376c settings camera_tx.send(QHYMessage::SetControl(Control::Exposure, 20000.0 * 1000.0)).unwrap(); @@ -245,9 +246,9 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V camera_tx.send(QHYMessage::BeginCapture(None)).unwrap(); - let LAPSE_PERIOD = Duration::from_millis(0); + let _LAPSE_PERIOD = Duration::from_millis(0); - let mut capture_start = Instant::now().checked_sub(Duration::from_millis(10)).unwrap().checked_sub(LAPSE_PERIOD).unwrap();; + // let capture_start = Instant::now().checked_sub(Duration::from_millis(10)).unwrap().checked_sub(LAPSE_PERIOD).unwrap(); loop { /* if capture_start.elapsed() > LAPSE_PERIOD { @@ -262,7 +263,8 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V Ok(buffer) => { camera_tx.send(QHYMessage::FrameAvailable(buffer)).unwrap(); }, - Err(RecvError) => { + Err(recv_error) => { + eprintln!("recv error: {:?}", recv_error); // disconnected. nothing we can do but to.. return; } @@ -282,19 +284,21 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V } Ok(QHYResponse::UpdatedSettings(settings)) => { settings_copy = settings; + eprintln!("settings updated: {:?}", settings_copy); } Ok(QHYResponse::Data(data, dimensions, properties)) => { image_writer.send(ImageInfo { data, dimensions, target, image_id: image_id, properties}).unwrap(); // images.log(target, image_id, settings_copy); image_id += 1; if Some(image_id) == count { - camera_tx.send(QHYMessage::Shutdown); + camera_tx.send(QHYMessage::Shutdown).unwrap(); } } Ok(QHYResponse::DroppedFrame) => { println!("Dropped frame..."); } - Err(RecvError) => { + Err(e) => { + eprintln!("recv error: {:?}", e); // camera is closed. hopefully it just shut down? but maybe crashed!! return; } @@ -303,46 +307,13 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V default(Duration::from_millis(2000)) => { camera_tx.send( QHYMessage::QueryControl(Control::CurTemp) - ); + ).unwrap(); } } } - /* - let t = std::thread::spawn(move || { - let mut camera = qhyccd::acquire(0).unwrap(); - camera.set_defaults().unwrap(); - camera.set_exposure_ms(400).unwrap(); - // camera.set_param(Control::Exposure, 10.0).unwrap(); - camera.set_param(Control::Gain, 4000.0); //.unwrap(); - camera.set_param(Control::Offset, 00.0).unwrap(); - // camera.set_param(Control::USBTraffic, 50.0).unwrap(); - // camera.set_param(Control::ManulPwm, 0.0).unwrap(); - // camera.set_target_temp(0.0).unwrap(); - camera.set_param(Control::Cooler, -25.0).unwrap(); - // camera.set_roi(0, 0, 1920 * 2, 1080 * 2).unwrap(); - println!("Gain: {:?}", camera.get_param_limits(Control::ManulPwm)); - println!("cur pwm ???: {}", camera.get_param(Control::CurPWM)); - println!("current temp: {}", camera.get_param(Control::CurTemp)); - // camera.set_param(Control::CONTROL_WBR, 2750.0).unwrap(); - // camera.set_param(Control::CONTROL_WBG, 2500.0).unwrap(); - // camera.set_param(Control::CONTROL_WBB, 3000.0).unwrap(); - // camera.set_bin_mode(2).unwrap(); - if !test { - let object = "veil"; - for i in 0..10 { - camera.take_image(&format!("{}_{}.png", object, i));//, i)); - } - } else { - camera.take_image("qhy_test_2.png").unwrap(); - println!("exposing: {:x}", camera.get_param(Control::IS_EXPOSING_DONE) as u64); - } - camera.release().unwrap(); - }); - t.join(); - */ } -fn operate_asi(test: bool) { +fn operate_asi(_test: bool) { println!("Operating on asi camera ... or i'll die trying"); let mut camera = asicam::acquire(0).unwrap(); @@ -352,18 +323,6 @@ fn operate_asi(test: bool) { std::thread::sleep(std::time::Duration::from_millis(500)); println!("Camera temperature is currently {:?}", camera.get_control_value(ControlType::Temperature).unwrap()); - /* - for exposure in [2000, 5000, 10000, 30000].iter() { - camera.set_control_value(ControlType::Exposure, *exposure).unwrap(); - for gain in [450, 375, 325, 250, 200].iter() { - camera.set_control_value(ControlType::Gain, *gain).unwrap(); - for offset in [100, 80, 60, 40, 20, 0].iter() { - camera.set_control_value(ControlType::Offset, *offset).unwrap(); - take_calibration_images(&camera, 1, &format!("roof_gain_{:03}_offset_{:03}_exposure_{:06}", gain, offset, exposure)); - } - } - } - */ camera.set_exposure_ms(30000).unwrap(); // camera.set_control_value(ControlType::Exposure, 70000000).unwrap(); camera.set_control_value(ControlType::Gain, 250).unwrap(); @@ -375,22 +334,6 @@ fn operate_asi(test: bool) { println!("Camera temperature is currently {:?}", camera.get_control_value(ControlType::Temperature).unwrap()); camera.take_image(&format!("ngc7380_{}.png", i)).unwrap(); } -// take_calibration_images(&camera, 40, "dark_gain_350_exposure_45000"); - /* - for exposure in [1000 * 1000 * 10].iter() { - camera.set_control_value(ControlType::Exposure, *exposure).unwrap(); - for gain in [450, 375, 325, 250, 200].iter() { - camera.set_control_value(ControlType::Gain, *gain).unwrap(); - for offset in [100, 80, 70, 60, 40, 0].iter() { - camera.set_control_value(ControlType::Offset, *offset).unwrap(); - take_calibration_images( - &camera, - 30, - &format!("images/gain_{:03}_offset_{:03}_exposure_{:06}", gain, offset, exposure)); - } - } - } - */ println!("Done!"); } diff --git a/src/qhyccd/mod.rs b/src/qhyccd/mod.rs index ac590af..bda6822 100644 --- a/src/qhyccd/mod.rs +++ b/src/qhyccd/mod.rs @@ -4,18 +4,12 @@ pub use self::QHYCCDCam::Control; use self::QHYCCDCam::*; -use std::alloc::{alloc, dealloc, Layout}; -use std::collections::HashMap; use std::ffi::CStr; use std::os; -use std::fs::File; -use std::io::BufWriter; -use std::path::Path; use std::time::Duration; use crossbeam_channel::unbounded; use crossbeam_channel::{Sender, Receiver, TryRecvError}; -use crossbeam_channel::select; use png::HasParameters; @@ -29,6 +23,15 @@ pub struct Camera { frame_size: usize, handle: *mut os::raw::c_void, settings: Settings, + parameters: Parameters, +} + +#[derive(Debug)] +pub struct Parameters { + bpp: u32, + pixel_dimensions: (f64, f64), + image_dimensions: (u32, u32), + chip_dimensions: (f64, f64), } #[derive(Debug, Default, Copy, Clone)] @@ -115,7 +118,6 @@ static mut INITIALIZED: bool = false; pub fn fix_channels_and_endianness(dataslice: &mut [u8]) { for i in 0..(dataslice.len() / 6) { let (b_low, b_high) = (dataslice[i * 6], dataslice[i * 6 + 1]); - let tmp2 = dataslice[i * 6 + 1]; dataslice[i * 6 + 1] = dataslice[i * 6 + 4]; dataslice[i * 6] = dataslice[i * 6 + 5]; dataslice[i * 6 + 4] = b_high; @@ -164,6 +166,7 @@ pub fn connect(camera_idx: i32) -> Result<(Receiver<QHYResponse>, Sender<QHYMess let mut camera = match acquire(camera_idx) { Ok(camera) => camera, Err(e) => { + eprintln!("camera setup error: {:?}", e); response_sender.send(QHYResponse::InitializationError).unwrap(); return; }, @@ -334,12 +337,27 @@ fn acquire(camera_idx: i32) -> Result<Camera> { check(QHYCCDCam::SetQHYCCDStreamMode(handle, 0))?; // 0 means single frame mode... check(QHYCCDCam::InitQHYCCD(handle))?; check(QHYCCDCam::CancelQHYCCDExposingAndReadout(handle))?; - Ok(Camera { + let mut camera = Camera { buffer: vec![], frame_size: 0, handle: handle, - settings: Settings::default() - }) + settings: Settings::default(), + parameters: Parameters { + chip_dimensions: (0.0, 0.0), + image_dimensions: (0, 0), + pixel_dimensions: (0.0, 0.0), + bpp: 0, + } + }; + let (chip_dimensions, image_dimensions, pixel_dimensions, bpp) = camera.get_dimensions()?; + let parameters = Parameters { + chip_dimensions, + image_dimensions, + pixel_dimensions, + bpp, + }; + camera.parameters = parameters; + Ok(camera) } } @@ -448,8 +466,6 @@ impl Camera { } pub fn set_defaults(&mut self) -> Result<()> { unsafe { - println!("Hey wait gotta get dimensions first"); - let ((chipw, chiph), (imagew, imageh), (pixelw, pixelh), bpp) = self.get_dimensions()?; match QHYCCDCam::IsQHYCCDControlAvailable(self.handle, Control::Color as i32) { 1 | 2 | 3 | 4 => { self.set_color_mode(false)?; @@ -463,14 +479,14 @@ impl Camera { return Err(CameraError::QHYError) } } - self.set_roi(0, 0, imagew, imageh)?; + self.set_roi(0, 0, self.parameters.image_dimensions.0, self.parameters.image_dimensions.1)?; self.set_bin_mode(1)?; if self.has_control(Control::TransferBit) { check(QHYCCDCam::SetQHYCCDBitsMode(self.handle, 16))?; self.settings.bpp = 16; println!("set tp 16bpp"); } - println!("roi set to {} x {} ???", imagew, imageh); + println!("roi set to {} x {} ???", self.parameters.image_dimensions.0, self.parameters.image_dimensions.1); println!("gain limits: {:?}", self.get_control_limits(Control::Gain)?); println!("exposure limits: {:?}", self.get_control_limits(Control::Exposure)?); println!("offset: {:?}", self.get_control_limits(Control::Offset)?); |