Skip to content

Commit

Permalink
Parital Bluetooth support, refactoring and improving, starting with o…
Browse files Browse the repository at this point in the history
…utput.

- Added partial support for Bluetooth (thanks to Leif Messinger for getting me onto that)
- Splited the evaluation of the input buffer into two files (IO_BT and IO_USB)
- Additional controler filtering by comparing input report size
- Removing rubish short names from Device.h structs
- Created output struct (still missing the force feedback triggers)
- Changed test application to print more info
  • Loading branch information
Ohjurot committed Nov 15, 2020
1 parent c145d9c commit 8f6e2f9
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 109 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ First Release coming soon!
#### Road map to first preview release:

- ~~Reading the input state from the controller using USB~~. DONE!
- ~~Reading basic input via bluetooth~~. DONE!
- Writing Output state to the controller using USB. *Work In Progress*
- Documenting the API
- Documenting the raw protocol
Expand All @@ -26,4 +27,4 @@ First preview should be released before 28.11.2020 (The hard work is done - The
#### Feature planed for the future

- Calibrating the gyroscope
- Writing / Reading over bluetooth (If you know something about the wireless protocol - especial writing data to the controller - please let me know by creating an issue!)
- Fully write and read over bluetooth (If you know something about the wireless protocol - especial writing data to the controller - please let me know by creating an issue!)
37 changes: 31 additions & 6 deletions VS19_Solution/DS5W_Test/src/wWinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,41 @@ INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance,
DS5W::DS5InputState inState;

// Application infinity loop
bool keepRunning = false;
bool keepRunning = true;
while (keepRunning) {
// Get input state
if (DS5W_SUCCESS(DS5W::getDeviceInputState(&con, &inState))) {
if (inState.headPhoneConnected) {
console.writeLine(L"Connected");
}
else {
console.writeLine(L"Not Connected");
// Build all universal buttons (USB and BT) as text
builder << std::endl << L" === Universal input ===" << std::endl;

builder << L"Left Stick\tX: " << (int)inState.leftStick.x << L"\tY: " << (int)inState.leftStick.y << (inState.buttonsA & DS5W_ISTATE_BTN_A_LEFT_STICK ? L"\tPUSH" : L"") << std::endl;
builder << L"Right Stick\tX: " << (int)inState.rightStick.x << L"\tY: " << (int)inState.rightStick.y << (inState.buttonsA & DS5W_ISTATE_BTN_A_RIGHT_STICK ? L"\tPUSH" : L"") << std::endl << std::endl;

builder << L"Left Trigger: " << (int)inState.leftTrigger << L"\tBinary active: " << (inState.buttonsA & DS5W_ISTATE_BTN_A_LEFT_TRIGGER ? L"Yes" : L"No") << (inState.buttonsA & DS5W_ISTATE_BTN_A_LEFT_BUMPER ? L"\tBUMPER" : L"") << std::endl;
builder << L"Right Trigger: " << (int)inState.rightTrigger << L"\tBinary active: " << (inState.buttonsA & DS5W_ISTATE_BTN_A_RIGHT_TRIGGER ? L"Yes" : L"No") << (inState.buttonsA & DS5W_ISTATE_BTN_A_RIGHT_BUMPER ? L"\tBUMPER" : L"") << std::endl << std::endl;

builder << L"DPAD: " << (inState.buttonsAndDpad & DS5W_ISTATE_DPAD_LEFT ? L"L " : L" ") << (inState.buttonsAndDpad & DS5W_ISTATE_DPAD_UP ? L"U " : L" ") <<
(inState.buttonsAndDpad & DS5W_ISTATE_DPAD_DOWN ? L"D " : L" ") << (inState.buttonsAndDpad & DS5W_ISTATE_DPAD_RIGHT ? L"R " : L" ");
builder << L"\tButtons: " << (inState.buttonsAndDpad & DS5W_ISTATE_BTX_SQUARE ? L"S " : L" ") << (inState.buttonsAndDpad & DS5W_ISTATE_BTX_CROSS ? L"X " : L" ") <<
(inState.buttonsAndDpad & DS5W_ISTATE_BTX_CIRCLE ? L"O " : L" ") << (inState.buttonsAndDpad & DS5W_ISTATE_BTX_TRIANGLE ? L"T " : L" ") << std::endl;
builder << (inState.buttonsA & DS5W_ISTATE_BTN_A_MENUE ? L"MENUE" : L"") << (inState.buttonsA & DS5W_ISTATE_BTN_A_SELECT ? L"\tSELECT" : L"") << std::endl;;

// Check if controler support USB
// TODO: Add a "user mode" connection query
if (con._internal.connection == DS5W::DeviceConnection::USB) {
builder << std::endl << L" === USB Exclusive (for now) ===" << std::endl;
builder << L"Tochpad" << (inState.buttonsB & DS5W_ISTATE_BTN_B_PAD_BUTTON ? L" (pushed):" : L":") << std::endl;

builder << L"Finger 1\tX: " << inState.touchPoint1.x << L"\t Y: " << inState.touchPoint1.y << std::endl;
builder << L"Finger 2\tX: " << inState.touchPoint2.x << L"\t Y: " << inState.touchPoint2.y << std::endl << std::endl;

builder << (inState.buttonsB & DS5W_ISTATE_BTN_B_PLAYSTATION_LOGO ? L"PLAYSTATION" : L"") << (inState.buttonsB & DS5W_ISTATE_BTN_B_MIC_BUTTON ? L"\tMIC" : L"") << std::endl;;

// Ommited accel and gyro
}

// Print to console
console.writeLine(builder);
}
else {
// Device disconnected show error and try to reconnect
Expand Down
20 changes: 12 additions & 8 deletions VS19_Solution/DualSenseWindows/DualSenseWindows.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,56 +129,56 @@
<OutDir>$(SolutionDir)bin\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</IntDir>
<TargetName>ds5w_$(PlatformShortName)</TargetName>
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)src;$(ProjectDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</IntDir>
<TargetName>ds5w_$(PlatformShortName)</TargetName>
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)src;$(ProjectDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</IntDir>
<TargetName>ds5w_$(PlatformShortName)</TargetName>
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)src;$(ProjectDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</IntDir>
<TargetName>ds5w_$(PlatformShortName)</TargetName>
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)src;$(ProjectDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</IntDir>
<TargetName>ds5w_$(PlatformShortName)</TargetName>
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)src;$(ProjectDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</IntDir>
<TargetName>ds5w_$(PlatformShortName)</TargetName>
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)src;$(ProjectDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</IntDir>
<TargetName>ds5w_$(PlatformShortName)</TargetName>
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)src;$(ProjectDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(ProjectName)\$(Configuration)-$(PlatformShortName)\</IntDir>
<TargetName>ds5w_$(PlatformShortName)</TargetName>
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)src;$(ProjectDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -314,9 +314,13 @@
<ClInclude Include="include\DualSenseWindows\DSW_Api.h" />
<ClInclude Include="include\DualSenseWindows\IO.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="src\DualSenseWindows\IO_BT.h" />
<ClInclude Include="src\DualSenseWindows\IO_USB.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\DualSenseWindows\IO.cpp" />
<ClCompile Include="src\DualSenseWindows\IO_BT.cpp" />
<ClCompile Include="src\DualSenseWindows\IO_USB.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DualSenseWindows.rc" />
Expand Down
12 changes: 12 additions & 0 deletions VS19_Solution/DualSenseWindows/DualSenseWindows.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,23 @@
<ClInclude Include="include\DualSenseWindows\DS5State.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\DualSenseWindows\IO_BT.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\DualSenseWindows\IO_USB.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\DualSenseWindows\IO.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\DualSenseWindows\IO_BT.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\DualSenseWindows\IO_USB.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DualSenseWindows.rc">
Expand Down
63 changes: 63 additions & 0 deletions VS19_Solution/DualSenseWindows/include/DualSenseWindows/DS5State.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#define DS5W_ISTATE_BTN_B_PAD_BUTTON 0x02
#define DS5W_ISTATE_BTN_B_MIC_BUTTON 0x04

#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 {

/// <summary>
Expand All @@ -57,6 +63,15 @@ namespace DS5W {
short z;
} Vector3, Vec3;

/// <summary>
/// RGB Color
/// </summary>
typedef struct _Color {
unsigned char r;
unsigned char g;
unsigned char b;
} Color;

/// <summary>
/// Touchpad state
/// </summary>
Expand All @@ -72,6 +87,26 @@ namespace DS5W {
unsigned int y;
} Touch;

/// <summary>
/// State of the mic led
/// </summary>
typedef enum class _MicLed {
/// <summary>
/// Lef is off
/// </summary>
OFF,

/// <summary>
/// Led is on
/// </summary>
ON,

/// <summary>
/// Led is pulsing
/// </summary>
PULSE,
} MicLed;

/// <summary>
/// Input state of the controler
/// </summary>
Expand Down Expand Up @@ -136,4 +171,32 @@ namespace DS5W {
/// </summary>
bool headPhoneConnected;
} DS5InputState;

typedef struct _DS5OutputState {
/// <summary>
/// Left / Hard rumbel motor
/// </summary>
unsigned char leftRumble;

/// <summary>
/// Right / Soft rumbel motor
/// </summary>
unsigned char rightRumble;

/// <summary>
/// State of the microphone led
/// </summary>
MicLed microphoneLed;

/// <summary>
/// Player indication leds bitflag (You may used them for other features) DS5W_OSTATE_PLAYER_LED_???
/// </summary>
unsigned char playerLeds;

/// <summary>
/// Color of the lightbar
/// </summary>
Color lightbar;

} DS5OutputState;
}
16 changes: 7 additions & 9 deletions VS19_Solution/DualSenseWindows/include/DualSenseWindows/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace DS5W {
/// Controler is connected via bluetooth
/// </summary>
BT = 1,
} DeviceConnection, DevCnt;
} DeviceConnection;

/// <summary>
/// Struckt for storing device enum info while device discovery
Expand All @@ -41,10 +41,9 @@ namespace DS5W {
/// <summary>
/// Connection type of the discoverd device
/// </summary>
DevCnt connection;
unsigned short inputReportByteLength;
DeviceConnection connection;
} _internal;
} DeviceEnumInfo, DevEInf;
} DeviceEnumInfo;

/// <summary>
/// Device context
Expand All @@ -67,18 +66,17 @@ namespace DS5W {
/// <summary>
/// Connection of the device
/// </summary>
DevCnt connection;
DeviceConnection connection;

/// <summary>
/// Current state of connection
/// </summary>
bool connected;

/// <summary>
/// HID Input buffer
/// HID Input buffer (will be allocated by the context init function)
/// </summary>
unsigned char* hidBuffer; //To replace with input report byte length
unsigned short inputReportByteLength;
unsigned char* hidBuffer;
}_internal;
} DeviceContext, DevCtx;
} DeviceContext;
}
Loading

0 comments on commit 8f6e2f9

Please sign in to comment.