-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.cs
52 lines (47 loc) · 2.05 KB
/
code.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
private static DispatcherTimer dispatcher = new DispatcherTimer(); // inside your class of your app
//As I am using a checkbox to activate the device.
//As logitech developer have not created a event listener to subscribe it to an event and continuously listen to events from the Wheel.
//So I am using DispatcherTimer as an event listener and to update my screen.
private void WHEEL_Checked(object sender, RoutedEventArgs e)
{
if(WHEEL.IsChecked == true)
{
dispatcher.Interval = TimeSpan.FromMilliseconds(1);
dispatcher.Tick += Start;
dispatcher.Start();
}
}
void Start()
{
Dispatcher.BeginInvoke(new Action(() => { Update(); }));
}
void Update()
{
LogitechGSDK.LogiSteeringInitialize(true);
try
{
if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
{
LogitechGSDK.DIJOYSTATE2ENGINES eNGINES = LogitechGSDK.LogiGetStateCSharp(0);
LogitechGSDK.LogiPlaySpringForce(0, 0, 0, 0);
String wheel = (((eNGINES.lX * 5)) / 360).ToString();
Rotate.Text = wheel;
}
else if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(1))
{
LogitechGSDK.DIJOYSTATE2ENGINES eNGINES = LogitechGSDK.LogiGetStateCSharp(1);
LogitechGSDK.LogiPlaySpringForce(1, 0, 0, 0);
String wheel = (((eNGINES.lX * 5)) / 360).ToString();
Rotate.Text = wheel;
}
else if (LogitechGSDK.LogiIsConnected(0) | LogitechGSDK.LogiIsConnected(1) == false)
{
WHEEL.IsChecked = false;
MessageBox.Show("Device not connected!! \nTry reconnecting or check if Logitech GameHub is running or not?");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}