diff options
author | iximeow <me@iximeow.net> | 2020-08-14 19:14:01 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2020-08-14 19:14:01 -0700 |
commit | faedb8827d3cfc6f1f59b4b29da6c3556ffc5760 (patch) | |
tree | 28afef2dc1866376dd807c3b2b8ba31cdc00c2a0 /src/qhyccd/mod.rs | |
parent | 500d14a308a2f58ea70b4a4e75c5603cd66d629f (diff) |
misc changes and improvements
Diffstat (limited to 'src/qhyccd/mod.rs')
-rw-r--r-- | src/qhyccd/mod.rs | 61 |
1 files changed, 46 insertions, 15 deletions
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<QHYResponse>, Sender<QHYMess let SLEEP_TIME = 2u64; let mut exposing = false; let mut counter = 0u64; + let mut capture_count: Option<u64> = None; loop { match message_receiver.try_recv() { @@ -182,14 +194,16 @@ pub fn connect(camera_idx: i32) -> Result<(Receiver<QHYResponse>, Sender<QHYMess drop(data); } } - Ok(QHYMessage::BeginCapture) => { + 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<QHYResponse>, Sender<QHYMess } } +// println!("counter: {:?}, exposing: {:?}", counter, exposing); if counter == 0 && exposing { if let Some(data) = camera.get_frame() { let (data, width, height, bpp, channels) = camera.read_frame(data).expect("can read frames from camera"); @@ -244,6 +259,20 @@ pub fn connect(camera_idx: i32) -> Result<(Receiver<QHYResponse>, Sender<QHYMess temp: (camera.settings.cur_temp * 10.0) as u16, }, )).unwrap(); + match &mut capture_count { + Some(count) => { + *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<u8>), - BeginCapture, + BeginCapture(Option<u64>), 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(()) } |