summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs52
-rw-r--r--src/qhyccd/mod.rs61
2 files changed, 87 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs
index 4b54a3a..ce1c19e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,6 +14,7 @@ use crossbeam_channel::{Sender, Receiver};
use crossbeam_channel::unbounded;
use std::time::Duration;
+use std::time::Instant;
use crate::asicam::ASICamera2::{ControlType, ImageType};
use crate::asicam::Camera;
@@ -60,8 +61,8 @@ fn record_image(data: &[u8], dimensions: Dimensions, target: &'static str, image
println!(".. writing raw");
let raw_path = format!("{}_{}.raw", target, image_id);
let raw_dest = Path::new(&raw_path);
- let mut file = File::create(raw_dest).unwrap();
- file.write(data);
+// let mut file = File::create(raw_dest).unwrap();
+// file.write(data);
}
fn main() {
@@ -99,7 +100,7 @@ fn main() {
}
});
- operate_qhy("ngc7635", None, free_frames, image_writer);
+ operate_qhy("settings", None, free_frames, image_writer);
// println!("Doing asi...");
// operate_asi(test);
}
@@ -130,7 +131,7 @@ struct Properties {
impl Properties {
pub fn stringy(&self) -> String {
- format!("{{\n device: \"{}\",\n exposure_ms: {}\n, gain: {}\n offset: {}\n gamma: {}\n temp: {}\n}}",
+ format!("{{\n \"device\": \"{}\",\n \"exposure_ms\": {},\n \"gain\": {},\n \"offset\": {},\n \"gamma\": {},\n \"temp\": {}\n}}",
self.device,
self.exposure_ms,
self.gain,
@@ -161,22 +162,51 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V
let mut image_id = 0u32;
let mut settings_copy = qhyccd::Settings::default();
- camera_tx.send(QHYMessage::SetControl(Control::Exposure, 2000.0 * 1000.0)).unwrap();
- camera_tx.send(QHYMessage::SetControl(Control::Offset, 00.0)).unwrap();
-// camera_tx.send(QHYMessage::SetControl(Control::Gamma, 10.0)).unwrap();
+ // qhy376c settings
+ camera_tx.send(QHYMessage::SetControl(Control::Exposure, 20000.0 * 1000.0)).unwrap();
+// camera_tx.send(QHYMessage::SetControl(Control::Exposure, 200.0 * 1000.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Cooler, 0.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Color, 1.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Gain, 4000.0)).unwrap();
+
+ /*
+ camera_tx.send(QHYMessage::SetControl(Control::Exposure, 60000.0 * 1000.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Cooler, 0.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Color, 0.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Gain, 110.0)).unwrap();
+ */
+
+ /*
+ camera_tx.send(QHYMessage::SetControl(Control::Exposure, 20000.0 * 1000.0)).unwrap();
+// camera_tx.send(QHYMessage::SetControl(Control::Offset, 00.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Gamma, 1.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Brightness, 00.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Contrast, 00.0)).unwrap();
// camera_tx.send(QHYMessage::SetControl(Control::Gamma, 2.0)).unwrap();
- camera_tx.send(QHYMessage::SetControl(Control::Cooler, 15.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Cooler, 0.0)).unwrap();
camera_tx.send(QHYMessage::SetControl(Control::USBTraffic, 60.0)).unwrap();
camera_tx.send(QHYMessage::SetControl(Control::Color, 0.0)).unwrap(); // disable color
-// camera_tx.send(QHYMessage::SetControl(Control::Gain, 3750.0)).unwrap();
camera_tx.send(QHYMessage::SetControl(Control::Gain, 4000.0)).unwrap();
+// camera_tx.send(QHYMessage::SetControl(Control::Gain, 140.0)).unwrap();
// camera_tx.send(QHYMessage::SetControl(Control::Gain, 4000.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));
- camera_tx.send(QHYMessage::BeginCapture).unwrap();
+
+ camera_tx.send(QHYMessage::BeginCapture(None)).unwrap();
+ 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();;
loop {
+ /*
+ if capture_start.elapsed() > LAPSE_PERIOD {
+ println!("Lapsing!!");
+ camera_tx.send(QHYMessage::BeginCapture(Some(1))).unwrap();
+ capture_start = Instant::now();
+ }
+ */
select! {
recv(free_frames) -> msg => {
match msg {
@@ -205,7 +235,7 @@ fn operate_qhy(target: &'static str, count: Option<u32>, free_frames: Receiver<V
settings_copy = settings;
}
Ok(QHYResponse::Data(data, dimensions, properties)) => {
- image_writer.send(ImageInfo { data, dimensions, target, image_id, properties}).unwrap();
+ 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 {
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(())
}