From faedb8827d3cfc6f1f59b4b29da6c3556ffc5760 Mon Sep 17 00:00:00 2001 From: iximeow Date: Fri, 14 Aug 2020 19:14:01 -0700 Subject: misc changes and improvements --- src/main.rs | 52 +++++++++++++++++++++++++++++++++++++---------- src/qhyccd/mod.rs | 61 +++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 87 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4b54a3a..ce1c19e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ use crossbeam_channel::{Sender, Receiver}; use crossbeam_channel::unbounded; use std::time::Duration; +use std::time::Instant; use crate::asicam::ASICamera2::{ControlType, ImageType}; use crate::asicam::Camera; @@ -60,8 +61,8 @@ fn record_image(data: &[u8], dimensions: Dimensions, target: &'static str, image println!(".. writing raw"); let raw_path = format!("{}_{}.raw", target, image_id); let raw_dest = Path::new(&raw_path); - let mut file = File::create(raw_dest).unwrap(); - file.write(data); +// let mut file = File::create(raw_dest).unwrap(); +// file.write(data); } fn main() { @@ -99,7 +100,7 @@ fn main() { } }); - operate_qhy("ngc7635", None, free_frames, image_writer); + operate_qhy("settings", None, free_frames, image_writer); // println!("Doing asi..."); // operate_asi(test); } @@ -130,7 +131,7 @@ struct Properties { impl Properties { pub fn stringy(&self) -> String { - format!("{{\n device: \"{}\",\n exposure_ms: {}\n, gain: {}\n offset: {}\n gamma: {}\n temp: {}\n}}", + format!("{{\n \"device\": \"{}\",\n \"exposure_ms\": {},\n \"gain\": {},\n \"offset\": {},\n \"gamma\": {},\n \"temp\": {}\n}}", self.device, self.exposure_ms, self.gain, @@ -161,22 +162,51 @@ fn operate_qhy(target: &'static str, count: Option, free_frames: Receiver LAPSE_PERIOD { + println!("Lapsing!!"); + camera_tx.send(QHYMessage::BeginCapture(Some(1))).unwrap(); + capture_start = Instant::now(); + } + */ select! { recv(free_frames) -> msg => { match msg { @@ -205,7 +235,7 @@ fn operate_qhy(target: &'static str, count: Option, free_frames: Receiver { - image_writer.send(ImageInfo { data, dimensions, target, image_id, properties}).unwrap(); + 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 { diff --git a/src/qhyccd/mod.rs b/src/qhyccd/mod.rs index 1f7bcb2..72a68b9 100644 --- a/src/qhyccd/mod.rs +++ b/src/qhyccd/mod.rs @@ -128,7 +128,7 @@ pub fn fix_channels_and_endianness(dataslice: &mut [u8]) { if false { for e in 0..3 { let el = ((dataslice[i * 6 + e * 2] as u16) << 8) | (dataslice[i * 6 + e * 2 + 1] as u16); - let el = el.saturating_mul(128); + let el = el.saturating_mul(16); dataslice[i * 6 + e * 2] = (el >> 8) as u8; dataslice[i * 6 + e * 2 + 1] = el as u8; } @@ -137,10 +137,21 @@ pub fn fix_channels_and_endianness(dataslice: &mut [u8]) { } pub fn fix_endianness(dataslice: &mut [u8]) { - for i in 0..(dataslice.len() / 2) { - let (low, high) = (dataslice[i * 2], dataslice[i * 2 + 1]); - dataslice[i * 2 + 0] = high; - dataslice[i * 2 + 1] = low; + // yolo it + if dataslice.len() % 2 != 0 { + panic!("you want to fix endianness of a slice that has length {}, which is not divisible by two. are you certain the data has an endianness to reverse?", dataslice.len()); + } + + let dataslice: &mut [u16] = unsafe { + std::slice::from_raw_parts_mut(dataslice.as_mut_ptr() as *mut u16, dataslice.len() / 2) + }; + for i in 0..dataslice.len() { + // TODO: simd-ize this? + // this is a pshufb and a mul.. + dataslice[i] = dataslice[i].swap_bytes(); + if true { +// dataslice[i] *= 16; + } } } @@ -165,6 +176,7 @@ pub fn connect(camera_idx: i32) -> Result<(Receiver, Sender = None; loop { match message_receiver.try_recv() { @@ -182,14 +194,16 @@ pub fn connect(camera_idx: i32) -> Result<(Receiver, Sender { + Ok(QHYMessage::BeginCapture(count)) => { counter = camera.settings.exposure; + capture_count = count; println!("Beginning capture"); camera.begin_exposure().expect("can begin exposures"); exposing = true; } Ok(QHYMessage::StopCapture) => { counter = 0; + capture_count = None; camera.cancel_exposure().expect("can cancel exposures"); exposing = false; } @@ -227,6 +241,7 @@ pub fn connect(camera_idx: i32) -> Result<(Receiver, Sender Result<(Receiver, Sender { + *count -= 1; + if *count == 0 { + println!("finished capture run"); + exposing = false; + camera.cancel_exposure(); + continue; + } + }, + None => { + // do nothing + } + } } else { // no frame ready in the buffer! we can't actually read the image... counter = camera.settings.exposure; @@ -272,7 +301,7 @@ pub enum QHYResponse { pub enum QHYMessage { FrameAvailable(Vec), - BeginCapture, + BeginCapture(Option), StopCapture, QueryControl(Control), SetControl(Control, f64), @@ -398,19 +427,17 @@ impl Camera { // well, this can fail if debayering just isn't supported. so let's... not QHYCCDCam::SetQHYCCDDebayerOnOff(self.handle, 0); } - /* - self.set_control(Control::CONTROL_WBR, 1000.0)?; - self.set_control(Control::CONTROL_WBG, 1000.0)?; - self.set_control(Control::CONTROL_WBB, 1000.0)?; - */ + self.set_control(Control::CONTROL_WBR, 4000.0)?; + self.set_control(Control::CONTROL_WBG, 4000.0)?; + self.set_control(Control::CONTROL_WBB, 4000.0)?; self.settings.channels = 1; } else { unsafe { check(QHYCCDCam::SetQHYCCDDebayerOnOff(self.handle, 1))?; } - self.set_control(Control::CONTROL_WBR, 1000.0)?; - self.set_control(Control::CONTROL_WBG, 1000.0)?; - self.set_control(Control::CONTROL_WBB, 1000.0)?; + self.set_control(Control::CONTROL_WBR, 4000.0)?; + self.set_control(Control::CONTROL_WBG, 4000.0)?; + self.set_control(Control::CONTROL_WBB, 4000.0)?; self.settings.channels = 3; } Ok(()) @@ -437,10 +464,14 @@ impl Camera { 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!("gain limits: {:?}", self.get_control_limits(Control::Gain)?); println!("exposure limits: {:?}", self.get_control_limits(Control::Exposure)?); + println!("brightness: {:?}", self.get_control_limits(Control::Brightness)?); + println!("gamma: {:?}", self.get_control_limits(Control::Gamma)?); + println!("contrast: {:?}", self.get_control_limits(Control::Contrast)?); // panic!("hi"); Ok(()) } -- cgit v1.1