Skip to main content

dualsense_tools/state/
values.rs

1/// Represents the value of an axis in a Dualsense controller
2#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)]
3pub struct DualsenseAxisValue(u8);
4
5impl DualsenseAxisValue {
6    pub fn as_u8(&self) -> u8 {
7        self.0
8    }
9}
10
11impl From<DualsenseAxisValue> for u8 {
12    fn from(val: DualsenseAxisValue) -> Self {
13        val.as_u8()
14    }
15}
16
17impl From<u8> for DualsenseAxisValue {
18    fn from(value: u8) -> Self {
19        DualsenseAxisValue(value)
20    }
21}
22
23/// Represents the value of a sensor (accelerometer/gyroscope)
24/// in a Dualsense controller
25#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)]
26pub struct DualsenseSensorValue(i16);
27
28impl From<i16> for DualsenseSensorValue {
29    fn from(value: i16) -> Self {
30        DualsenseSensorValue(value)
31    }
32}
33
34impl From<DualsenseSensorValue> for f32 {
35    fn from(val: DualsenseSensorValue) -> Self {
36        val.0 as f32
37    }
38}