pub mod dualsense_calibration {
pub const ACCEL_RANGE: f32 = 16384.0;
pub const GYRO_RANGE: f32 = 1024.0;
#[must_use]
pub fn accel_to_ms2(raw: i16) -> f32 {
const G: f32 = 9.81; (f32::from(raw) / ACCEL_RANGE) * 8.0 * G
}
#[must_use]
pub fn gyro_to_rads(raw: i16) -> f32 {
const DEG_TO_RAD: f32 = std::f32::consts::PI / 180.0;
(f32::from(raw) / GYRO_RANGE) * 2000.0 * DEG_TO_RAD
}
}
pub mod dualshock4_calibration {
pub const ACCEL_RANGE: f32 = 16384.0;
pub const GYRO_RANGE: f32 = 1024.0;
#[must_use]
pub fn accel_to_ms2(raw: i16) -> f32 {
const G: f32 = 9.81;
(f32::from(raw) / ACCEL_RANGE) * 8.0 * G
}
#[must_use]
pub fn gyro_to_rads(raw: i16) -> f32 {
const DEG_TO_RAD: f32 = std::f32::consts::PI / 180.0;
(f32::from(raw) / GYRO_RANGE) * 2000.0 * DEG_TO_RAD
}
}
pub mod dualshock3_calibration {
pub const SIXAXIS_MID: i16 = 0x0200;
pub const ACCEL_SCALE: f32 = 113.0;
#[must_use]
pub fn accel_to_ms2(raw: i16) -> f32 {
const G: f32 = 9.81;
let centered = raw - SIXAXIS_MID;
(f32::from(centered) / ACCEL_SCALE) * G
}
#[must_use]
pub fn be_bytes_to_i16(bytes: [u8; 2]) -> i16 {
i16::from_be_bytes(bytes)
}
}
pub mod switch_calibration {
pub const GYRO_SENSITIVITY: f32 = 13371.0;
pub const ACCEL_SENSITIVITY: f32 = 4096.0;
#[must_use]
pub fn gyro_to_rads(raw: i16) -> f32 {
const DEG_TO_RAD: f32 = std::f32::consts::PI / 180.0;
(f32::from(raw) / GYRO_SENSITIVITY) * DEG_TO_RAD
}
#[must_use]
pub fn accel_to_ms2(raw: i16) -> f32 {
const G: f32 = 9.81;
(f32::from(raw) / ACCEL_SENSITIVITY) * G
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct MotionData {
pub gyro_pitch: f32,
pub gyro_yaw: f32,
pub gyro_roll: f32,
pub accel_x: f32,
pub accel_y: f32,
pub accel_z: f32,
}
pub trait MotionBackend {
fn poll(&mut self) -> Option<MotionData>;
fn is_connected(&self) -> bool;
fn name(&self) -> &'static str;
}
#[derive(Debug, Clone, Copy, Default)]
pub struct TouchpadFinger {
pub active: bool,
pub x: f32,
pub y: f32,
pub id: u8,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct TouchpadData {
pub finger1: TouchpadFinger,
pub finger2: TouchpadFinger,
pub button_pressed: bool,
}
pub trait TouchpadBackend {
fn poll(&mut self) -> Option<TouchpadData>;
fn supports_multitouch(&self) -> bool;
fn name(&self) -> &'static str;
}