Skip to content

Commit

Permalink
Add support functions for ExposureWeights (SludgePhD#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyor authored and Aemulation committed Oct 8, 2024
1 parent 1b4e2d3 commit cb301d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ impl Device {
Self::open_impl(path.as_ref(), true)
}

pub fn try_clone(&self) -> io::Result<Self> {
Ok(Self {
file: self.file.try_clone()?,
available_capabilities: self.available_capabilities,
})
}

/// Opens a V4L2 device file from the given path.
///
/// If the path does not refer to a V4L2 device node, an error will be returned.
Expand Down
25 changes: 22 additions & 3 deletions src/uvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use self::raw::{XuControlQuery, XuQuery};
const HFLIP_UNIT_SELECTOR: u8 = 0x0c;
const VFLIP_UNIT_SELECTOR: u8 = 0x0d;
const UVC_EXTENSION_UNIT: u8 = 0x03;
const EXPOSURE_WEIGHTS_UNIT_SELECTOR: u8 = 0x09;

/// `UVCH` meta capture format.
#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -86,7 +87,7 @@ impl<'a> UvcExt<'a> {
}

pub fn horizontal_flip(&mut self) -> io::Result<()> {
self.set_control(
self.control_query(
UVC_EXTENSION_UNIT,
HFLIP_UNIT_SELECTOR,
XuQuery::SET_CUR,
Expand All @@ -95,15 +96,33 @@ impl<'a> UvcExt<'a> {
}

pub fn vertical_flip(&mut self) -> io::Result<()> {
self.set_control(
self.control_query(
UVC_EXTENSION_UNIT,
VFLIP_UNIT_SELECTOR,
XuQuery::SET_CUR,
&mut [1, 0],
)
}

fn set_control<const SIZE: usize>(
pub fn set_auto_exposure_weights(&mut self, weights: &mut [u8; 17]) -> io::Result<()> {
self.control_query(
UVC_EXTENSION_UNIT,
EXPOSURE_WEIGHTS_UNIT_SELECTOR,
XuQuery::SET_CUR,
weights,
)
}

pub fn get_auto_exposure_weights(&mut self, out: &mut [u8; 17]) -> io::Result<()> {
self.control_query(
UVC_EXTENSION_UNIT,
EXPOSURE_WEIGHTS_UNIT_SELECTOR,
XuQuery::GET_CUR,
out,
)
}

fn control_query<const SIZE: usize>(
&self,
unit: u8,
selector: u8,
Expand Down

0 comments on commit cb301d1

Please sign in to comment.