Skip to content

Commit

Permalink
nreal: switch to hidapi
Browse files Browse the repository at this point in the history
  • Loading branch information
badicsalex committed Apr 7, 2023
1 parent b73bc85 commit 48f7de7
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 182 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -15,11 +15,12 @@ license = "MIT"
[features]
default = ["mad_gaze", "rokid", "nreal"]
rokid = ["rusb"]
nreal = ["rusb", "tinyjson"]
nreal = ["hidapi", "tinyjson"]
mad_gaze = ["serialport"]

[dependencies]
byteorder = "1.4"
hidapi = { version = "2.2.2", optional = true }
rusb = { version = "0.9.1", optional = true }
serialport = { version = "4.2", optional = true }
tinyjson = { version = "2.5.1", optional = true }
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Expand Up @@ -46,11 +46,18 @@ pub enum Error {
/// An rusb error happened. See [`rusb::Error`] for specifics
#[cfg(feature = "rusb")]
UsbError(rusb::Error),
/// A hidapi error happened. See [`hidapi::HidError`] for specifics
#[cfg(feature = "rusb")]
HidError(hidapi::HidError),
/// A serialport error happened. See [`serialport::Error`] for specifics
#[cfg(feature = "serialport")]
SerialPortError(serialport::Error),
/// No glasses were found.
NotFound,
/// Packet sending or reception timed out. Note that this is not the only
/// timeout error that is sent (e.g. UsbError can contain a timeout), and
/// also this is usually a fatal one.
PacketTimeout,
/// The glasses (or one of its devices) were disconnected
Disconnected(&'static str),
/// Other fatal error, usually a problem with the library itself, or
Expand Down Expand Up @@ -156,6 +163,13 @@ impl From<rusb::Error> for Error {
}
}

#[cfg(feature = "hidapi")]
impl From<hidapi::HidError> for Error {
fn from(e: hidapi::HidError) -> Self {
Error::HidError(e)
}
}

#[cfg(feature = "serialport")]
impl From<serialport::Error> for Error {
fn from(e: serialport::Error) -> Self {
Expand Down

0 comments on commit 48f7de7

Please sign in to comment.