/*
DS5State.h is part of DualSenseWindows
https://github.com/mattdevv/DualSense-Windows
Contributors of this file:
11.2021 mattdevv
11.2020 Ludwig Füchsl
Licensed under the MIT License (To be found in repository root directory)
*/
#pragma once
// DPAD buttons
#define DS5W_ISTATE_BTN_DPAD_LEFT 0x01
#define DS5W_ISTATE_BTN_DPAD_DOWN 0x02
#define DS5W_ISTATE_BTN_DPAD_RIGHT 0x04
#define DS5W_ISTATE_BTN_DPAD_UP 0x08
// Face buttons
#define DS5W_ISTATE_BTN_SQUARE 0x10
#define DS5W_ISTATE_BTN_CROSS 0x20
#define DS5W_ISTATE_BTN_CIRCLE 0x40
#define DS5W_ISTATE_BTN_TRIANGLE 0x80
// Shoulder buttons
#define DS5W_ISTATE_BTN_BUMPER_LEFT 0x0100
#define DS5W_ISTATE_BTN_BUMPER_RIGHT 0x0200
#define DS5W_ISTATE_BTN_TRIGGER_LEFT 0x0400
#define DS5W_ISTATE_BTN_TRIGGER_RIGHT 0x0800
// Menu buttons
#define DS5W_ISTATE_BTN_SELECT 0x1000
#define DS5W_ISTATE_BTN_MENU 0x2000
// Stick buttons
#define DS5W_ISTATE_BTN_STICK_LEFT 0x4000
#define DS5W_ISTATE_BTN_STICK_RIGHT 0x8000
// Extra buttons
#define DS5W_ISTATE_BTN_PLAYSTATION_LOGO 0x010000
#define DS5W_ISTATE_BTN_PAD_BUTTON 0x020000
#define DS5W_ISTATE_BTN_MIC_BUTTON 0x040000
#define DS5W_OSTATE_PLAYER_LED_LEFT 0x01
#define DS5W_OSTATE_PLAYER_LED_MIDDLE_LEFT 0x02
#define DS5W_OSTATE_PLAYER_LED_MIDDLE 0x04
#define DS5W_OSTATE_PLAYER_LED_MIDDLE_RIGHT 0x08
#define DS5W_OSTATE_PLAYER_LED_RIGHT 0x10
namespace DS5W {
///
/// Analog stick
///
typedef struct _AnalogStick {
///
/// X Position of stick (0 = Center)
///
char x;
///
/// Y Posistion of stick (0 = Center)
///
char y;
} AnalogStick;
///
/// 3 Component vector
///
typedef struct _Vec3 {
int x;
int y;
int z;
} Vector3, Vec3;
///
/// RGB Color
///
typedef struct _Color {
unsigned char r;
unsigned char g;
unsigned char b;
} Color;
///
/// Touchpad state
///
typedef struct _Touch {
///
/// X positon of finger (0 - 1920)
///
unsigned int x;
///
/// Y position of finger (0 - 1080)
///
unsigned int y;
///
/// Touch is down
///
bool down;
///
/// 7-bit ID for touch
///
unsigned char id;
} Touch;
typedef struct _Battery {
///
/// Charching state of the battery
///
bool charging;
///
/// Indicates that the battery is fully charged
///
bool fullyCharged;
///
/// Battery charge level 0x0 to
///
unsigned char level;
} Battery;
///
/// State of the mic led
///
typedef enum class _MicLed : unsigned char{
///
/// Lef is off
///
OFF = 0x00,
///
/// Led is on
///
ON = 0x01,
///
/// Led is pulsing
///
PULSE = 0x02,
} MicLed;
///
/// Type of trigger effect
///
typedef enum class _TriggerEffectType : unsigned char {
///
/// Disable all effects (after trigger is released)
///
NoResitance = 0x00,
///
/// Continuous Resitance is applied
///
ContinuousResitance = 0x01,
///
/// Seciton resistance is applied
///
SectionResitance = 0x02,
///
/// Disable all effects and release any active tension
///
ReleaseAll = 0x05,
///
/// Extended trigger effect
///
EffectEx = 0x26,
///
/// Calibrate triggers
///
Calibrate = 0xFC,
} TriggerEffectType;
///
/// Trigger effect
///
typedef struct _TriggerEffect {
///
/// Trigger effect type
///
TriggerEffectType effectType;
///
/// Union for effect parameters
///
union {
///
/// Union one raw data
///
unsigned char _u1_raw[10];
///
/// For type == ContinuousResitance
///
struct {
///
/// Start position of resistance
///
unsigned char startPosition;
///
/// Force of resistance
///
unsigned char force;
///
/// PAD / UNUSED
///
unsigned char _pad[8];
} Continuous;
///
/// For type == SectionResitance
///
struct {
///
/// Start position of resistance
///
unsigned char startPosition;
///
/// End position of resistance (>= start)
///
unsigned char endPosition;
///
/// PAD / UNUSED
///
unsigned char _pad[8];
} Section;
///
/// For type == EffectEx
///
struct {
///
/// Position at witch the effect starts
///
unsigned char startPosition;
///
/// Wher the effect should keep playing when trigger goes beyond 255
///
bool keepEffect;
///
/// Force applied when trigger >= (255 / 2)
///
unsigned char beginForce;
///
/// Force applied when trigger <= (255 / 2)
///
unsigned char middleForce;
///
/// Force applied when trigger is beyond 255
///
unsigned char endForce;
///
/// Vibration frequency of the trigger
///
unsigned char frequency;
///
/// PAD / UNUSED
///
unsigned char _pad[4];
} EffectEx;
};
} TriggerEffect;
///
/// Led brightness
///
typedef enum _LedBrightness : unsigned char {
///
/// Low led brightness
///
LOW = 0x02,
///
/// Medium led brightness
///
MEDIUM = 0x01,
///
/// High led brightness
///
HIGH = 0x00,
} LedBrightness;
///
/// Player leds values
///
typedef struct _PlayerLeds {
///
/// Player indication leds bitflag (You may used them for other features) DS5W_OSTATE_PLAYER_LED_???
///
unsigned char bitmask;
///
/// Indicates weather the player leds should fade in
///
bool playerLedFade;
///
/// Brightness of the player leds
///
LedBrightness brightness;
} PlayerLeds;
///
/// Flags used by DualSense controller to identify changes output report will perform
///
typedef enum class _OutputFlags : unsigned short
{
SetMainMotorsA = 1 << 0, // Allow changing controller haptics. Also requires SetMainMotorsB flag
SetMainMotorsB = 1 << 1, // Allow changing controller haptics. Also requires SetMainMotorsA flag
SetTriggerMotorsA = 1 << 2, // Allow changing trigger haptics. Also requires SetTriggerMotorsB flag
SetTriggerMotorsB = 1 << 3, // Allow changing trigger haptics. Also requires SetTriggerMotorsA flag
SetAudioVolume = 1 << 4, // Enable modification of audio volume
EnableAudio = 1 << 5, // Enable internal speaker (even while headset is connected)
SetMicrophoneVolume = 1 << 6, // Enable modification of microphone volume
EnableMicrophone = 1 << 7, // Enable internal mic (even while headset is connected)
SetMicrophoneLED = 1 << 8, // Allow changing microphone LED state
SetAudioMicMute = 1 << 9, // Set microphone to mute when flag is on?
SetColorLED = 1 << 10, // Allow changing lightbar RGB value
DisableAllLED = 1 << 11, // Turn off all lights while flag is set
SetPlayerLED = 1 << 12, // Allow changing which player LEDs are enabled
UnknownFlag1 = 1 << 13, // ?
SetMotorStrength = 1 << 14, // Allow changing rumble strength
UnknownFlag2 = 1 << 15, // ?
} OutputFlags;
///
/// Default output flags to allow changing all settings other than audio/microphone
///
const unsigned short DefaultOutputFlags =
(unsigned short)OutputFlags::SetMainMotorsA |
(unsigned short)OutputFlags::SetMainMotorsB |
(unsigned short)OutputFlags::SetTriggerMotorsA |
(unsigned short)OutputFlags::SetTriggerMotorsB |
(unsigned short)OutputFlags::SetMicrophoneLED |
(unsigned short)OutputFlags::SetAudioMicMute |
(unsigned short)OutputFlags::SetColorLED |
(unsigned short)OutputFlags::SetPlayerLED |
(unsigned short)OutputFlags::UnknownFlag1 |
(unsigned short)OutputFlags::SetMotorStrength |
(unsigned short)OutputFlags::UnknownFlag2;
///
/// Input state of the controler
///
typedef struct _DS5InputState {
///
/// Position of left stick
///
AnalogStick leftStick;
///
/// Posisiton of right stick
///
AnalogStick rightStick;
///
/// bitflags of buttons, (face | btnsA | btnsB), final 13 bits are empty
///
unsigned int buttonMap;
///
/// Left trigger position
///
unsigned char leftTrigger;
///
/// Right trigger position
///
unsigned char rightTrigger;
///
/// Accelerometer
///
Vector3 accelerometer;
///
/// Gyroscope (Currently only raw values will be dispayed! Probably needs calibration (Will be done within the lib in the future))
///
Vector3 gyroscope;
///
/// First touch point
///
Touch touchPoint1;
///
/// Second touch point
///
Touch touchPoint2;
///
/// Sensor timestamp in 0.33 microseconds
///
unsigned int currentTime;
///
/// Time since last input report. Measured in 0.33 microseconds
///
unsigned int deltaTime;
///
/// Battery information
///
Battery battery;
///
/// Indicates the connection of headphone
///
bool headPhoneConnected;
///
/// EXPERIMAENTAL: Feedback of the left adaptive trigger (only when trigger effect is active)
///
unsigned char leftTriggerFeedback;
///
/// EXPERIMAENTAL: Feedback of the right adaptive trigger (only when trigger effect is active)
///
unsigned char rightTriggerFeedback;
} DS5InputState;
typedef struct _DS5OutputState {
///
/// Left / Hard rumbel motor
///
unsigned char leftRumble;
///
/// Right / Soft rumbel motor
///
unsigned char rightRumble;
///
/// strength of rumble motors in 12.5% steps
/// lower nibble (bits 0-3) main rumbles
/// uppper nibble (bits 4-7) trigger rumbles
///
unsigned char rumbleStrength;
///
/// State of the microphone led
///
MicLed microphoneLed;
///
/// Diables all leds
///
bool disableLeds;
///
/// Player leds
///
PlayerLeds playerLeds;
///
/// Color of the lightbar
///
Color lightbar;
///
/// Effect of left trigger
///
TriggerEffect leftTriggerEffect;
///
/// Effect of right trigger
///
TriggerEffect rightTriggerEffect;
} DS5OutputState;
}