mirror of
https://github.com/nefarius/ViGEmBus.git
synced 2025-08-10 00:52:17 +00:00
Reworked native API for extended DS4 report
This commit is contained in:
@@ -380,15 +380,13 @@ extern "C" {
|
||||
* @author Benjamin "Nefarius" H<>glinger-Stelzer
|
||||
* @date 07.09.2020
|
||||
*
|
||||
* @param vigem The driver connection object.
|
||||
* @param target The target device object.
|
||||
* @param report The report buffer.
|
||||
* @param reportLength Length of the report buffer.
|
||||
* @param vigem The driver connection object.
|
||||
* @param target The target device object.
|
||||
* @param report The report buffer.
|
||||
*
|
||||
* @returns A VIGEM_ERROR.
|
||||
*/
|
||||
VIGEM_API VIGEM_ERROR vigem_target_ds4_update_ex(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PUCHAR report,
|
||||
ULONG reportLength);
|
||||
VIGEM_API VIGEM_ERROR vigem_target_ds4_update_ex(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, DS4_REPORT_EX report);
|
||||
|
||||
/**
|
||||
* Returns the internal index (serial number) the bus driver assigned to the provided
|
||||
|
||||
@@ -200,3 +200,57 @@ VOID FORCEINLINE DS4_REPORT_INIT(
|
||||
DS4_SET_DPAD(Report, DS4_BUTTON_DPAD_NONE);
|
||||
}
|
||||
|
||||
#include <pshpack1.h> // pack structs tightly
|
||||
//
|
||||
// DualShock 4 HID Touchpad structure
|
||||
//
|
||||
typedef struct _DS4_TOUCH
|
||||
{
|
||||
BYTE bPacketCounter; // timestamp / packet counter associated with touch event
|
||||
BYTE bIsUpTrackingNum1; // 0 means down; active low
|
||||
// unique to each finger down, so for a lift and repress the value is incremented
|
||||
BYTE bTouchData1[3]; // Two 12 bits values (for X and Y)
|
||||
// middle byte holds last 4 bits of X and the starting 4 bits of Y
|
||||
BYTE bIsUpTrackingNum2; // second touch data immediately follows data of first touch
|
||||
BYTE bTouchData2[3]; // resolution is 1920x943
|
||||
} DS4_TOUCH, * PDS4_TOUCH;
|
||||
|
||||
//
|
||||
// DualShock 4 v1 complete HID Input report
|
||||
//
|
||||
typedef struct _DS4_REPORT_EX
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
BYTE bThumbLX;
|
||||
BYTE bThumbLY;
|
||||
BYTE bThumbRX;
|
||||
BYTE bThumbRY;
|
||||
USHORT wButtons;
|
||||
BYTE bSpecial;
|
||||
BYTE bTriggerL;
|
||||
BYTE bTriggerR;
|
||||
USHORT wTimestamp;
|
||||
BYTE bBatteryLvl;
|
||||
SHORT wGyroX;
|
||||
SHORT wGyroY;
|
||||
SHORT wGyroZ;
|
||||
SHORT wAccelX;
|
||||
SHORT wAccelY;
|
||||
SHORT wAccelZ;
|
||||
BYTE _bUnknown1[5];
|
||||
BYTE bBatteryLvlSpecial;
|
||||
// really should have a enum to show everything that this can represent (USB charging, battery level; EXT, headset, microphone connected)
|
||||
BYTE _bUnknown2[2];
|
||||
BYTE bTouchPacketsN; // 0x00 to 0x03 (USB max)
|
||||
DS4_TOUCH sCurrentTouch;
|
||||
DS4_TOUCH sPreviousTouch[2];
|
||||
} Report;
|
||||
|
||||
UCHAR ReportBuffer[63];
|
||||
};
|
||||
} DS4_REPORT_EX, *PDS4_REPORT_EX;
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
@@ -444,7 +444,7 @@ typedef struct _DS4_SUBMIT_REPORT_EX
|
||||
//
|
||||
// Full size HID report excluding fixed Report ID.
|
||||
//
|
||||
_In_ UCHAR Report[63];
|
||||
_In_ DS4_REPORT_EX Report;
|
||||
|
||||
} DS4_SUBMIT_REPORT_EX, * PDS4_SUBMIT_REPORT_EX;
|
||||
|
||||
|
||||
@@ -975,52 +975,52 @@ VIGEM_ERROR vigem_target_ds4_update(
|
||||
return VIGEM_ERROR_NONE;
|
||||
}
|
||||
|
||||
VIGEM_ERROR vigem_target_ds4_update_ex(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PUCHAR report, ULONG reportLength)
|
||||
VIGEM_ERROR vigem_target_ds4_update_ex(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, DS4_REPORT_EX report)
|
||||
{
|
||||
if (!vigem)
|
||||
return VIGEM_ERROR_BUS_INVALID_HANDLE;
|
||||
if (!vigem)
|
||||
return VIGEM_ERROR_BUS_INVALID_HANDLE;
|
||||
|
||||
if (!target)
|
||||
return VIGEM_ERROR_INVALID_TARGET;
|
||||
if (!target)
|
||||
return VIGEM_ERROR_INVALID_TARGET;
|
||||
|
||||
if (vigem->hBusDevice == INVALID_HANDLE_VALUE)
|
||||
return VIGEM_ERROR_BUS_NOT_FOUND;
|
||||
if (vigem->hBusDevice == INVALID_HANDLE_VALUE)
|
||||
return VIGEM_ERROR_BUS_NOT_FOUND;
|
||||
|
||||
if (target->SerialNo == 0)
|
||||
return VIGEM_ERROR_INVALID_TARGET;
|
||||
if (target->SerialNo == 0)
|
||||
return VIGEM_ERROR_INVALID_TARGET;
|
||||
|
||||
DWORD transferred = 0;
|
||||
OVERLAPPED lOverlapped = { 0 };
|
||||
lOverlapped.hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
DWORD transferred = 0;
|
||||
OVERLAPPED lOverlapped = {0};
|
||||
lOverlapped.hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
|
||||
DS4_SUBMIT_REPORT_EX dsr;
|
||||
DS4_SUBMIT_REPORT_EX_INIT(&dsr, target->SerialNo);
|
||||
DS4_SUBMIT_REPORT_EX dsr;
|
||||
DS4_SUBMIT_REPORT_EX_INIT(&dsr, target->SerialNo);
|
||||
|
||||
memcpy_s(dsr.Report, sizeof(dsr.Report), report, reportLength);
|
||||
dsr.Report = report;
|
||||
|
||||
DeviceIoControl(
|
||||
vigem->hBusDevice,
|
||||
IOCTL_DS4_SUBMIT_REPORT, // Same IOCTL, just different size
|
||||
&dsr,
|
||||
dsr.Size,
|
||||
nullptr,
|
||||
0,
|
||||
&transferred,
|
||||
&lOverlapped
|
||||
);
|
||||
DeviceIoControl(
|
||||
vigem->hBusDevice,
|
||||
IOCTL_DS4_SUBMIT_REPORT, // Same IOCTL, just different size
|
||||
&dsr,
|
||||
dsr.Size,
|
||||
nullptr,
|
||||
0,
|
||||
&transferred,
|
||||
&lOverlapped
|
||||
);
|
||||
|
||||
if (GetOverlappedResult(vigem->hBusDevice, &lOverlapped, &transferred, TRUE) == 0)
|
||||
{
|
||||
if (GetLastError() == ERROR_ACCESS_DENIED)
|
||||
{
|
||||
CloseHandle(lOverlapped.hEvent);
|
||||
return VIGEM_ERROR_INVALID_TARGET;
|
||||
}
|
||||
}
|
||||
if (GetOverlappedResult(vigem->hBusDevice, &lOverlapped, &transferred, TRUE) == 0)
|
||||
{
|
||||
if (GetLastError() == ERROR_ACCESS_DENIED)
|
||||
{
|
||||
CloseHandle(lOverlapped.hEvent);
|
||||
return VIGEM_ERROR_INVALID_TARGET;
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(lOverlapped.hEvent);
|
||||
CloseHandle(lOverlapped.hEvent);
|
||||
|
||||
return VIGEM_ERROR_NONE;
|
||||
return VIGEM_ERROR_NONE;
|
||||
}
|
||||
|
||||
ULONG vigem_target_get_index(PVIGEM_TARGET target)
|
||||
|
||||
Reference in New Issue
Block a user