-
Notifications
You must be signed in to change notification settings - Fork 0
/
VJoyHandler.cs
84 lines (71 loc) · 2.91 KB
/
VJoyHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Text;
using vJoyInterfaceWrap;
namespace Bongos
{
public class VJoyHandler : OutputHandler
{
private uint topLeft;
private uint topRight;
private uint botLeft;
private uint botRight;
private uint micButton;
private HID_USAGES micAxis;
private uint start;
private int micSensitivity;
private vJoy joystick;
public VJoyHandler(BongoManager manager, BongoInputMapping mapping, int id, int mic) : base(manager, mapping)
{
joystick = new vJoy();
uint _id = (uint)id;
micSensitivity = mic;
if (id <= 0 | id > 16)
{
Program.WriteErrorToConsoleAndExit("Invalid vJoy id");
}
if (!joystick.vJoyEnabled())
{
Program.WriteErrorToConsoleAndExit("vJoy not enabled");
}
if (!joystick.AcquireVJD(_id))
{
Program.WriteErrorToConsoleAndExit("Failed to acquire vJoy device");
}
TranslateMapping(mapping);
joystick.ResetVJD(_id);
manager.TopRightPressed += () => joystick.SetBtn(true, _id, topRight);
manager.BotRightPressed += () => joystick.SetBtn(true, _id, botRight);
manager.TopLeftPressed += () => joystick.SetBtn(true, _id, topLeft);
manager.BotLeftPressed += () => joystick.SetBtn(true, _id, botLeft);
manager.StartPressed += () => joystick.SetBtn(true, _id, start);
manager.TopRightReleased += () => joystick.SetBtn(false, _id, topRight);
manager.BotRightReleased += () => joystick.SetBtn(false, _id, botRight);
manager.TopLeftReleased += () => joystick.SetBtn(false, _id, topLeft);
manager.BotLeftReleased += () => joystick.SetBtn(false, _id, botLeft);
manager.StartReleased += () => joystick.SetBtn(false, _id, start);
if (micButton == 255)
{
manager.MicUpdate += (int update) => joystick.SetAxis(update * micSensitivity, _id, micAxis);
}
else
{
manager.MicStarted += () => joystick.SetBtn(true, _id, micButton);
manager.MicReleased += () => joystick.SetBtn(false, _id, micButton);
}
}
private void TranslateMapping(BongoInputMapping mapping)
{
topLeft = uint.Parse(mapping.topLeft);
topRight = uint.Parse(mapping.topRight);
botLeft = uint.Parse(mapping.botLeft);
botRight = uint.Parse(mapping.botRight);
start = uint.Parse(mapping.start);
if (!uint.TryParse(mapping.mic, out micButton))
{
micButton = 255;
Enum.TryParse("HID_USAGE_" + mapping.mic, out micAxis);
}
}
}
}