summaryrefslogtreecommitdiff
path: root/hid
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2017-03-27 23:32:24 -0700
committerDaniel Mueller <deso@posteo.net>2017-03-27 23:32:24 -0700
commitfdd34d1ac10e37b3e0683a3c716665f50684596b (patch)
treee67fe42feabaf928d0f4c9d07037bea3ceca08fe /hid
parent1e9627ad412f364f3c5f556c5bb2ca2bb076d06d (diff)
downloadnitrocli-fdd34d1ac10e37b3e0683a3c716665f50684596b.tar.gz
nitrocli-fdd34d1ac10e37b3e0683a3c716665f50684596b.tar.bz2
Update hid crate to version 0.4.0
The 'hid' crate got a couple of bug fixes, at least one of which we require in order to retrieve HID feature reports correctly. This patch imports the new state and bumps up the library version used. Import subrepo hid/:hid at 52b47d78c17b876194e4b4a1c0c8ae8adfb3d39c
Diffstat (limited to 'hid')
-rw-r--r--hid/Cargo.toml2
-rw-r--r--hid/src/handle.rs43
2 files changed, 21 insertions, 24 deletions
diff --git a/hid/Cargo.toml b/hid/Cargo.toml
index 13a7d49..91111a4 100644
--- a/hid/Cargo.toml
+++ b/hid/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "hid"
-version = "0.3.0"
+version = "0.4.0"
authors = ["meh. <meh@schizofreni.co>"]
license = "WTFPL"
diff --git a/hid/src/handle.rs b/hid/src/handle.rs
index 280bdcf..759c87e 100644
--- a/hid/src/handle.rs
+++ b/hid/src/handle.rs
@@ -29,11 +29,11 @@ impl Handle {
impl Handle {
/// Set the handle in blocking or non-blocking mode.
- pub fn blocking(&mut self, value: bool) -> error::Result<()> {
+ pub fn blocking(&mut self, value: bool) -> error::Result<&mut Self> {
unsafe {
match hid_set_nonblocking(self.as_mut_ptr(), if value { 1 } else { 0 }) {
0 =>
- Ok(()),
+ Ok(self),
_ =>
Err(Error::General)
@@ -87,10 +87,10 @@ impl<'a> Data<'a> {
/// Write data to the device with the given report ID.
pub fn write_to<T: AsRef<[u8]>>(&mut self, id: u8, data: T) -> error::Result<usize> {
let data = data.as_ref();
- let mut buffer = Vec::with_capacity(data.len() + 1);
+ let mut buffer = vec![0u8; data.len() + 1];
- buffer.push(id);
- buffer.extend(data);
+ buffer[0] = id;
+ (&mut buffer[1 ..]).copy_from_slice(data);
self.write(&buffer)
}
@@ -134,16 +134,13 @@ impl<'a> Data<'a> {
let mut data = data.as_mut();
let mut buffer = Vec::with_capacity(data.len() + 1);
- match try!(self.read(&mut buffer, timeout)) {
- None => {
- Ok(None)
- }
-
- Some(length) => {
- data.clone_from_slice(&buffer[1..length]);
+ if let Some(length) = self.read(&mut buffer, timeout)? {
+ data[0..length - 1].copy_from_slice(&buffer[1..length]);
- Ok(Some((data[0], length - 1)))
- }
+ Ok(Some((buffer[0], length - 1)))
+ }
+ else {
+ Ok(None)
}
}
}
@@ -190,7 +187,7 @@ impl<'a> Feature<'a> {
/// Get a feature request.
///
/// The first byte must be the report ID.
- pub fn get<T: AsMut<[u8]>>(&mut self, mut data: T) -> error::Result<Option<usize>> {
+ pub fn get<T: AsMut<[u8]>>(&mut self, mut data: T) -> error::Result<usize> {
let data = data.as_mut();
unsafe {
@@ -198,22 +195,22 @@ impl<'a> Feature<'a> {
-1 =>
Err(Error::Read),
- 0 =>
- Ok(None),
-
- v =>
- Ok(Some(v as usize))
+ length =>
+ Ok(length as usize)
}
}
}
/// Get a feature request from the given report ID.
- pub fn get_from<T: AsMut<[u8]>>(&mut self, id: u8, mut data: T) -> error::Result<Option<usize>> {
+ pub fn get_from<T: AsMut<[u8]>>(&mut self, id: u8, mut data: T) -> error::Result<usize> {
let data = data.as_mut();
let mut buffer = vec![0u8; data.len() + 1];
-
buffer[0] = id;
- self.get(&mut buffer)
+
+ let length = self.get(&mut buffer)?;
+ data[0..length - 1].copy_from_slice(&buffer[1..length]);
+
+ Ok(length - 1)
}
}