Skip to content

Commit 1e644fd

Browse files
committed
run with steamVR
1 parent 12bec6f commit 1e644fd

9 files changed

Lines changed: 8291 additions & 88 deletions

File tree

LighthouseV2PowerControl/Class1.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

LighthouseV2PowerControl/Form1.Designer.cs

Lines changed: 44 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LighthouseV2PowerControl/Form1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Drawing;
33
using System.Linq;
44
using System.Windows.Forms;
5+
using Valve.VR;
56

67

78
namespace LighthouseV2PowerControl

LighthouseV2PowerControl/Form1.resx

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<root>
3-
<!--
4-
Microsoft ResX Schema
5-
6-
Version 2.0
7-
8-
The primary goals of this format is to allow a simple XML format
9-
that is mostly human readable. The generation and parsing of the
10-
various data types are done through the TypeConverter classes
11-
associated with the data types.
12-
13-
Example:
14-
15-
... ado.net/XML headers & schema ...
16-
<resheader name="resmimetype">text/microsoft-resx</resheader>
17-
<resheader name="version">2.0</resheader>
18-
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19-
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20-
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21-
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22-
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23-
<value>[base64 mime encoded serialized .NET Framework object]</value>
24-
</data>
25-
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26-
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27-
<comment>This is a comment</comment>
28-
</data>
29-
30-
There are any number of "resheader" rows that contain simple
31-
name/value pairs.
32-
33-
Each data row contains a name, and value. The row also contains a
34-
type or mimetype. Type corresponds to a .NET class that support
35-
text/value conversion through the TypeConverter architecture.
36-
Classes that don't support this are serialized and stored with the
37-
mimetype set.
38-
39-
The mimetype is used for serialized objects, and tells the
40-
ResXResourceReader how to depersist the object. This is currently not
41-
extensible. For a given mimetype the value must be set accordingly:
42-
43-
Note - application/x-microsoft.net.object.binary.base64 is the format
44-
that the ResXResourceWriter will generate, however the reader can
45-
read any of the formats listed below.
46-
47-
mimetype: application/x-microsoft.net.object.binary.base64
48-
value : The object must be serialized with
49-
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50-
: and then encoded with base64 encoding.
51-
52-
mimetype: application/x-microsoft.net.object.soap.base64
53-
value : The object must be serialized with
54-
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55-
: and then encoded with base64 encoding.
56-
57-
mimetype: application/x-microsoft.net.object.bytearray.base64
58-
value : The object must be serialized into a byte array
59-
: using a System.ComponentModel.TypeConverter
60-
: and then encoded with base64 encoding.
61-
-->
1+
<root>
622
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
633
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
644
<xsd:element name="root" msdata:IsDataSet="true">

LighthouseV2PowerControl/LighthouseV2PowerControl.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
4+
<OutputType>WinExe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<UseWindowsForms>true</UseWindowsForms>
77
<ApplicationIcon>newIcon.ico</ApplicationIcon>
88
<Version>0.0.2</Version>
99
<Authors>D0rG</Authors>
10+
<StartupObject>LighthouseV2PowerControl.Program</StartupObject>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

LighthouseV2PowerControl/Program.cs

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Text.RegularExpressions;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using System.Windows.Forms;
89
using Windows.ApplicationModel.Email.DataProvider;
910
using Windows.Devices.Bluetooth;
1011
using Windows.Devices.Bluetooth.GenericAttributeProfile;
1112
using Windows.Devices.Enumeration;
13+
using Windows.Media.Capture;
1214
using Windows.Storage.Streams;
15+
using Valve.VR;
1316

1417
namespace LighthouseV2PowerControl
1518
{
@@ -26,18 +29,39 @@ static class Program
2629
public delegate void LogHandler(object msg, LogType type);
2730
public static event LogHandler OnLog;
2831
private static Form1 app = null;
32+
private static CVRSystem OVRSystem;
2933

30-
[STAThread]
3134
static void Main(string[] args)
3235
{
3336
Application.SetHighDpiMode(HighDpiMode.SystemAware);
3437
Application.EnableVisualStyles();
3538
Application.SetCompatibleTextRenderingDefault(false);
39+
3640
app = new Form1();
3741
OnLog += (msg, type) => app.Log(msg, type);
38-
Stack<EventHandler> eventHandlers = new Stack<EventHandler>();
42+
try
43+
{
44+
EVRInitError error = EVRInitError.None;
45+
OVRSystem = OpenVR.Init(ref error, EVRApplicationType.VRApplication_Background); //çàïóñêàåòñÿ è âûðóáàåòñÿ ñ SteamVR
46+
if (error == EVRInitError.Init_NoServerForBackgroundApp)
47+
{
48+
Log("Init without SteamVR;");
49+
}
50+
else if(error != EVRInitError.None)
51+
{
52+
LogError(error);
53+
}
54+
}
55+
catch (Exception e)
56+
{
57+
LogError(e.Message);
58+
}
59+
60+
Stack<EventHandler> eventHandlers = new Stack<EventHandler>(); //Ïðñîòî äëÿ óäîáíîãî íàçíà÷åíèÿ êíîïîê.
3961
eventHandlers.Push(new EventHandler((obj, args) => SendActiveStatus(true)));
4062
eventHandlers.Push(new EventHandler((obj, args) => SendActiveStatus(false)));
63+
eventHandlers.Push(new EventHandler((obj, args) => SetAppManifest()));
64+
eventHandlers.Push(new EventHandler((obj, args) => RmAppManifest()));
4165
foreach (Button button in app.GetButtons())
4266
{
4367
button.Click += eventHandlers.Pop();
@@ -53,7 +77,6 @@ static void Main(string[] args)
5377
{
5478
GetGattCharacteristicsAsync();
5579
}
56-
5780
Application.Run(app);
5881
}
5982

@@ -141,7 +164,15 @@ private static async void UseArgumentsAsync(string[] args)
141164
{
142165
await SendOnLighthouseAsync(deactivateByte);
143166
}
144-
Application.Exit();
167+
else if (args[0] == "--reg")
168+
{
169+
SetAppManifest();
170+
}
171+
else if (args[0] == "--rm")
172+
{
173+
RmAppManifest();
174+
}
175+
Exit();
145176
}
146177

147178
private static void Log(object msg)
@@ -156,10 +187,48 @@ private static void LogError(object msg)
156187
OnLog.Invoke(msg, LogType.error);
157188
}
158189

190+
private static void SetAppManifest()
191+
{
192+
EVRInitError evrInitError = EVRInitError.None;
193+
OpenVR.Init(ref evrInitError, EVRApplicationType.VRApplication_Utility);
194+
if (evrInitError != EVRInitError.None)
195+
{
196+
LogError(evrInitError);
197+
}
198+
199+
EVRApplicationError applicationError = OpenVR.Applications.AddApplicationManifest(Directory.GetCurrentDirectory() + @"\manifest.vrmanifest", false);
200+
if (applicationError != EVRApplicationError.None){
201+
LogError(applicationError);
202+
}
203+
Log("Application manifest registered;");
204+
}
205+
206+
private static void RmAppManifest()
207+
{
208+
EVRInitError evrInitError = EVRInitError.None;
209+
OpenVR.Init(ref evrInitError, EVRApplicationType.VRApplication_Utility);
210+
if (evrInitError != EVRInitError.None)
211+
{
212+
LogError(evrInitError);
213+
}
214+
215+
EVRApplicationError applicationError = OpenVR.Applications.RemoveApplicationManifest(Directory.GetCurrentDirectory() + @"\manifest.vrmanifest");
216+
if (applicationError != EVRApplicationError.None){
217+
LogError(applicationError);
218+
}
219+
Log("Application manifest removed;");
220+
}
221+
159222
public static void SendActiveStatus(bool status)
160223
{
161224
SendOnLighthouseAsync((status)? activateByte : deactivateByte);
162225
}
226+
227+
private static void Exit()
228+
{
229+
OpenVR.Shutdown();
230+
Application.Exit();
231+
}
163232
}
164233

165234
public enum LogType

0 commit comments

Comments
 (0)