Skip to content

Commit

Permalink
redo properties API again - make default ID list smaller (and mostly …
Browse files Browse the repository at this point in the history
…things people actually use) and make the whole thing simpler overall (for us)
  • Loading branch information
l1npengtul committed Dec 11, 2024
1 parent 0646b0a commit 096880e
Show file tree
Hide file tree
Showing 2 changed files with 357 additions and 92 deletions.
54 changes: 5 additions & 49 deletions nokhwa-core/src/camera.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::error::{NokhwaError, NokhwaResult};
use crate::frame_format::FrameFormat;
use crate::properties::{CameraProperties, CameraPropertyId, CameraPropertyValue};
use crate::properties::{ControlId, ControlValue, Properties};
use crate::types::{CameraFormat, CameraIndex, FrameRate, Resolution};
use std::collections::HashMap;
use crate::frame_buffer::FrameBuffer;
use crate::stream::Stream;

pub trait Open {
Expand All @@ -14,33 +15,6 @@ pub trait AsyncOpen: Sized {
async fn open_async(index: CameraIndex) -> NokhwaResult<Self>;
}

macro_rules! def_camera_props {
( $($property:ident, )* ) => {
paste::paste! {
$(
fn [<$property:snake>] (&self) -> Option<&crate::properties::CameraPropertyDescriptor> {
self.properties().[<$property:snake>]()
}

fn [<set_ $property:snake>] (&mut self, value: crate::properties::CameraPropertyValue) -> Result<(), crate::error::NokhwaError> {
self.set_property(&crate::properties::CameraPropertyId::$property, value)
}
)*
}
};
}

// macro_rules! def_camera_props_async {
// ( $($property:ident, )* ) => {
// paste::paste! {
// $(
// async fn [<set_ $property:snake _async>] (&mut self, value: CameraPropertyValue) -> Result<(), NokhwaError> {
// self.[<set_ $property:snake >](value)
// }
// )*
// }
// };
// }

pub trait Setting {
fn enumerate_formats(&self) -> Result<Vec<CameraFormat>, NokhwaError>;
Expand All @@ -52,31 +26,13 @@ pub trait Setting {

fn set_format(&self, camera_format: CameraFormat) -> Result<(), NokhwaError>;

fn properties(&self) -> &CameraProperties;
fn properties(&self) -> &Properties;

fn set_property(
&mut self,
property: &CameraPropertyId,
value: CameraPropertyValue,
property: &ControlId,
value: ControlValue,
) -> Result<(), NokhwaError>;

def_camera_props!(
Brightness,
Contrast,
Hue,
Saturation,
Sharpness,
Gamma,
WhiteBalance,
BacklightCompensation,
Pan,
Tilt,
Zoom,
Exposure,
Iris,
Focus,
Facing,
);
}

// #[cfg(feature = "async")]
Expand Down
Loading

0 comments on commit 096880e

Please sign in to comment.