Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwomey committed May 28, 2017
2 parents a7f06e3 + f6f8355 commit 4de98bb
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Debug
Release
.vs
27 changes: 24 additions & 3 deletions OrbiterSteamController/OrbiterSteamController.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
Expand Down Expand Up @@ -88,7 +88,14 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\Users\Administrator\Desktop\Orbitersdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\Users\Administrator\Desktop\Orbitersdk\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>msvcirt.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<AdditionalDependencies>orbiter.lib;Orbitersdk.lib;Xinput9_1_0.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -97,10 +104,15 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\Users\Administrator\Desktop\Orbitersdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>C:\Users\Administrator\Desktop\Orbitersdk\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>msvcirt.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<AdditionalDependencies>orbiter.lib;Orbitersdk.lib;Xinput9_1_0.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -110,14 +122,23 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\Users\Administrator\Desktop\Orbitersdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>C:\Users\Administrator\Desktop\Orbitersdk\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>msvcirt.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<AdditionalDependencies>orbiter.lib;Orbitersdk.lib;Xinput9_1_0.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="XinputController.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="XinputController.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
8 changes: 8 additions & 0 deletions OrbiterSteamController/OrbiterSteamController.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XinputController.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="XinputController.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
87 changes: 84 additions & 3 deletions OrbiterSteamController/XinputController.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,90 @@
#include "XinputController.h"

