Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ROBUST
- //#define EFFICIENT
- using Fleck;
- using System;
- using System.Windows;
- using vJoyInterfaceWrap;
- namespace ets2Dashboard
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- // Declaring one joystick (Device id 1) and a position structure.
- static public vJoy joystick;
- static public vJoy.JoystickState iReport;
- static public uint id = 1;
- public MainWindow()
- {
- InitializeComponent();
- var server = new WebSocketServer("ws://0.0.0.0:8181");
- server.Start(socket =>
- {
- socket.OnOpen = () => Console.WriteLine("Open!");
- socket.OnClose = () => Console.WriteLine("Close!");
- socket.OnMessage = message =>
- {
- socket.Send(message);
- uint btn = uint.Parse(message) + 1;
- bool res = joystick.SetBtn(true, id, btn);
- //joystick.SetBtn(false, id, btn);
- Console.WriteLine("{0}: {1}", btn, res);
- System.Threading.Thread.Sleep(50);
- res = joystick.SetBtn(false, id, btn);
- Console.WriteLine("{0}: {1}", btn, res);
- };
- });
- Console.WriteLine("Loaded!");
- // Create one joystick object and a position structure.
- joystick = new vJoy();
- iReport = new vJoy.JoystickState();
- // Device ID can only be in the range 1-16
- //if (args.Length > 0 && !String.IsNullOrEmpty(args[0]))
- // id = Convert.ToUInt32(args[0]);
- if (id <= 0 || id > 16)
- {
- Console.WriteLine("Illegal device ID {0}\nExit!", id);
- return;
- }
- // Get the driver attributes (Vendor ID, Product ID, Version Number)
- if (!joystick.vJoyEnabled())
- {
- Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
- return;
- }
- else
- Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString());
- // Get the state of the requested device
- VjdStat status = joystick.GetVJDStatus(id);
- switch (status)
- {
- case VjdStat.VJD_STAT_OWN:
- Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id);
- break;
- case VjdStat.VJD_STAT_FREE:
- Console.WriteLine("vJoy Device {0} is free\n", id);
- break;
- case VjdStat.VJD_STAT_BUSY:
- Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id);
- break;
- case VjdStat.VJD_STAT_MISS:
- Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id);
- break;
- default:
- Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id);
- break;
- };
- // Get the number of buttons and POV Hat switchessupported by this vJoy device
- int nButtons = joystick.GetVJDButtonNumber(id);
- // Print results
- Console.WriteLine("\nvJoy Device {0} capabilities:\n", id);
- Console.WriteLine("Number of buttons\t\t{0}\n", nButtons);
- // Test if DLL matches the driver
- UInt32 DllVer = 0, DrvVer = 0;
- bool match = joystick.DriverMatch(ref DllVer, ref DrvVer);
- if (match)
- Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", DllVer);
- else
- Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer);
- // Acquire the target
- if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
- {
- Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id);
- return;
- }
- else
- {
- Console.WriteLine("Acquired: vJoy device number {0}.\n", id);
- joystick.ResetVJD(id);
- //while(true)
- //{
- // joystick.SetBtn(true, id, 0);
- // System.Threading.Thread.Sleep(1000);
- //}
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement