SHARE
TWEET

Untitled

a guest Jul 12th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define ROBUST
  2. //#define EFFICIENT
  3.  
  4. using Fleck;
  5. using System;
  6. using System.Windows;
  7.  
  8. using vJoyInterfaceWrap;
  9.  
  10. namespace ets2Dashboard
  11. {
  12.     /// <summary>
  13.     /// Interaction logic for MainWindow.xaml
  14.     /// </summary>
  15.     public partial class MainWindow : Window
  16.     {
  17.         // Declaring one joystick (Device id 1) and a position structure.
  18.         static public vJoy joystick;
  19.         static public vJoy.JoystickState iReport;
  20.         static public uint id = 1;
  21.  
  22.         public MainWindow()
  23.         {
  24.             InitializeComponent();
  25.  
  26.             var server = new WebSocketServer("ws://0.0.0.0:8181");
  27.             server.Start(socket =>
  28.             {
  29.                 socket.OnOpen = () => Console.WriteLine("Open!");
  30.                 socket.OnClose = () => Console.WriteLine("Close!");
  31.                 socket.OnMessage = message =>
  32.                 {
  33.                     socket.Send(message);
  34.                     uint btn = uint.Parse(message) + 1;
  35.                     bool res = joystick.SetBtn(true, id, btn);
  36.                     //joystick.SetBtn(false, id, btn);
  37.                     Console.WriteLine("{0}: {1}", btn, res);
  38.                     System.Threading.Thread.Sleep(50);
  39.                     res = joystick.SetBtn(false, id, btn);
  40.                     Console.WriteLine("{0}: {1}", btn, res);
  41.                 };
  42.             });
  43.  
  44.             Console.WriteLine("Loaded!");
  45.             // Create one joystick object and a position structure.
  46.             joystick = new vJoy();
  47.             iReport = new vJoy.JoystickState();
  48.  
  49.  
  50.             // Device ID can only be in the range 1-16
  51.             //if (args.Length > 0 && !String.IsNullOrEmpty(args[0]))
  52.             //    id = Convert.ToUInt32(args[0]);
  53.             if (id <= 0 || id > 16)
  54.             {
  55.                 Console.WriteLine("Illegal device ID {0}\nExit!", id);
  56.                 return;
  57.             }
  58.  
  59.             // Get the driver attributes (Vendor ID, Product ID, Version Number)
  60.             if (!joystick.vJoyEnabled())
  61.             {
  62.                 Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
  63.                 return;
  64.             }
  65.             else
  66.                 Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString());
  67.  
  68.             // Get the state of the requested device
  69.             VjdStat status = joystick.GetVJDStatus(id);
  70.             switch (status)
  71.             {
  72.                 case VjdStat.VJD_STAT_OWN:
  73.                     Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id);
  74.                     break;
  75.                 case VjdStat.VJD_STAT_FREE:
  76.                     Console.WriteLine("vJoy Device {0} is free\n", id);
  77.                     break;
  78.                 case VjdStat.VJD_STAT_BUSY:
  79.                     Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id);
  80.                     break;
  81.                 case VjdStat.VJD_STAT_MISS:
  82.                     Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id);
  83.                     break;
  84.                 default:
  85.                     Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id);
  86.                     break;
  87.             };
  88.  
  89.             // Get the number of buttons and POV Hat switchessupported by this vJoy device
  90.             int nButtons = joystick.GetVJDButtonNumber(id);
  91.  
  92.             // Print results
  93.             Console.WriteLine("\nvJoy Device {0} capabilities:\n", id);
  94.             Console.WriteLine("Number of buttons\t\t{0}\n", nButtons);
  95.  
  96.             // Test if DLL matches the driver
  97.             UInt32 DllVer = 0, DrvVer = 0;
  98.             bool match = joystick.DriverMatch(ref DllVer, ref DrvVer);
  99.             if (match)
  100.                 Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", DllVer);
  101.             else
  102.                 Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer);
  103.  
  104.  
  105.             // Acquire the target
  106.             if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
  107.             {
  108.                 Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id);
  109.                 return;
  110.             }
  111.             else
  112.             {
  113.                 Console.WriteLine("Acquired: vJoy device number {0}.\n", id);
  114.                 joystick.ResetVJD(id);
  115.  
  116.                 //while(true)
  117.                 //{
  118.                 //    joystick.SetBtn(true, id, 0);
  119.                 //    System.Threading.Thread.Sleep(1000);
  120.                 //}
  121.             }
  122.  
  123.         }
  124.     }
  125. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top