tmp: use sdk (broken)
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
143
src/sdk/error.rs
Normal file
143
src/sdk/error.rs
Normal file
@@ -0,0 +1,143 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum XSdkErrorSeverity {
|
||||
Info,
|
||||
Fatal,
|
||||
}
|
||||
|
||||
impl fmt::Display for XSdkErrorSeverity {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let text = match self {
|
||||
XSdkErrorSeverity::Info => "INFO",
|
||||
XSdkErrorSeverity::Fatal => "FATAL",
|
||||
};
|
||||
write!(f, "{}", text)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum XSdkErrorCode {
|
||||
NoErr,
|
||||
Sequence,
|
||||
Param,
|
||||
InvalidCamera,
|
||||
LoadLib,
|
||||
Unsupported,
|
||||
Busy,
|
||||
ForceModeBusy,
|
||||
AfTimeout,
|
||||
ShootError,
|
||||
FrameFull,
|
||||
Standby,
|
||||
NoDriver,
|
||||
NoModelModule,
|
||||
ApiNotFound,
|
||||
ApiMismatch,
|
||||
InvalidUsbMode,
|
||||
Communication,
|
||||
Timeout,
|
||||
Combination,
|
||||
WriteError,
|
||||
CardFull,
|
||||
Hardware,
|
||||
Internal,
|
||||
MemFull,
|
||||
Unknown,
|
||||
RunningOtherFunction(XSdkErrorDetail),
|
||||
}
|
||||
|
||||
impl XSdkErrorCode {
|
||||
pub fn severity(&self) -> XSdkErrorSeverity {
|
||||
match self {
|
||||
XSdkErrorCode::NoErr => XSdkErrorSeverity::Info,
|
||||
XSdkErrorCode::InvalidCamera
|
||||
| XSdkErrorCode::Busy
|
||||
| XSdkErrorCode::ForceModeBusy
|
||||
| XSdkErrorCode::AfTimeout
|
||||
| XSdkErrorCode::FrameFull
|
||||
| XSdkErrorCode::Standby
|
||||
| XSdkErrorCode::WriteError
|
||||
| XSdkErrorCode::CardFull
|
||||
| XSdkErrorCode::RunningOtherFunction(_) => XSdkErrorSeverity::Info,
|
||||
|
||||
_ => XSdkErrorSeverity::Fatal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for XSdkErrorCode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let text = match self {
|
||||
XSdkErrorCode::NoErr => "No error",
|
||||
XSdkErrorCode::Sequence => "Function call sequence error",
|
||||
XSdkErrorCode::Param => "Function parameter error",
|
||||
XSdkErrorCode::InvalidCamera => "Invalid camera",
|
||||
XSdkErrorCode::LoadLib => "Lower-layer libraries cannot be loaded",
|
||||
XSdkErrorCode::Unsupported => "Unsupported function call",
|
||||
XSdkErrorCode::Busy => "Camera is busy",
|
||||
XSdkErrorCode::ForceModeBusy => {
|
||||
"Camera is busy. XSDK_SetForceMode can be used to recover"
|
||||
}
|
||||
XSdkErrorCode::AfTimeout => "Unable to focus using autofocus",
|
||||
XSdkErrorCode::ShootError => "Error occurred during shooting",
|
||||
XSdkErrorCode::FrameFull => "Frame buffer full; release canceled",
|
||||
XSdkErrorCode::Standby => "System standby",
|
||||
XSdkErrorCode::NoDriver => "No camera found",
|
||||
XSdkErrorCode::NoModelModule => "No library; model-dependent function cannot be called",
|
||||
XSdkErrorCode::ApiNotFound => "Unknown model-dependent function call",
|
||||
XSdkErrorCode::ApiMismatch => "Parameter mismatch for model-dependent function call",
|
||||
XSdkErrorCode::InvalidUsbMode => "Invalid USB mode",
|
||||
XSdkErrorCode::Communication => "Communication error",
|
||||
XSdkErrorCode::Timeout => "Operation timeout for unknown reasons",
|
||||
XSdkErrorCode::Combination => "Function call combination error",
|
||||
XSdkErrorCode::WriteError => "Memory card write error. Memory card must be replaced",
|
||||
XSdkErrorCode::CardFull => {
|
||||
"Memory card full. Memory card must be replaced or formatted"
|
||||
}
|
||||
XSdkErrorCode::Hardware => "Camera hardware error",
|
||||
XSdkErrorCode::Internal => "Unexpected internal error",
|
||||
XSdkErrorCode::MemFull => "Unexpected memory error",
|
||||
XSdkErrorCode::Unknown => "Other unexpected error",
|
||||
XSdkErrorCode::RunningOtherFunction(details) => {
|
||||
&format!("Camera is busy due to another function: {details}")
|
||||
}
|
||||
};
|
||||
|
||||
write!(f, "{text} ({})", self.severity())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum XSdkErrorDetail {
|
||||
S1,
|
||||
AEL,
|
||||
AFL,
|
||||
InstantAF,
|
||||
AFON,
|
||||
Shooting,
|
||||
ShootingCountdown,
|
||||
Recording,
|
||||
LiveView,
|
||||
UntransferredImage,
|
||||
}
|
||||
|
||||
impl fmt::Display for XSdkErrorDetail {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let text = match self {
|
||||
XSdkErrorDetail::S1 => "S1 error (generic placeholder)",
|
||||
XSdkErrorDetail::AEL => "AE is locked",
|
||||
XSdkErrorDetail::AFL => "AF is locked",
|
||||
XSdkErrorDetail::InstantAF => "INSTANT AF in operation",
|
||||
XSdkErrorDetail::AFON => "AF for AF ON in operation",
|
||||
XSdkErrorDetail::Shooting => "Shooting in progress",
|
||||
XSdkErrorDetail::ShootingCountdown => "SELF-TIMER in operation",
|
||||
XSdkErrorDetail::Recording => "Movie is in recording",
|
||||
XSdkErrorDetail::LiveView => "Liveview is in progress",
|
||||
XSdkErrorDetail::UntransferredImage => {
|
||||
"Pictures remain in the in-camera volatile memory"
|
||||
}
|
||||
};
|
||||
write!(f, "{}", text)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user