Skip to content

Commit

Permalink
vimba: fix load and save settings
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Apr 12, 2024
1 parent 0bc38bb commit 7dd0a59
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
8 changes: 4 additions & 4 deletions ci2-vimba/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> {
// When file goes out of scope, it will be closed.
}

let mut settings_settings = vimba::FeaturePersistentSettings::default(); // let's get meta. settings to load the settings.
let settings_settings = vimba::default_feature_persist_settings(); // let's get meta. settings to load the settings.
self.camera
.lock()
.camera_settings_load(&settings_path, &mut settings_settings)
.camera_settings_load(&settings_path, &settings_settings)
.map_vimba_err()

// tempdir will be closed and removed when it is dropped.
Expand All @@ -505,10 +505,10 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> {
// write the settings to a file
let settings_path = dir.path().join("settings.xml");

let mut settings_settings = vimba::FeaturePersistentSettings::default(); // let's get meta. settings to save the settings.
let settings_settings = vimba::default_feature_persist_settings(); // let's get meta. settings to save the settings.
self.camera
.lock()
.camera_settings_save(&settings_path, &mut settings_settings)
.camera_settings_save(&settings_path, &settings_settings)
.map_vimba_err()?;

let buf = std::fs::read_to_string(&settings_path)?;
Expand Down
9 changes: 6 additions & 3 deletions vimba/examples/features-load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ fn main() -> anyhow::Result<()> {
let cam_id = camera_infos[0].camera_id_string.as_str();
println!("Opening camera {}", cam_id);
let camera = vimba::Camera::open(cam_id, vimba::access_mode::FULL, &lib.vimba_lib)?;

let mut settings_settings = vimba::FeaturePersistentSettings::default(); // let's get meta. settings to load the settings.
// Settings to load the settings. Let's get meta.
let settings_settings = vmbc_sys::VmbFeaturePersistSettings_t {
persistType: vmbc_sys::VmbFeaturePersistType::VmbFeaturePersistNoLUT,
..vimba::default_feature_persist_settings()
};
println!(
" loading settings from: {}",
settings_path.to_string_lossy()
);
camera.camera_settings_load(settings_path, &mut settings_settings)?;
camera.camera_settings_load(settings_path, &settings_settings)?;
}
Ok(())
}
10 changes: 8 additions & 2 deletions vimba/examples/features-save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ fn main() -> anyhow::Result<()> {
let cam_id = camera_infos[0].camera_id_string.as_str();
println!("Opening camera {}", cam_id);
let camera = vimba::Camera::open(cam_id, vimba::access_mode::FULL, &lib.vimba_lib)?;
let mut settings_settings = vimba::FeaturePersistentSettings::default(); // let's get meta. settings to save the settings.
// Settings to save the settings. Let's get meta.
let settings_settings = vmbc_sys::VmbFeaturePersistSettings_t {
persistType: vmbc_sys::VmbFeaturePersistType::VmbFeaturePersistNoLUT,
..vimba::default_feature_persist_settings()
};
let settings_path = format!("{}.xml", cam_id);
println!(" saving settings to: {}", settings_path);
camera.camera_settings_save(settings_path, &mut settings_settings)?;
camera.camera_settings_save(settings_path, &settings_settings)?;
} else {
println!("No camera, nothing to do.");
}
Ok(())
}
34 changes: 14 additions & 20 deletions vimba/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ impl<'lib> Camera<'lib> {
pub fn camera_settings_save<P: AsRef<std::path::Path>>(
&self,
out_path: P,
p_settings: &mut FeaturePersistentSettings,
p_settings: &VmbFeaturePersistSettings_t,
) -> Result<()> {
let mut buf = path_to_bytes(out_path);
buf.push(0);
Expand All @@ -677,7 +677,7 @@ impl<'lib> Camera<'lib> {
vimba_call!(self.vimba_lib.VmbSettingsSave(
self.handle,
buf.as_ptr() as *const i8,
(&mut p_settings.inner) as *mut _,
p_settings as *const _,
sz
))?;
Ok(())
Expand All @@ -686,7 +686,7 @@ impl<'lib> Camera<'lib> {
pub fn camera_settings_load<P: AsRef<std::path::Path>>(
&self,
in_path: P,
p_settings: &mut FeaturePersistentSettings,
p_settings: &VmbFeaturePersistSettings_t,
) -> Result<()> {
let mut buf = path_to_bytes(in_path);
buf.push(0);
Expand All @@ -695,7 +695,7 @@ impl<'lib> Camera<'lib> {
vimba_call!(self.vimba_lib.VmbSettingsLoad(
self.handle,
buf.as_ptr() as *const i8,
(&mut p_settings.inner) as *mut _,
p_settings as *const _,
sz
))?;
Ok(())
Expand All @@ -711,22 +711,16 @@ impl<'lib> Drop for Camera<'lib> {
}
}

pub struct FeaturePersistentSettings {
inner: VmbFeaturePersistSettings_t,
}

impl Default for FeaturePersistentSettings {
fn default() -> Self {
// These values are saved in .xml file from the Vimba Viewer 5.1 GUI.
Self {
inner: VmbFeaturePersistSettings_t {
persistType: vmbc_sys::VmbFeaturePersistType::VmbFeaturePersistNoLUT
as vmbc_sys::VmbFeaturePersist_t,
modulePersistFlags: vmbc_sys::VmbModulePersistFlagsType::VmbModulePersistFlagsNone,
maxIterations: 5,
loggingLevel: 4,
},
}
pub fn default_feature_persist_settings() -> VmbFeaturePersistSettings_t {
// These values are the defaults in vmbpy-1.0.4 from Vimba X in the
// save_settings() and load_settings() function signatures with the
// exception of maxIterations and loggingLevel, which are the values that
// Vimba X viewer seems to use.
VmbFeaturePersistSettings_t {
persistType: vmbc_sys::VmbFeaturePersistType::VmbFeaturePersistStreamable,
modulePersistFlags: vmbc_sys::VmbModulePersistFlagsType::VmbModulePersistFlagsNone,
maxIterations: 10,
loggingLevel: 4,
}
}

Expand Down

0 comments on commit 7dd0a59

Please sign in to comment.