chore: refactor ptp handling
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,28 +1,52 @@
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::{
|
||||
error::Error,
|
||||
sync::atomic::{AtomicU32, Ordering},
|
||||
};
|
||||
|
||||
use rusb::GlobalContext;
|
||||
|
||||
use super::{CameraId, CameraImpl};
|
||||
|
||||
pub const FUJIFILM_XT5: CameraId = CameraId {
|
||||
name: "FUJIFILM XT-5",
|
||||
vendor: 0x04cb,
|
||||
product: 0x02fc,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FujifilmXT5 {
|
||||
device: rusb::Device<GlobalContext>,
|
||||
session_counter: AtomicU32,
|
||||
}
|
||||
|
||||
impl FujifilmXT5 {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
session_counter: AtomicU32::new(1),
|
||||
}
|
||||
pub fn new_boxed(
|
||||
rusb_device: rusb::Device<GlobalContext>,
|
||||
) -> Result<Box<dyn CameraImpl>, Box<dyn Error + Send + Sync>> {
|
||||
let session_counter = AtomicU32::new(1);
|
||||
|
||||
let handle = rusb_device.open()?;
|
||||
let device = handle.device();
|
||||
|
||||
Ok(Box::new(Self {
|
||||
session_counter,
|
||||
device,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl CameraImpl for FujifilmXT5 {
|
||||
fn name(&self) -> &'static str {
|
||||
"FUJIFILM X-T5"
|
||||
fn id(&self) -> &'static CameraId {
|
||||
&FUJIFILM_XT5
|
||||
}
|
||||
|
||||
fn usb_id(&self) -> String {
|
||||
let bus = self.device.bus_number();
|
||||
let address = self.device.address();
|
||||
format!("{}.{}", bus, address)
|
||||
}
|
||||
|
||||
fn ptp(&self) -> libptp::Camera<rusb::GlobalContext> {
|
||||
libptp::Camera::new(&self.device).unwrap()
|
||||
}
|
||||
|
||||
fn next_session_id(&self) -> u32 {
|
||||
|
||||
Reference in New Issue
Block a user