Skip to content

Commit

Permalink
Add set control by id
Browse files Browse the repository at this point in the history
  • Loading branch information
fishrockz committed Jan 22, 2025
1 parent 3a1f52c commit 25cd38c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libcamera/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,16 @@ impl ControlList {
/// be returned. Use [ControlList::get] if you need to ensure that value was set.
pub fn set<C: Control>(&mut self, val: C) -> Result<(), ControlError> {
let ctrl_val: ControlValue = val.into();
self.set_by_id(C::ID as _, ctrl_val)
}

pub fn set_by_id(&mut self, id: u32, ctrl_val: ControlValue) -> Result<(), ControlError> {
unsafe {
let val_ptr = NonNull::new(libcamera_control_value_create()).unwrap();
ctrl_val.write(val_ptr);
libcamera_control_list_set(self.ptr().cast_mut(), C::ID as _, val_ptr.as_ptr());
libcamera_control_list_set(self.ptr().cast_mut(), id, val_ptr.as_ptr());
libcamera_control_value_destroy(val_ptr.as_ptr());
}

Ok(())
}
}
Expand Down

0 comments on commit 25cd38c

Please sign in to comment.