dualsense-ts
Version:
The natural interface for your DualSense Classic and DualSense Access controllers, with Typescript
166 lines • 7.38 kB
TypeScript
import { Momentary, Dpad, DpadParams, Mute, Unisense, UnisenseParams, Touchpad, Gyroscope, GyroscopeParams, Accelerometer, AccelerometerParams, Battery, BatteryParams, Lightbar, PlayerLeds, Audio, PowerSaveControl } from "./elements";
import { Input, InputParams } from "./input";
import { DualsenseHID, FirmwareInfo, FactoryInfo, DualsenseColor, ResolvedCalibration } from "./hid";
import { Intensity } from "./math";
import { Orientation, type OrientationParams, ShakeDetector, type ShakeDetectorParams } from "./motion";
/** Settings for your Dualsense controller and each of its inputs */
export interface DualsenseParams extends InputParams {
/** Sets the source for HID events. Default: decide automatically */
hid?: DualsenseHID | null;
/** Settings for the Playstation button */
ps?: InputParams;
/** Settings for the mute button */
mute?: InputParams;
/** Settings for the options button */
options?: InputParams;
/** Settings for the create button */
create?: InputParams;
/** Settings for the triangle button */
triangle?: InputParams;
/** Settings for the circle button */
circle?: InputParams;
/** Settings for the cross button */
cross?: InputParams;
/** Settings for the square button */
square?: InputParams;
/** Settings for the dpad buttons */
dpad?: DpadParams;
/** Settings for inputs on the left half of the controller */
left?: UnisenseParams;
/** Settings for inputs on the right side of the controller */
right?: UnisenseParams;
/** Settings for the touchpad inputs */
touchpad?: InputParams;
/** Settings for the gyroscope */
gyroscope?: GyroscopeParams;
/** Settings for the accelerometer */
accelerometer?: AccelerometerParams;
/** Settings for the battery */
battery?: BatteryParams;
/** Settings for the connection indicator */
connection?: InputParams;
/** Settings for the orientation tracker (Madgwick AHRS) */
orientation?: OrientationParams;
/** Settings for the shake detector */
shake?: ShakeDetectorParams;
}
/** Represents a Dualsense controller */
export declare class Dualsense extends Input<Dualsense> {
readonly state: Dualsense;
/** The Playstation button */
readonly ps: Momentary;
/** The mute button and status light */
readonly mute: Mute;
/** The options button */
readonly options: Momentary;
/** The create button */
readonly create: Momentary;
/** The triangle button */
readonly triangle: Momentary;
/** The circle button */
readonly circle: Momentary;
/** The cross, or X button */
readonly cross: Momentary;
/** The square button */
readonly square: Momentary;
/** The up/down/left/right dpad buttons */
readonly dpad: Dpad;
/** Inputs on the left half of the controller */
readonly left: Unisense;
/** Inputs on the right half of the controller */
readonly right: Unisense;
/** The touchpad; works like a pair of analog sticks */
readonly touchpad: Touchpad;
/** Tracks the controller's angular velocity */
readonly gyroscope: Gyroscope;
/** Tracks the controller's linear acceleration */
readonly accelerometer: Accelerometer;
/** Battery level and charging status */
readonly battery: Battery;
/** Whether a microphone is connected (e.g. headset mic or USB mic) */
readonly microphone: Momentary;
/** Whether headphones are connected to the controller's 3.5mm jack */
readonly headphone: Momentary;
/** The RGB light bar at the top of the controller */
readonly lightbar: Lightbar;
/** The 5 white player indicator LEDs */
readonly playerLeds: PlayerLeds;
/** Audio volume, routing, and microphone controls */
readonly audio: Audio;
/** Per-subsystem power save controls (disable touch, motion, haptics, audio) */
readonly powerSave: PowerSaveControl;
/**
* Fused orientation from Madgwick AHRS sensor fusion.
* Provides pitch, yaw, roll (radians), quaternion, and
* accelerometer-only tilt. Updated automatically each HID report.
*/
readonly orientation: Orientation;
/**
* Shake detector with frequency analysis.
* Provides intensity (0–1), dominant frequency (Hz), and an
* active flag. Updated automatically each HID report.
*/
readonly shake: ShakeDetector;
/** Monotonic sensor timestamp in microseconds from the controller's clock.
* Updated with each input report — useful for correlating motion sensor
* readings with other inputs across frames. Wraps at 2^32 (~71.6 minutes). */
sensorTimestamp: number;
/** Previous sensor timestamp for computing dt (microseconds). */
private prevSensorTimestamp;
/** Active interval timers, cleared on dispose */
private readonly timers;
/**
* Buffered battery reading, sampled on a slow cadence
* Battery readings are prone to flip-flopping, so we buffer them
*/
private readonly pendingBattery;
/** Represents the underlying HID device. Provides input events. */
readonly hid: DualsenseHID;
/**
* Firmware and hardware information.
* Contains sensible defaults until the device reports its actual values.
*/
get firmwareInfo(): FirmwareInfo;
/**
* Factory information (serial number, body color, board revision).
* Contains sensible defaults until the device reports its actual values.
*/
get factoryInfo(): FactoryInfo;
/**
* IMU calibration factors derived from the controller's factory calibration
* data (Feature Report 0x05). Applied automatically to gyroscope and
* accelerometer readings — exposed here for inspection and diagnostics.
*/
get calibration(): ResolvedCalibration;
/** A virtual button representing whether or not a controller is connected */
readonly connection: Momentary;
/** True if any input at all is active or changing */
get active(): boolean;
/** Returns `true` if the controller is connected via Bluetooth */
get wireless(): boolean;
/** Body color of the controller */
get color(): DualsenseColor;
/** Factory-stamped serial number of the controller */
get serialNumber(): string;
constructor(params?: DualsenseParams);
/** Stop all internal timers and release resources. */
dispose(): void;
/** Average rumble strength across both halves of the controller. */
private get rumbleIntensity();
/** Reset adaptive trigger feedback on both sides to the default linear feel */
resetTriggerFeedback(): void;
/**
* Play a built-in test tone via the onboard DSP.
* Works over both USB and Bluetooth. Call `stopTestTone()` to stop.
* @param target Output destination — "speaker" (default) or "headphone"
* @param tone Which tone to play — "1khz" (default), "100hz", or "both"
*/
startTestTone(target?: "speaker" | "headphone", tone?: "1khz" | "100hz" | "both"): Promise<void>;
/** Stop the DSP test tone */
stopTestTone(): Promise<void>;
/** Check or adjust rumble intensity evenly across both sides of the controller */
rumble(intensity?: Intensity): number;
/** Distributes HID event values to the controller's public inputs. */
private processHID;
}
//# sourceMappingURL=dualsense.d.ts.map