summaryrefslogtreecommitdiff
path: root/src/qhyccd
diff options
context:
space:
mode:
Diffstat (limited to 'src/qhyccd')
-rw-r--r--src/qhyccd/QHYCCDCam.rs1
-rw-r--r--src/qhyccd/mod.rs37
2 files changed, 33 insertions, 5 deletions
diff --git a/src/qhyccd/QHYCCDCam.rs b/src/qhyccd/QHYCCDCam.rs
index 37deef9..8419bb7 100644
--- a/src/qhyccd/QHYCCDCam.rs
+++ b/src/qhyccd/QHYCCDCam.rs
@@ -106,6 +106,7 @@ extern "C" {
pub fn InitQHYCCD(id: *mut os::raw::c_void) -> os::raw::c_int;
pub fn IsQHYCCDControlAvailable(handle: *mut os::raw::c_void, control: os::raw::c_int) -> os::raw::c_int;
pub fn SetQHYCCDParam(handle: *mut os::raw::c_void, control: os::raw::c_int, value: os::raw::c_double) -> os::raw::c_int;
+ pub fn GetQHYCCDParamMinMaxStep(handle: *mut os::raw::c_void, control: os::raw::c_int, min: *mut os::raw::c_double, max: *mut os::raw::c_double, step: *mut os::raw::c_double) -> os::raw::c_int;
pub fn GetQHYCCDParam(handle: *mut os::raw::c_void, control: os::raw::c_int) -> os::raw::c_double;
pub fn GetQHYCCDEffectiveArea(handle: *mut os::raw::c_void, startx: *mut os::raw::c_int, starty: *mut os::raw::c_int, sizex: *mut os::raw::c_int, sizey: *mut os::raw::c_int) -> os::raw::c_int;
pub fn GetQHYCCDOverScanArea(handle: *mut os::raw::c_void, startx: *mut os::raw::c_int, starty: *mut os::raw::c_int, sizex: *mut os::raw::c_int, sizey: *mut os::raw::c_int) -> os::raw::c_int;
diff --git a/src/qhyccd/mod.rs b/src/qhyccd/mod.rs
index 0ce31e2..a7fb784 100644
--- a/src/qhyccd/mod.rs
+++ b/src/qhyccd/mod.rs
@@ -105,6 +105,26 @@ impl Camera {
}
}
}
+ pub fn get_param_limits(&self, control: Control) -> Result<(f64, f64, f64)> {
+ unsafe {
+ if self.has_param(control) {
+ let mut min = 0f64;
+ let mut max = 0f64;
+ let mut step = 0f64;
+ match check(QHYCCDCam::GetQHYCCDParamMinMaxStep(self.handle, control as i32, &mut min, &mut max, &mut step)) {
+ Ok(_) => {
+ Ok((min, max, step))
+ },
+ Err(_) => {
+ Err(CameraError::QHYError)
+ }
+ }
+ } else {
+ Err(CameraError::InvalidControl)
+ }
+ }
+ }
+
pub fn get_param(&self, control: Control) -> f64 {
unsafe {
QHYCCDCam::GetQHYCCDParam(self.handle, control as i32)
@@ -228,15 +248,22 @@ impl Camera {
let ref mut w = BufWriter::new(file);
let mut encoder = png::Encoder::new(w, castediw as u32, castedih as u32);
encoder.set(png::ColorType::RGB).set(png::BitDepth::Sixteen);
- let mut writer = encoder.write_header().unwrap();
- writer.write_image_data(
+ // crazy theory, endianness might be wrong...
+ // so flip the bytes first
+ let mut dataslice: &mut [u8] =
unsafe {
- std::slice::from_raw_parts(
+ std::slice::from_raw_parts_mut(
data,
bufsize as usize
)
- }
- ).unwrap();
+ };
+ for i in 0..(bufsize as usize / 2) {
+ let tmp = dataslice[i * 2];
+ dataslice[i * 2] = dataslice[i * 2 + 1];
+ dataslice[i * 2 + 1] = tmp;
+ }
+ let mut writer = encoder.write_header().unwrap();
+ writer.write_image_data(dataslice).unwrap();
dealloc(data as *mut u8, data_layout);
Ok(())
}