Skip to content

Commit

Permalink
Merge pull request #60 from KaiseiYokoyama/dev/0.6.0
Browse files Browse the repository at this point in the history
Dev/0.6.0
  • Loading branch information
KaiseiYokoyama authored Jun 6, 2020
2 parents ecfce8e + abb9c04 commit 72cfee7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "joycon-rs"
version = "0.5.6"
version = "0.6.0"
authors = ["Kaisei Yokoyama <[email protected]>"]
repository = "https://github.com/KaiseiYokoyama/joycon-rs"
edition = "2018"
Expand All @@ -17,6 +17,10 @@ exclude = ["/images/*"]
hidapi-alt-for-hidapi-issue-127 = "1.2.1"
crossbeam-channel = "0.4.2"
lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] , optional = true }

[features]
use_serde = ["serde"]

[dev-dependencies]
doc-comment = "0.3.3"
Expand Down
17 changes: 15 additions & 2 deletions src/joycon/driver/input_report_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod common {
use std::convert::TryFrom;

/// Battery level
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub enum BatteryLevel {
Empty,
Expand All @@ -44,6 +45,7 @@ mod common {
}

/// Battery info
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
pub struct Battery {
pub level: BatteryLevel,
Expand Down Expand Up @@ -72,13 +74,15 @@ mod common {
}

/// Device info
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
pub enum Device {
JoyCon,
ProConOrChargingGrip,
}

/// Connection info
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
pub struct ConnectionInfo {
pub device: Device,
Expand All @@ -104,6 +108,7 @@ mod common {
}

/// Button status
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub struct PushedButtons {
pub right: Vec<Buttons>,
Expand Down Expand Up @@ -191,6 +196,7 @@ mod common {
}

/// Analog stick data
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub struct AnalogStickData {
pub horizontal: u16,
Expand All @@ -210,6 +216,7 @@ mod common {
}

/// Common parts of the standard input report
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub struct CommonReport {
pub input_report_id: u8,
Expand Down Expand Up @@ -303,6 +310,7 @@ pub trait InputReportMode<D: JoyConDriver>: Sized {
fn into_driver(self) -> D;
}

#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
/// Standard input report with extra report.
pub struct StandardInputReport<EX: TryFrom<[u8; 349], Error=JoyConError>> {
pub common: CommonReport,
Expand Down Expand Up @@ -537,6 +545,7 @@ pub mod standard_full_mode {
use super::*;

/// IMU(6-Axis sensor)'s value.
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AxisData {
/// Acceleration to X measured
Expand Down Expand Up @@ -575,6 +584,7 @@ pub mod standard_full_mode {
}

/// 6-Axis data. 3 frames of 2 groups of 3 Int16LE each. Group is Acc followed by Gyro.
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct IMUData {
pub data: [AxisData; 3]
Expand Down Expand Up @@ -712,6 +722,7 @@ pub mod simple_hid_mode {
use super::*;

#[allow(non_camel_case_types)]
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
pub enum SimpleHIDButton {
Down,
Expand Down Expand Up @@ -740,6 +751,7 @@ pub mod simple_hid_mode {
};

/// Hold your controller sideways so that SL, SYNC, and SR line up with the screen. Pushing the stick towards a direction in this table will cause that value to be sent.
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
pub enum StickDirection {
Up,
Expand Down Expand Up @@ -777,12 +789,13 @@ pub mod simple_hid_mode {
}

/// Pushed buttons and stick direction.
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct SimpleHIDReport {
pub input_report_id: u8,
pub pushed_buttons: Vec<SimpleHIDButton>,
pub stick_direction: StickDirection,
pub filter_data: [u8; 8],
pub filler_data: [u8; 8],
}

impl TryFrom<[u8; 12]> for SimpleHIDReport {
Expand Down Expand Up @@ -826,7 +839,7 @@ pub mod simple_hid_mode {
input_report_id,
pushed_buttons,
stick_direction,
filter_data,
filler_data: filter_data,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions src/joycon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub use manager::{JoyConManager, JOYCON_RECEIVER};
use std::sync::Arc;
use std::fmt::{Debug, Formatter};

#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
pub enum Buttons {
A,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ extern crate doc_comment;
doctest!("../README.md");

pub mod prelude {
#[cfg(feature = "use_serde")]
pub(crate) use serde::{Serialize, Deserialize};
pub use hidapi::*;
pub use crossbeam_channel;
pub use crate::result::*;
Expand Down

0 comments on commit 72cfee7

Please sign in to comment.