summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2020-10-19 00:01:18 -0700
committeriximeow <me@iximeow.net>2020-10-19 00:01:18 -0700
commitaf13b8c588ca7b5e4f761c4bd3baf03807e7d61b (patch)
tree0cf91a3e409e34cf059cd9f3c3673f4ce5d28870 /src/main.rs
parentc3f1887b4e9b1a4eaf42b51bcbdbe92e888f96d7 (diff)
dewarn
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs97
1 files changed, 20 insertions, 77 deletions
diff --git a/src/main.rs b/src/main.rs
index c892d97..e874594 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,7 +14,7 @@ use crossbeam_channel::{Sender, Receiver};
use crossbeam_channel::unbounded;
use std::time::Duration;
-use std::time::Instant;
+// use std::time::Instant;
use crate::asicam::ASICamera2::{ControlType, ImageType};
use crate::asicam::Camera;
@@ -60,13 +60,12 @@ fn record_image(data: &[u8], dimensions: Dimensions, target: &'static str, image
println!("image written!");
println!(".. writing raw");
let raw_path = format!("{}_{}.raw", target, image_id);
- let raw_dest = Path::new(&raw_path);
+ // let raw_dest = Path::new(&raw_path);
// let mut file = File::create(raw_dest).unwrap();
// file.write(data);
}
fn main() {
- let test = true;
println!("Doing qhy...");
let (image_writer, image_reader) = unbounded();
let (frame_sender, free_frames) = unbounded();
@@ -129,17 +128,18 @@ fn main() {
if scale_factor != 1 {
let downscaled = downscale(data.as_slice(), dimensions.width, dimensions.height, scale_factor);
let image_info = show_image::ImageInfo::mono8(dimensions.width as usize / scale_factor as usize, dimensions.height as usize / scale_factor as usize);
- window.set_image(&(downscaled.as_slice(), image_info), "image-001");
+ let _ = window.set_image(&(downscaled.as_slice(), image_info), "image-001");
} else {
let image_info = show_image::ImageInfo::mono8(dimensions.width as usize, dimensions.height as usize);
- window.set_image(&(data.as_slice(), image_info), "image-001");
+ let _ = window.set_image(&(data.as_slice(), image_info), "image-001");
}
record_image(data.as_slice(), dimensions, target, image_id, &properties);
println!("pretend i wrote image {}_{}", target, image_id);
frame_sender.send(data).unwrap();
}
- Err(RecvError) => {
+ Err(recv_error) => {
+ eprintln!("recv error: {:?}", recv_error);
// something in the application has crashed. time 2 die
return;
}
@@ -155,7 +155,7 @@ fn main() {
}
#[derive(Debug, Copy, Clone)]
-struct Dimensions {
+pub struct Dimensions {
width: u32,
height: u32,
bpp: u8,
@@ -169,7 +169,7 @@ impl Dimensions {
}
#[derive(Debug)]
-struct Properties {
+pub struct Properties {
pub device: &'static str,
pub exposure_ms: u32,
pub gain: u16,
@@ -206,10 +206,11 @@ enum ImageWriter {
fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<Vec<u8>>, image_writer: Sender<ImageInfo>) {
use crate::qhyccd::Control;
println!("Operating on qhy camera ... or i'll die trying");
- let (mut camera_rx, mut camera_tx) = qhyccd::connect(0).unwrap();
+ let (camera_rx, camera_tx) = qhyccd::connect(0).unwrap();
let mut image_id = 0u32;
let mut settings_copy = qhyccd::Settings::default();
+ eprintln!("settings initialized: {:?}", settings_copy);
// qhy376c settings
camera_tx.send(QHYMessage::SetControl(Control::Exposure, 20000.0 * 1000.0)).unwrap();
@@ -245,9 +246,9 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V
camera_tx.send(QHYMessage::BeginCapture(None)).unwrap();
- let LAPSE_PERIOD = Duration::from_millis(0);
+ let _LAPSE_PERIOD = Duration::from_millis(0);
- let mut capture_start = Instant::now().checked_sub(Duration::from_millis(10)).unwrap().checked_sub(LAPSE_PERIOD).unwrap();;
+ // let capture_start = Instant::now().checked_sub(Duration::from_millis(10)).unwrap().checked_sub(LAPSE_PERIOD).unwrap();
loop {
/*
if capture_start.elapsed() > LAPSE_PERIOD {
@@ -262,7 +263,8 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V
Ok(buffer) => {
camera_tx.send(QHYMessage::FrameAvailable(buffer)).unwrap();
},
- Err(RecvError) => {
+ Err(recv_error) => {
+ eprintln!("recv error: {:?}", recv_error);
// disconnected. nothing we can do but to..
return;
}
@@ -282,19 +284,21 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V
}
Ok(QHYResponse::UpdatedSettings(settings)) => {
settings_copy = settings;
+ eprintln!("settings updated: {:?}", settings_copy);
}
Ok(QHYResponse::Data(data, dimensions, properties)) => {
image_writer.send(ImageInfo { data, dimensions, target, image_id: image_id, properties}).unwrap();
// images.log(target, image_id, settings_copy);
image_id += 1;
if Some(image_id) == count {
- camera_tx.send(QHYMessage::Shutdown);
+ camera_tx.send(QHYMessage::Shutdown).unwrap();
}
}
Ok(QHYResponse::DroppedFrame) => {
println!("Dropped frame...");
}
- Err(RecvError) => {
+ Err(e) => {
+ eprintln!("recv error: {:?}", e);
// camera is closed. hopefully it just shut down? but maybe crashed!!
return;
}
@@ -303,46 +307,13 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V
default(Duration::from_millis(2000)) => {
camera_tx.send(
QHYMessage::QueryControl(Control::CurTemp)
- );
+ ).unwrap();
}
}
}
- /*
- 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);
- }
- camera.release().unwrap();
- });
- t.join();
- */
}
-fn operate_asi(test: bool) {
+fn operate_asi(_test: bool) {
println!("Operating on asi camera ... or i'll die trying");
let mut camera = asicam::acquire(0).unwrap();
@@ -352,18 +323,6 @@ fn operate_asi(test: bool) {
std::thread::sleep(std::time::Duration::from_millis(500));
println!("Camera temperature is currently {:?}", camera.get_control_value(ControlType::Temperature).unwrap());
- /*
- for exposure in [2000, 5000, 10000, 30000].iter() {
- camera.set_control_value(ControlType::Exposure, *exposure).unwrap();
- for gain in [450, 375, 325, 250, 200].iter() {
- camera.set_control_value(ControlType::Gain, *gain).unwrap();
- for offset in [100, 80, 60, 40, 20, 0].iter() {
- camera.set_control_value(ControlType::Offset, *offset).unwrap();
- take_calibration_images(&camera, 1, &format!("roof_gain_{:03}_offset_{:03}_exposure_{:06}", gain, offset, exposure));
- }
- }
- }
- */
camera.set_exposure_ms(30000).unwrap();
// camera.set_control_value(ControlType::Exposure, 70000000).unwrap();
camera.set_control_value(ControlType::Gain, 250).unwrap();
@@ -375,22 +334,6 @@ fn operate_asi(test: bool) {
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() {
- camera.set_control_value(ControlType::Exposure, *exposure).unwrap();
- for gain in [450, 375, 325, 250, 200].iter() {
- camera.set_control_value(ControlType::Gain, *gain).unwrap();
- for offset in [100, 80, 70, 60, 40, 0].iter() {
- camera.set_control_value(ControlType::Offset, *offset).unwrap();
- take_calibration_images(
- &camera,
- 30,
- &format!("images/gain_{:03}_offset_{:03}_exposure_{:06}", gain, offset, exposure));
- }
- }
- }
- */
println!("Done!");
}