diff --git a/lighthouse-protocol/src/input/input_event.rs b/lighthouse-protocol/src/input/input_event.rs index a871f3b..c581da3 100644 --- a/lighthouse-protocol/src/input/input_event.rs +++ b/lighthouse-protocol/src/input/input_event.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::Direction; -use super::{EventSource, GamepadEvent, KeyEvent, MidiEvent, MouseEvent, UnknownEvent}; +use super::{EventSource, GamepadEvent, KeyEvent, MidiEvent, MouseEvent, OrientationEvent, UnknownEvent}; /// A user input event, as generated by the new frontend (LUNA). #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] @@ -12,6 +12,7 @@ pub enum InputEvent { Mouse(MouseEvent), Gamepad(GamepadEvent), Midi(MidiEvent), + Orientation(OrientationEvent), #[serde(untagged)] Unknown(UnknownEvent), } @@ -23,6 +24,7 @@ impl InputEvent { InputEvent::Key(KeyEvent { source, .. }) => source, InputEvent::Mouse(MouseEvent { source, .. }) => source, InputEvent::Gamepad(GamepadEvent { source, .. }) => source, + InputEvent::Orientation(OrientationEvent { source, .. }) => source, InputEvent::Midi(MidiEvent { source, .. }) => source, InputEvent::Unknown(UnknownEvent { source, .. }) => source, } @@ -58,7 +60,7 @@ impl InputEvent { mod tests { use serde_json::json; - use crate::{Delta, EventSource, GamepadAxis2DEvent, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, Pos, UnknownEvent, Vec2}; + use crate::{Delta, EventSource, GamepadAxis2DEvent, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, OrientationEvent, Pos, UnknownEvent, Vec2}; #[test] fn key_event() { @@ -180,6 +182,27 @@ mod tests { ); } + #[test] + fn orientation_event() { + assert_eq!( + serde_json::from_value::(json!({ + "type": "orientation", + "source": 1, + "absolute": false, + "alpha": null, + "beta": 3.0, + "gamma": -10.0, + })).unwrap(), + InputEvent::Orientation(OrientationEvent { + source: EventSource::Int(1), + absolute: Some(false), + alpha: None, + beta: Some(3.0), + gamma: Some(-10.0), + }) + ) + } + #[test] fn unknown_event() { assert_eq!( diff --git a/lighthouse-protocol/src/input/mod.rs b/lighthouse-protocol/src/input/mod.rs index be60063..a0435bc 100644 --- a/lighthouse-protocol/src/input/mod.rs +++ b/lighthouse-protocol/src/input/mod.rs @@ -11,6 +11,7 @@ mod legacy_input_event; mod midi_event; mod mouse_button; mod mouse_event; +mod orientation_event; mod unknown_event; pub use event_source::*; @@ -26,4 +27,5 @@ pub use legacy_input_event::*; pub use midi_event::*; pub use mouse_button::*; pub use mouse_event::*; +pub use orientation_event::*; pub use unknown_event::*; diff --git a/lighthouse-protocol/src/input/orientation_event.rs b/lighthouse-protocol/src/input/orientation_event.rs new file mode 100644 index 0000000..f172a40 --- /dev/null +++ b/lighthouse-protocol/src/input/orientation_event.rs @@ -0,0 +1,18 @@ +use serde::{Deserialize, Serialize}; + +use super::EventSource; + +/// A device orientation event. +#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] +pub struct OrientationEvent { + /// The client identifier. + pub source: EventSource, + // /// Whether the device provides absolute orientation data. + pub absolute: Option, + /// The motion of the device around the z-axis, in degrees from 0 (inclusive) to 360 (exclusive). + pub alpha: Option, + /// The motion of the device around the x-axis (front to back motion), in degrees from -180 (inclusive) to 180 (exclusive). + pub beta: Option, + /// The motion of the device around the y-axis (left to right motion), in degrees from -90 (inclusive) to 90 (exclusive). + pub gamma: Option, +}