Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SENSE_HAT_EVDEV_NAME: &[u8; 31] = b"Raspberry Pi Sense HAT Joystick";
/// * `Direction::Down = 108`
/// * `Direction::Left = 105`
/// * `Direction::Up = 106`
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum Direction {
Enter = 28,
Up = 103,
Expand All @@ -58,7 +58,7 @@ impl Direction {
}

/// The action that was executed with the given `Direction`.
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum Action {
Release = 0,
Press = 1,
Expand All @@ -80,9 +80,9 @@ impl Action {
/// `std::time::Duration`, the `Direction`, and the `Action` that were issued by the `JoyStick`.
#[derive(Debug)]
pub struct JoyStickEvent {
timestamp: Duration,
direction: Direction,
action: Action,
pub timestamp: Duration,
pub direction: Direction,
pub action: Action,
}

impl JoyStickEvent {
Expand Down Expand Up @@ -121,9 +121,10 @@ impl JoyStick {
/// Returns a result with a `Vec<JoyStickEvent>`. This function will
/// block the current thread until events are issued by the `JoyStick` device.
pub fn events(&mut self) -> io::Result<Vec<JoyStickEvent>> {
let events: Vec<JoyStickEvent> = self.device
let events: Vec<JoyStickEvent> = self
.device
.events_no_sync()
.map_err(|e| io::Error::from(e))?
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?
.filter(|ev| ev._type == 1)
.map(|ev| {
let secs = ev.time.tv_sec as u64;
Expand Down