use serde::{Deserialize, Serialize};
use thiserror::Error;
use super::backlight::BacklightChange;
use super::dpi::Dpi;
use super::report_rate::ReportRate;
#[derive(Debug, Clone, Error, PartialEq, Eq, Serialize, Deserialize)]
pub enum WriteError {
#[error("HID transport error: {0}")]
Hid(String),
#[error("no connected device matched the route")]
DeviceNotFound,
#[error("device at index {index:#04x} did not respond to HID++")]
DeviceUnreachable {
index: u8,
},
#[error("device does not expose HID++ feature {feature_hex:#06x}")]
FeatureUnsupported {
feature_hex: u16,
},
#[error("device returned no supported DPI values")]
EmptyDpiList,
#[error("HID++ protocol error: {0}")]
Hidpp(String),
#[error("HID++ feature error during {operation:?} for feature {feature_hex:#06x}: {kind:?}")]
HidppFeature {
operation: HidppOperation,
feature_hex: u16,
kind: HidppFeatureErrorKind,
},
#[error("HID++ unsupported response during {operation:?} for feature {feature_hex:#06x}")]
UnsupportedResponse {
operation: HidppOperation,
feature_hex: u16,
},
#[error("HID++ request timed out during {operation:?}")]
RequestTimedOut {
operation: HidppOperation,
},
#[error("tokio runtime init failed: {message}")]
RuntimeInit {
message: String,
},
#[error("background agent is unavailable")]
AgentUnavailable,
#[error("invalid light value for {control}: {value}")]
InvalidLightValue {
control: String,
value: u16,
},
#[error("light control is unsupported: {control}")]
LightUnsupported {
control: String,
},
#[error("multiple raw HID devices matched the route")]
AmbiguousRawDevice,
#[error("DPI {requested} is not one of the device-reported supported values")]
DpiUnsupported {
requested: Dpi,
},
#[error("device reports DPI {actual} after a write of {requested}")]
DpiNotApplied {
requested: Dpi,
actual: Dpi,
},
#[error("device does not advertise haptic waveform {waveform}")]
HapticWaveformUnsupported {
waveform: u8,
},
#[error("report rate {requested} Hz is not one the device lists for this connection")]
ReportRateUnsupported {
requested: ReportRate,
},
#[error("device reports {actual} Hz after a write of {requested} Hz")]
ReportRateNotApplied {
requested: ReportRate,
actual: ReportRate,
},
#[error("the keyboard does not offer {change}")]
BacklightChangeUnsupported {
change: BacklightChange,
},
#[error("keyboard does not report {change} after the write")]
BacklightNotApplied {
change: BacklightChange,
},
#[error("device reports haptic status {status}, so haptics cannot play")]
HapticsUnavailable {
status: u8,
},
#[error("the device does not let software rename its Easy-Switch hosts")]
HostRenameUnsupported,
#[error("Easy-Switch channel {} has no paired computer", u16::from(*slot) + 1)]
HostSlotEmpty {
slot: u8,
},
#[error("a host name must be 1 to {max_len} bytes of UTF-8 without NUL")]
HostNameRejected {
max_len: u8,
},
#[error("device reports host name {actual:?} after a write of {requested:?}")]
HostNameNotApplied {
requested: String,
actual: Option<String>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum HidppOperation {
ResolveFeature,
DumpFeatures,
ReadDpi,
ReadDpiCapabilities,
WriteDpi,
ReadSmartShift,
WriteSmartShift,
Lighting,
ReadWheelMode,
WriteWheelMode,
ReadBacklight,
WriteBacklight,
WriteFnLock,
Light,
PlayHaptic,
ReadFnLock,
ReadPointerScaling,
WritePointerScaling,
WriteOsLayout,
ReadReportRate,
WriteReportRate,
ReadHosts,
RenameHost,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum HidppFeatureErrorKind {
NoError,
Unknown,
InvalidArgument,
OutOfRange,
HwError,
LogitechInternal,
InvalidFeatureIndex,
InvalidFunctionId,
Busy,
Unsupported,
Unrecognized,
}