Skip to content
Draft
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/input/output_event/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
pub mod native;
pub mod value;

use std::sync::mpsc::Sender;

use ::evdev::{FFEffectData, InputEvent};
use native::NativeOutputEvent;

use crate::drivers::{
dualsense::hid_report::SetStatePackedOutputData,
Expand All @@ -10,8 +14,10 @@ use crate::drivers::{
use super::output_capability::{Haptic, OutputCapability};

/// Output events are events that flow from target devices back to source devices
/// TODO: Remove this in favor of directly using NativeOutputEvent
#[derive(Debug, Clone)]
pub enum OutputEvent {
Native(NativeOutputEvent),
Evdev(InputEvent),
Uinput(UinputOutputEvent),
DualSense(SetStatePackedOutputData),
Expand All @@ -23,6 +29,7 @@ impl OutputEvent {
/// Returns the capability of the output event
fn as_capability(&self) -> Vec<OutputCapability> {
match self {
OutputEvent::Native(event) => todo!(),
OutputEvent::Evdev(event) => match event.destructure() {
evdev::EventSummary::Synchronization(_, _, _) => {
vec![OutputCapability::NotImplemented]
Expand Down
20 changes: 20 additions & 0 deletions src/input/output_event/native.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::input::output_capability::OutputCapability;

use super::value::OutputValue;

#[derive(Debug, Clone)]
pub struct NativeOutputEvent {
capability: OutputCapability,
value: OutputValue,
}

impl NativeOutputEvent {
pub fn new(capability: OutputCapability, value: OutputValue) -> Self {
Self { capability, value }
}

/// Returns the value of this event
pub fn get_value(&self) -> &OutputValue {
&self.value
}
}
55 changes: 55 additions & 0 deletions src/input/output_event/value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use packed_struct::types::SizedInteger;

use crate::{
drivers::steam_deck::hid_report::PackedRumbleReport, input::output_capability::OutputCapability,
};

use super::native::NativeOutputEvent;

#[derive(Debug, Clone)]
pub enum OutputValue {
ForceFeedback(ForceFeedbackValue),
Led,
}

#[derive(Debug, Clone)]
pub enum ForceFeedbackValue {
Magnitude { strong: f64, weak: f64 },
SuperSpecialMegaRumble { x: f64, y: f64, z: f64 },
}

/// Deck -> Native
impl From<PackedRumbleReport> for NativeOutputEvent {
fn from(value: PackedRumbleReport) -> Self {
let capability = OutputCapability::ForceFeedback;
let value = OutputValue::ForceFeedback(ForceFeedbackValue::Magnitude {
strong: value.left_speed.to_primitive() as f64,
weak: value.right_speed.to_primitive() as f64,
});

Self::new(capability, value)
}
}

/// Native -> Deck
impl From<NativeOutputEvent> for PackedRumbleReport {
fn from(event: NativeOutputEvent) -> Self {
// TODO: this conversion
let OutputValue::ForceFeedback(value) = event.get_value() else {
// NOTE: UNABLE TO TRANSLATE!
return Self::default();
};

match value {
ForceFeedbackValue::Magnitude { strong, weak } => todo!(),
ForceFeedbackValue::SuperSpecialMegaRumble { x, y, z } => todo!(),
}

Self {
intensity: 0,
left_speed: Default::default(),
right_speed: Default::default(),
..Default::default()
}
}
}
Loading