summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2019-10-06 01:26:07 -0700
committerAndy Wortman <ixineeringeverywhere@gmail.com>2019-10-06 01:26:07 -0700
commit56ff8b55d5b831ed068439ff60909ffbb2fb568a (patch)
tree5b143033ca8d1294d47a1eeb4b8a460d04da5862 /src
parent347333f2edd964e0dd258faa1549cb4d67471db9 (diff)
write raw data in case it's more useful for postprocessing
add a notion of camera properties, write that alongside images automatically fix colors if the image is in fact colors
Diffstat (limited to 'src')
-rw-r--r--src/main.rs71
-rw-r--r--src/qhyccd/mod.rs16
2 files changed, 73 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs
index dc70da6..a4ff360 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -24,10 +24,16 @@ use crate::qhyccd::QHYMessage;
use std::path::Path;
use std::fs::File;
use std::io::BufWriter;
+use std::io::Write;
use png::HasParameters;
-fn record_image(data: &[u8], dimensions: Dimensions, target: &'static str, image_id: u32) {
+fn record_image(data: &[u8], dimensions: Dimensions, target: &'static str, image_id: u32, properties: &Properties) {
+ let props_path = format!("{}_{}.json", target, image_id);
+ let props_dest = Path::new(&props_path);
+ let mut props_file = File::create(props_dest).unwrap();
+ // TODO: serde_json::serialize
+ props_file.write(properties.stringy().as_bytes()).unwrap();
let path_string = format!("{}_{}.png", target, image_id);
println!("writing {}..", path_string);
let dest = Path::new(&path_string);
@@ -51,6 +57,11 @@ fn record_image(data: &[u8], dimensions: Dimensions, target: &'static str, image
let mut writer = encoder.write_header().unwrap();
writer.write_image_data(data).unwrap();
println!("image written!");
+ 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);
}
fn main() {
@@ -64,9 +75,17 @@ fn main() {
select! {
recv(image_reader) -> msg => {
match msg {
- Ok(ImageInfo { mut data, dimensions, target, image_id }) => {
- qhyccd::fix_channels_and_endianness(data.as_mut_slice());
- record_image(data.as_slice(), dimensions, target, image_id);
+ Ok(ImageInfo { mut data, dimensions, target, image_id, properties }) => {
+ match dimensions.channels {
+ 1 => {
+ qhyccd::fix_endianness(data.as_mut_slice());
+ },
+ 3 => {
+ qhyccd::fix_channels_and_endianness(data.as_mut_slice());
+ }
+ c => { panic!("unsupported channel count: {}", c); }
+ }
+ record_image(data.as_slice(), dimensions, target, image_id, &properties);
println!("pretend i wrote image {}_{}", target, image_id);
frame_sender.send(data).unwrap();
}
@@ -80,7 +99,7 @@ fn main() {
}
});
- operate_qhy("dark_gain_4000", None, free_frames, image_writer);
+ operate_qhy("ngc7635", None, free_frames, image_writer);
// println!("Doing asi...");
// operate_asi(test);
}
@@ -99,9 +118,33 @@ impl Dimensions {
}
}
+#[derive(Debug)]
+struct Properties {
+ pub device: &'static str,
+ pub exposure_ms: u32,
+ pub gain: u16,
+ pub offset: u16,
+ pub gamma: u16,
+ pub temp: u16, // in hundredths of degrees, C. eg, 100 => 1deg C,
+}
+
+impl Properties {
+ pub fn stringy(&self) -> String {
+ format!("{{\n device: \"{}\",\n exposure_ms: {}\n, gain: {}\n offset: {}\n gamma: {}\n temp: {}\n}}",
+ self.device,
+ self.exposure_ms,
+ self.gain,
+ self.offset,
+ self.gamma,
+ self.temp
+ )
+ }
+}
+
struct ImageInfo {
data: Vec<u8>,
dimensions: Dimensions,
+ properties: Properties,
target: &'static str,
image_id: u32
}
@@ -110,7 +153,7 @@ enum ImageWriter {
FrameReady(Vec<u8>, Dimensions, &'static str, u32)
}
-fn operate_qhy(target: &'static str, count: Option<u32>, mut free_frames: Receiver<Vec<u8>>, mut image_writer: Sender<ImageInfo>) {
+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();
@@ -118,12 +161,16 @@ fn operate_qhy(target: &'static str, count: Option<u32>, mut free_frames: Receiv
let mut image_id = 0u32;
let mut settings_copy = qhyccd::Settings::default();
- camera_tx.send(QHYMessage::SetControl(Control::Exposure, 20000000.0)).unwrap();
- camera_tx.send(QHYMessage::SetControl(Control::Gain, 4000.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Exposure, 120000.0 * 1000.0)).unwrap();
camera_tx.send(QHYMessage::SetControl(Control::Offset, 00.0)).unwrap();
- camera_tx.send(QHYMessage::SetControl(Control::Cooler, 27.0)).unwrap();
+// camera_tx.send(QHYMessage::SetControl(Control::Gamma, 10.0)).unwrap();
+// camera_tx.send(QHYMessage::SetControl(Control::Gamma, 2.0)).unwrap();
+ camera_tx.send(QHYMessage::SetControl(Control::Cooler, 00.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::Color, 1.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, 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));
@@ -157,8 +204,8 @@ fn operate_qhy(target: &'static str, count: Option<u32>, mut free_frames: Receiv
Ok(QHYResponse::UpdatedSettings(settings)) => {
settings_copy = settings;
}
- Ok(QHYResponse::Data(data, dimensions)) => {
- image_writer.send(ImageInfo { data, dimensions, target, image_id: image_id }).unwrap();
+ Ok(QHYResponse::Data(data, dimensions, properties)) => {
+ image_writer.send(ImageInfo { data, dimensions, target, 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 12630d6..becb698 100644
--- a/src/qhyccd/mod.rs
+++ b/src/qhyccd/mod.rs
@@ -20,6 +20,7 @@ use crossbeam_channel::select;
use png::HasParameters;
use crate::Dimensions;
+use crate::Properties;
// unsafe impl Send for Camera { }
#[derive(Debug)]
@@ -222,7 +223,18 @@ pub fn connect(camera_idx: i32) -> Result<(Receiver<QHYResponse>, Sender<QHYMess
let (data, width, height, bpp, channels) = camera.read_frame(data).expect("can read frames from camera");
counter = camera.settings.exposure;
camera.begin_exposure().expect("can begin exposures");
- response_sender.send(QHYResponse::Data(data, Dimensions::new(width, height, bpp, channels))).unwrap();
+ response_sender.send(QHYResponse::Data(
+ data,
+ Dimensions::new(width, height, bpp, channels),
+ Properties {
+ device: "qhy376c",
+ exposure_ms: camera.settings.exposure as u32,
+ gain: camera.settings.gain as u16,
+ offset: camera.settings.offset as u16,
+ gamma: camera.settings.gamma as u16,
+ temp: (camera.settings.cur_temp * 10.0) as u16,
+ },
+ )).unwrap();
} else {
// no frame ready in the buffer! we can't actually read the image...
counter = camera.settings.exposure;
@@ -242,7 +254,7 @@ pub fn connect(camera_idx: i32) -> Result<(Receiver<QHYResponse>, Sender<QHYMess
pub enum QHYResponse {
InitializationError,
- Data(Vec<u8>, Dimensions),
+ Data(Vec<u8>, Dimensions, Properties),
DroppedFrame,
Shutdown,
UpdatedSettings(Settings),