summaryrefslogtreecommitdiff
path: root/src/qhyccd/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/qhyccd/mod.rs')
-rw-r--r--src/qhyccd/mod.rs44
1 files changed, 30 insertions, 14 deletions
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)?);