/* Device.h is part of DualSenseWindows https://github.com/mattdevv/DualSense-Windows Contributors of this file: 11.2021 Matthew Hall 11.2020 Ludwig Füchsl Licensed under the MIT License (To be found in repository root directory) */ #pragma once #include #include // more accurate integer multiplication by a fraction constexpr int mult_frac(int x, int numer, int denom) { int quot = x / denom; int rem = x % denom; return quot * numer + (rem * numer) / denom; } namespace DS5W { /// /// Storage for calibration values used to parse raw motion data /// typedef struct _AxisCalibrationData { short bias; int sens_numer; int sens_denom; int calibrate(int rawValue) { return mult_frac(sens_numer, rawValue - bias, sens_denom); } } AxisCalibrationData; typedef struct _DeviceCalibrationData { /// /// Values to calibrate controller's accelerometer and gyroscope /// AxisCalibrationData accelerometer[3]; /// /// Values to calibrate controller's gyroscope /// AxisCalibrationData gyroscope[3]; } DeviceCalibrationData; /// /// Enum for device connection type /// typedef enum class _DeviceConnection : unsigned char { /// /// Controler is connected via USB /// USB = 0, /// /// Controler is connected via bluetooth /// BT = 1, } DeviceConnection; /// /// Struckt for storing device enum info while device discovery /// typedef struct _DeviceEnumInfo { /// /// Encapsulate data in struct to (at least try) prevent user from modifing the context /// struct { /// /// Path to the discovered device /// wchar_t path[260]; /// /// Connection type of the discoverd device /// DeviceConnection connection; /// /// Unique device identifier /// 32-bit hash of device interface's path /// UINT32 uniqueID; } _internal; } DeviceEnumInfo; /// /// Device context /// typedef struct _DeviceContext { /// /// Encapsulate data in struct to (at least try) prevent user from modifing the context /// struct { /// /// Path to the device /// wchar_t devicePath[260]; /// /// Unique device identifier /// 32-bit hash of device interface's path /// UINT32 uniqueID; /// /// Handle to the open device /// HANDLE deviceHandle; /// /// Synchronization struct for async input /// OVERLAPPED olRead; /// /// Synchronization struct for async output /// OVERLAPPED olWrite; /// /// Connection of the device /// DeviceConnection connectionType; /// /// Collection of values required to parse controller's motion data /// DeviceCalibrationData calibrationData; /// /// Time when last input report was received, measured in 0.33 microseconds /// unsigned int timestamp; /// /// Current state of connection /// bool connected; /// /// HID Input buffer /// unsigned char hidInBuffer[DS_MAX_INPUT_REPORT_SIZE]; /// /// HID Output buffer /// unsigned char hidOutBuffer[DS_MAX_OUTPUT_REPORT_SIZE]; }_internal; } DeviceContext; }