Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristallranke committed Jan 10, 2021
0 parents commit 0f450d9
Show file tree
Hide file tree
Showing 11 changed files with 1,125 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/.vs
**/Debug
**/Release
**/Doku
discord_game_sdk
pluginsdk
*.suo
*.user
*.sdf
*.opensdf
*.ipch
Thumbs.db
25 changes: 25 additions & 0 deletions KSPW00tNow.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KSPW00tNow", "KSPW00tNow\KSPW00tNow.csproj", "{1F0B9CF0-E868-4FA1-BBF0-F3B9F145895D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1F0B9CF0-E868-4FA1-BBF0-F3B9F145895D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F0B9CF0-E868-4FA1-BBF0-F3B9F145895D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F0B9CF0-E868-4FA1-BBF0-F3B9F145895D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F0B9CF0-E868-4FA1-BBF0-F3B9F145895D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {98461E2F-0516-4A3E-9A09-CD59D8329C56}
EndGlobalSection
EndGlobal
173 changes: 173 additions & 0 deletions KSPW00tNow/FlightControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KSPW00tNow
{
[KSPAddon(KSPAddon.Startup.Flight, false)]
public class FlightControl : UnityEngine.MonoBehaviour
{
bool error;

float[] oldKeystates;
FlightCtrlState lastCtrlState;

void Log(String name, String message = "")
{
UnityEngine.Debug.Log($"[KSPW00tNow] {name}: {message}");
}

static bool wootInit = false;

void Awake()
{
Log("Awake");
error = false;

oldKeystates = new float[256];
lastCtrlState = null;

FlightInputHandler.OnRawAxisInput += ControlUpdate;
if (!wootInit) {
wootInit = true;
WootingAnalogSDKNET.WootingAnalogSDK.Initialise();
}
// WootingAnalogSDKNET.WootingAnalogSDK.DeviceEvent += DeviceEventHandler;
}

IEnumerator Start()
{
Log("Start");
yield return new UnityEngine.WaitForSeconds(2.5f);
}
void OnDestroy()
{
FlightInputHandler.OnRawAxisInput -= ControlUpdate;
// WootingAnalogSDKNET.WootingAnalogSDK.DeviceEvent -= DeviceEventHandler;
//WootingAnalogSDKNET.WootingAnalogSDK.UnInitialise();
Log("OnDestroy");
}

void Update()
{
}

void OnEnable()
{
Log("OnEnable");
}

void OnDisable()
{
// FlightInputHandler.OnRawAxisInput -= ControlUpdate;
// WootingAnalogSDKNET.WootingAnalogSDK.DeviceEvent -= DeviceEventHandler;
// WootingAnalogSDKNET.WootingAnalogSDK.UnInitialise();
Log("OnDisable");
}

float Clamp(float value)
{
return Math.Min(1.0f, Math.Max(value, -1.0f));
}

void ControlUpdate(FlightCtrlState state)
{
float pitch = 0.0f;
float roll = 0.0f;
float yaw = 0.0f;
float throttle = 0.0f;

float transX = 0.0f;
float transY = 0.0f;
float transZ = 0.0f;

var (keys, readErr) = WootingAnalogSDKNET.WootingAnalogSDK.ReadFullBuffer(20);
if (readErr == WootingAnalogSDKNET.WootingAnalogResult.Ok) {
if (keys.Count == 0) {
lastCtrlState = state;
} else {
foreach (var analog in keys)
{
HidKey key = (HidKey)analog.Item1;
if (key == HidKey.W) {
pitch -= analog.Item2;
} else if (key == HidKey.S) {
pitch += analog.Item2;
} else if (key == HidKey.Q) {
roll -= analog.Item2;
} else if (key == HidKey.E) {
roll += analog.Item2;
} else if (key == HidKey.A) {
yaw -= analog.Item2;
} else if (key == HidKey.D) {
yaw += analog.Item2;
} else if (key == HidKey.N) {
transZ -= analog.Item2;
} else if (key == HidKey.H) {
transZ += analog.Item2;
} else if (key == HidKey.I) {
transY -= analog.Item2;
} else if (key == HidKey.K) {
transY += analog.Item2;
} else if (key == HidKey.J) {
transX -= analog.Item2;
} else if (key == HidKey.L) {
transX += analog.Item2;
} else if (key == HidKey.RCtrl) {
throttle -= analog.Item2;
} else if(key == HidKey.RShift) {
throttle += analog.Item2;
}
Log("ControlUpdate", $"({analog.Item1},{analog.Item2})");
}
}
} else {
if (!error) {
error = true;
Log("ControlUpdate", $"Wooting Error code ({readErr})");
}
}
if (pitch != 0) {
state.pitch = pitch;
Log("ControlUpdate", $"Pitch {pitch})");
}
if (roll != 0) {
state.roll = roll;
Log("ControlUpdate", $"Pitch {roll})");
}
if (yaw != 0) {
state.yaw = yaw;
state.wheelSteer = yaw;
Log("ControlUpdate", $"Pitch {yaw})");
}
if (transX != 0) {
state.X = transX;
Log("ControlUpdate", $"Pitch {transX})");
}
if (transY != 0) {
state.Y = transY;
Log("ControlUpdate", $"Pitch {transY})");
}
if (transZ != 0) {
state.Z = transZ;
Log("ControlUpdate", $"Pitch {transZ})");
}
if (throttle != 0) {
state.mainThrottle = Clamp(lastCtrlState.mainThrottle + throttle/32.0f);
state.wheelThrottle = Clamp(lastCtrlState.wheelThrottle + throttle/32.0f);
Log("ControlUpdate", $"Pitch {throttle})");
}
lastCtrlState = state;
}

void DeviceEventHandler(WootingAnalogSDKNET.DeviceEventType eventType, WootingAnalogSDKNET.DeviceInfo deviceInfo)
{
if (eventType == WootingAnalogSDKNET.DeviceEventType.Connected) {
} else {
}
}
}
}
40 changes: 40 additions & 0 deletions KSPW00tNow/HidKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KSPW00tNow
{
public enum HidKey
{
A = 4,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
RCtrl = 228,
RShift
}
}
71 changes: 71 additions & 0 deletions KSPW00tNow/KSPW00tNow.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1F0B9CF0-E868-4FA1-BBF0-F3B9F145895D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KSPW00tNow</RootNamespace>
<AssemblyName>KSPW00tNow</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>G:\Spiele\Steam\SteamApps\common\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>G:\Spiele\Steam\SteamApps\common\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>G:\Spiele\Steam\SteamApps\common\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FlightControl.cs" />
<Compile Include="HidKey.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Wooting Analog SDK\WootingAnalogSDK.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Wooting Analog SDK\wooting_analog_wrapper.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions KSPW00tNow/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("KSPW00tNow")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KSPW00tNow")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]

// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("1f0b9cf0-e868-4fa1-bbf0-f3b9f145895d")]

// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 0f450d9

Please sign in to comment.