XinputController::XinputController(int controllerNumber)
{

XinputController::XinputController() {
init();
}


XinputController::~XinputController() {

}

void XinputController::init() {
setControllerNumber();
updateState();
}

void XinputController::updateState() {
ZeroMemory(&state, sizeof(XINPUT_STATE));
XInputGetState(controllerNumber, &state);
}

int XinputController::getLX() {
updateState();
return state.Gamepad.sThumbLX;
}

int XinputController::getLY() {
updateState();
return state.Gamepad.sThumbLY;
}

int XinputController::getRX() {
updateState();
return state.Gamepad.sThumbRX;
}

int XinputController::getRY() {
updateState();
return state.Gamepad.sThumbRY;
}

XinputController::~XinputController()
int XinputController::getRT() {
updateState();
return state.Gamepad.bRightTrigger;
}

int XinputController::getLT() {
updateState();
return state.Gamepad.bLeftTrigger;
}

double XinputController::getNormLX() {
return max(-1, (double)getLX() / 32767); // Returns from -1 to 1
}

double XinputController::getNormLY() {
return max(-1, (double)getLY() / 32767); // Returns from -1 to 1
}

double XinputController::getNormRX() {
return max(-1, (double)getRX() / 32767); // Returns from -1 to 1
}

double XinputController::getNormRY() {
return max(-1, (double)getRY() / 32767); // Returns from -1 to 1
}

double XinputController::getNormRT() {
//return max(-1, (double)((getRT() - 128) / 127)); // Returns from -1 to 1
return (double)getRT() / 255; // Returns from 0 to 1
}

double XinputController::getNormLT() {
//return max(-1, (double)((getLT() - 128) / 127)); // Returns from -1 to 1
return (double)getLT() / 255; // Returns from 0 to 1
}

void XinputController::setControllerNumber() // Sets the controller to the first connected controller
{
int controllerId = -1;
for (DWORD i = 0; i < XUSER_MAX_COUNT && controllerId == -1; i++)
{
ZeroMemory(&state, sizeof(XINPUT_STATE));

if (XInputGetState(i, &state) == ERROR_SUCCESS)
controllerId = i;
}
controllerNumber = controllerId;
}
22 changes: 20 additions & 2 deletions OrbiterSteamController/XinputController.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
#pragma once
#include <Windows.h>
#include <xinput.h>

class XinputController
{
int controllerNumber;
XINPUT_STATE state;

//XINPUT_STATE state;
public:
XinputController(int controllerNumber);
XinputController();
~XinputController();

double getNormLX();
double getNormLY();
double getNormRX();
double getNormRY();
double getNormRT();
double getNormLT();

private:
void setControllerNumber();
void init();
void updateState();
int getLX();
int getLY();
int getRX();
int getRY();
int getRT();
int getLT();
};

83 changes: 14 additions & 69 deletions OrbiterSteamController/main.cpp
Original file line number Diff line number Diff line change
@@ -1,82 +1,27 @@
#define STRICT
#define ORBITER_MODULE

#include <Orbitersdk.h>
#include <xinput.h>
//#define DEBUG

int getFirstConnectedController();
int getLX(int controller);
#include <Orbitersdk.h>
#include "XinputController.h"

int firstConnectedController = -1;
XINPUT_STATE state;
XinputController controller;

DLLCLBK void InitModule(HINSTANCE hModule) {
firstConnectedController = getFirstConnectedController();
controller = XinputController();
}

DLLCLBK void opcPreStep(double simt, double simdt, double mjd)
{
/*sprintf(oapiDebugString(), "%.2f", oapiGetSimTime());*/
//firstConnectedController = getFirstConnectedController();
sprintf(oapiDebugString(), "First Controller: %d", getLX(firstConnectedController));
DLLCLBK void opcPreStep(double simt, double simdt, double mjd) {
#ifdef DEBUG
sprintf(oapiDebugString(), "LX: %f LY: %f LT+RT: %f RX: %f RY: %f", controller.getNormLX(), controller.getNormLY(), controller.getNormRT() + (controller.getNormLT() * -1), controller.getNormRX(), controller.getNormRY());
#endif

VESSEL* vessel = oapiGetFocusInterface();
//vessel->SetADCtrlMode(DWORD(0));

vessel->SetControlSurfaceLevel(AIRCTRL_ELEVATOR, -1, false);
}

int getFirstConnectedController() {
int controllerId = -1;

for (DWORD i = 0; i < XUSER_MAX_COUNT && controllerId == -1; i++)
{

ZeroMemory(&state, sizeof(XINPUT_STATE));

if (XInputGetState(i, &state) == ERROR_SUCCESS)
controllerId = i;
}
return controllerId;
}

/*XINPUT_STATE updateControllerInputState() {
ZeroMemory(&state, sizeof(XINPUT_STATE));
XInputGetState(firstConnectedController, &state);
}*/

int getLX(int controller) {
if (controller > -1) {
ZeroMemory(&state, sizeof(XINPUT_STATE));
XInputGetState(controller, &state);
return state.Gamepad.sThumbLX;
}
else {
return -1;
}
}
int getLY(int controller) {
if (controller > -1) {
ZeroMemory(&state, sizeof(XINPUT_STATE));
XInputGetState(controller, &state);
return state.Gamepad.sThumbLY;
}
else {
return -1;
}
}

vessel->SetControlSurfaceLevel(AIRCTRL_ELEVATOR, controller.getNormLY() * -1, false);
vessel->SetControlSurfaceLevel(AIRCTRL_AILERON, controller.getNormLX(), false);
vessel->SetControlSurfaceLevel(AIRCTRL_RUDDER, controller.getNormRT() + (controller.getNormLT() * -1), false);

/*
int getLX() {
int controller = getFirstConnectedController();
if (controller > -1) {
XINPUT_STATE state;
ZeroMemory(&state, sizeof(XINPUT_STATE));
XInputGetState(controller, &state);
return state.Gamepad.sThumbLX;
} else {
return -1;
}
// An experiment with controlling the view with the RS directly. Not really needed as you can bind either pad to a mouse with the right button held down
//oapiCameraSetCockpitDir((roundf(controller.getNormRX() * 1000) / 1000) * -1, roundf(controller.getNormRY() * 1000) / 1000, false);
}
*/
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# OrbiterSteamController

## Intro

I love the Steam Controller, however it presents itself to the running process directly as an xinput controller. Unfortunately this means Orbiter can't detect it during launch.

This plugin detects the xinput controller presented by the Steam Controller and maps the analog inputs to the flight control surfaces.

## Install

Unzip the contents into your Orbiter install directory.

## Setup

1. Enable OrbiterSteamController in the Orbiter _Modules_ menu
2. Add Orbiter as a non-Steam game
3. Configure the controller in the Steam Overlay
* Configure the analog stick as _Joystick Move_ with Output set to _Left Joystick_
* For the left and right triggers, configure the Trigger Analog Output as _Left Trigger_ and _Right Trigger_ respectively and disable Full Pull and Soft Pull Actions

## Use

The analog stick will now control pitch and roll. The left and right triggers will control yaw.

## Additional Tips

* Outside of the analog functions, you can configure almost everything else directly in the Steam Overlay by mapping keys to the Steam Controller.
* You can configure one of the pads as a mouse with a _Touch Binding_ of "RIGHT MOUSE" - and a click action of the _HOME_ key. This will give you a nice touchpad for changing your view, looking around in the cockpit.

0 comments on commit 4de98bb

Please sign in to comment.