From 0d887779b8dee042999d04a29d4a095a3df93a6c Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 23 Jul 2019 23:21:14 -0700 Subject: asi camera adjustments record images in 16 bit mode, is the biggest change --- src/asicam/mod.rs | 28 +++++++++++--------- src/main.rs | 79 +++++++++++++++++++++++++++++++------------------------ 2 files changed, 61 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/asicam/mod.rs b/src/asicam/mod.rs index 4d006ae..93ed683 100644 --- a/src/asicam/mod.rs +++ b/src/asicam/mod.rs @@ -117,25 +117,29 @@ impl Camera { ASICamera2::ASIGetDataAfterExp( self.id, self.image_buffer, - self.curr_width as i64 * self.curr_height as i64 * 3 + self.curr_width as i64 * self.curr_height as i64 * 2 ) }; build_result((), res)?; + let mut real_image = vec![0; self.curr_width as usize * self.curr_height as usize * 2 * 3]; + for i in 0..(self.curr_width * self.curr_height) { + unsafe { + real_image[i as usize * 6 + 0] = *self.image_buffer.offset(i as isize * 2 + 1); + real_image[i as usize * 6 + 2] = *self.image_buffer.offset(i as isize * 2 + 1); + real_image[i as usize * 6 + 4] = *self.image_buffer.offset(i as isize * 2 + 1); + real_image[i as usize * 6 + 1] = *self.image_buffer.offset(i as isize * 2); + real_image[i as usize * 6 + 3] = *self.image_buffer.offset(i as isize * 2); + real_image[i as usize * 6 + 5] = *self.image_buffer.offset(i as isize * 2); + } + } let dest = Path::new(path); let file = File::create(dest).unwrap(); let ref mut w = BufWriter::new(file); let mut encoder = png::Encoder::new(w, self.curr_width, self.curr_height); - encoder.set(png::ColorType::RGB).set(png::BitDepth::Eight); + encoder.set(png::ColorType::RGB).set(png::BitDepth::Sixteen); let mut writer = encoder.write_header().unwrap(); - writer.write_image_data( - unsafe { - std::slice::from_raw_parts( - self.image_buffer, - self.curr_width as usize * self.curr_height as usize* 3 - ) - } - ).unwrap(); + writer.write_image_data(&real_image).unwrap(); Ok(()) } @@ -248,10 +252,10 @@ pub fn acquire(camera_id: i32) -> Result { camera.curr_height = camera_props.max_height as u32; camera.color_format = ImageType::RGB24; camera.image_buffer = alloc( - Layout::from_size_align(camera.curr_width as usize * camera.curr_height as usize * 3, 8).unwrap() + Layout::from_size_align(camera.curr_width as usize * camera.curr_height as usize * 2, 8).unwrap() ); - let res = ASICamera2::ASISetROIFormat(camera_id, camera.width as i32, camera.height as i32, 1, ImageType::RGB24 as i32); + let res = ASICamera2::ASISetROIFormat(camera_id, camera.width as i32, camera.height as i32, 1, ImageType::RAW16 as i32); build_result((), res)?; println!("Set ROI/Format"); diff --git a/src/main.rs b/src/main.rs index 95de6fd..7275c96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,39 +12,46 @@ use crate::asicam::Camera; fn main() { let test = true; - println!("Doing qhy..."); - operate_qhy(test); +// println!("Doing qhy..."); +// operate_qhy(test); println!("Doing asi..."); -// operate_asi(test); + operate_asi(test); } fn operate_qhy(test: bool) { use crate::qhyccd::Control; println!("Operating on qhy camera ... or i'll die trying"); - let mut camera = qhyccd::acquire(0).unwrap(); - camera.set_defaults().unwrap(); - camera.set_exposure_ms(1).unwrap(); - camera.set_param(Control::Gain, 34.0).unwrap(); - camera.set_param(Control::Offset, 00.0).unwrap(); - camera.set_param(Control::USBTraffic, 50.0).unwrap(); -// camera.set_target_temp(0.0).unwrap(); - camera.set_param(Control::Cooler, -15.0).unwrap(); - println!("Gain: {:?}", camera.get_param_limits(Control::Gain)); -// camera.set_param(Control::Speed, 1.0).unwrap(); - println!("current temp: {}", camera.get_param(Control::CurTemp)); - camera.set_param(Control::CONTROL_WBR, 2750.0).unwrap(); - camera.set_param(Control::CONTROL_WBG, 2500.0).unwrap(); - camera.set_param(Control::CONTROL_WBB, 3000.0).unwrap(); - // camera.set_bin_mode(2).unwrap(); - if !test { - let object = "m13"; - for i in 0..20 { - camera.take_image(&format!("{}_{}.png", object, i));//, i)); + let t = std::thread::spawn(move || { + let mut camera = qhyccd::acquire(0).unwrap(); + camera.set_defaults().unwrap(); + camera.set_exposure_ms(400).unwrap(); + // camera.set_param(Control::Exposure, 10.0).unwrap(); + camera.set_param(Control::Gain, 4000.0); //.unwrap(); + camera.set_param(Control::Offset, 00.0).unwrap(); + // camera.set_param(Control::USBTraffic, 50.0).unwrap(); + // camera.set_param(Control::ManulPwm, 0.0).unwrap(); + // camera.set_target_temp(0.0).unwrap(); + camera.set_param(Control::Cooler, -25.0).unwrap(); + // camera.set_roi(0, 0, 1920 * 2, 1080 * 2).unwrap(); + println!("Gain: {:?}", camera.get_param_limits(Control::ManulPwm)); + println!("cur pwm ???: {}", camera.get_param(Control::CurPWM)); + println!("current temp: {}", camera.get_param(Control::CurTemp)); + // camera.set_param(Control::CONTROL_WBR, 2750.0).unwrap(); + // camera.set_param(Control::CONTROL_WBG, 2500.0).unwrap(); + // camera.set_param(Control::CONTROL_WBB, 3000.0).unwrap(); + // camera.set_bin_mode(2).unwrap(); + if !test { + let object = "veil"; + for i in 0..10 { + camera.take_image(&format!("{}_{}.png", object, i));//, i)); + } + } else { + camera.take_image("qhy_test_2.png").unwrap(); + println!("exposing: {:x}", camera.get_param(Control::IS_EXPOSING_DONE) as u64); } - } else { - camera.take_image("qhy_test_2.png").unwrap(); - } - camera.release().unwrap(); + camera.release().unwrap(); + }); + t.join(); } fn operate_asi(test: bool) { @@ -52,9 +59,9 @@ fn operate_asi(test: bool) { let mut camera = asicam::acquire(0).unwrap(); println!("{:?}", camera); -// camera.set_control_value(ControlType::TargetTemp, -100).unwrap(); -// camera.set_control_value(ControlType::CoolerOn, 1).unwrap(); -// std::thread::sleep(std::time::Duration::from_millis(500)); + camera.set_control_value(ControlType::CoolerOn, 1).unwrap(); + camera.set_control_value(ControlType::TargetTemp, -200).unwrap(); + std::thread::sleep(std::time::Duration::from_millis(500)); println!("Camera temperature is currently {:?}", camera.get_control_value(ControlType::Temperature).unwrap()); /* @@ -69,13 +76,17 @@ fn operate_asi(test: bool) { } } */ - camera.set_exposure_ms(1).unwrap(); + camera.set_exposure_ms(30000).unwrap(); // camera.set_control_value(ControlType::Exposure, 70000000).unwrap(); - camera.set_control_value(ControlType::Gain, 475).unwrap(); + camera.set_control_value(ControlType::Gain, 250).unwrap(); camera.set_control_value(ControlType::Offset, 0).unwrap(); - camera.set_control_value(ControlType::HardwareBin, 0).unwrap(); - camera.set_roi_format(camera.width, camera.height, 1, ImageType::RGB24).unwrap(); - camera.take_image("asi_test.png").unwrap(); + camera.set_control_value(ControlType::HardwareBin, 1).unwrap(); + camera.set_roi_format(camera.width, camera.height, 1, ImageType::RAW16).unwrap(); + for i in 0..240 { + println!("doing image {}", i); + println!("Camera temperature is currently {:?}", camera.get_control_value(ControlType::Temperature).unwrap()); + camera.take_image(&format!("ngc7380_{}.png", i)).unwrap(); + } // take_calibration_images(&camera, 40, "dark_gain_350_exposure_45000"); /* for exposure in [1000 * 1000 * 10].iter() { -- cgit v1.1