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/qhyccd/mod.rs | 61 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 15 deletions(-) (limited to 'src/qhyccd/mod.rs') 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