dualsense-ts
Version:
The natural interface for your DualSense Classic and DualSense Access controllers, with Typescript
102 lines • 3.91 kB
TypeScript
/**
* IMU calibration data from Feature Report 0x05.
*
* The DualSense stores per-unit factory calibration for the gyroscope and
* accelerometer. Reading and applying these offsets and scale factors
* removes bias drift and normalises per-axis sensitivity, giving more
* accurate motion data than the hardcoded mapping.
*
* Layout mirrors the Linux kernel hid-playstation.c interpretation of
* Feature Report 0x05 (41 bytes including the report-ID prefix).
*/
import type { HIDProvider } from "./hid_provider";
/** Per-axis calibration parameters for one gyro axis */
export interface GyroAxisCalibration {
/** Resting-state bias (raw int16 counts) */
bias: number;
/** Raw count at +reference rotation rate */
plus: number;
/** Raw count at −reference rotation rate */
minus: number;
}
/** Per-axis calibration parameters for one accelerometer axis */
export interface AccelAxisCalibration {
/** Raw count at +1 g */
plus: number;
/** Raw count at −1 g */
minus: number;
}
/** Full IMU calibration data parsed from Feature Report 0x05 */
export interface IMUCalibration {
gyro: {
pitch: GyroAxisCalibration;
yaw: GyroAxisCalibration;
roll: GyroAxisCalibration;
/** Reference rotation-rate magnitude (positive direction) */
speedPlus: number;
/** Reference rotation-rate magnitude (negative direction) */
speedMinus: number;
};
accel: {
x: AccelAxisCalibration;
y: AccelAxisCalibration;
z: AccelAxisCalibration;
};
}
/** Precomputed bias + scale for a single axis */
export interface AxisCalibrationFactors {
/** Value to subtract from the raw int16 */
bias: number;
/** Multiplier: calibrated = (raw − bias) × scale, then clamp to [−1, 1] */
scale: number;
}
/**
* Precomputed calibration factors for all six IMU axes.
*
* Per-sample application: `calibrated = clamp((raw − bias) × scale, −1, 1)`
*/
export interface ResolvedCalibration {
gyroPitch: AxisCalibrationFactors;
gyroYaw: AxisCalibrationFactors;
gyroRoll: AxisCalibrationFactors;
accelX: AxisCalibrationFactors;
accelY: AxisCalibrationFactors;
accelZ: AxisCalibrationFactors;
}
/** Identity calibration: zero bias, uniform 1/32767 scale */
export declare const DefaultResolvedCalibration: ResolvedCalibration;
/**
* Parse Feature Report 0x05 into an {@link IMUCalibration}.
*
* The report may or may not include the report-ID byte as the first
* element depending on platform — the parser auto-detects.
*/
export declare function parseIMUCalibration(buf: Uint8Array): IMUCalibration;
/**
* Precompute per-axis bias and scale from raw calibration data.
*
* **Gyroscope:** Removes resting-state bias and normalises per-axis
* sensitivity so that the same physical rotation rate produces the same
* numeric value on all three axes. The most-sensitive axis (largest
* raw range) maps exactly to [-1, 1] at full scale; less-sensitive
* axes are boosted to match, with ≤ 4% clipping at extreme values.
*
* **Accelerometer:** Removes the zero-point offset (manufacturing
* tolerance) and normalises per-axis sensitivity the same way.
*/
export declare function resolveCalibration(cal: IMUCalibration): ResolvedCalibration;
/**
* Read and parse IMU calibration from a connected controller.
* Returns undefined if the report cannot be read.
*/
export declare function readIMUCalibration(provider: HIDProvider): Promise<IMUCalibration | undefined>;
/**
* Assemble two raw report bytes into a signed int16.
*/
export declare function rawInt16(lo: number, hi: number): number;
/**
* Apply precomputed calibration to a single axis sample.
* `calibrated = clamp((raw − bias) × scale, −1, 1)`
*/
export declare function applyCal(raw: number, factors: AxisCalibrationFactors): number;
//# sourceMappingURL=calibration.d.ts.map