public async Task HandleMessage(
            string rawMessage,
            EliteSharedState sharedState,
            ArduinoCommunication.Arduino arduino)
        {
            var message = JsonConvert.DeserializeObject <CommonCommunication.Message>(rawMessage);

            Logger?.LogDebug($"Message Type received: {message.Type}");

            switch (message?.Type)
            {
            case "client_ready":
                await Task.Run(() => Client.CreateConnection(message.Data)).ConfigureAwait(false);

                break;

            case "connect_joysticks":
                await Task.Run(ConnectJoysticks).ConfigureAwait(false);

                break;

            case "disconnect_joysticks":
                await Task.Run(DisconnectJoysticks).ConfigureAwait(false);

                break;

            case "connect_arduino":
                await Task.Run(ConnectArduino).ConfigureAwait(false);

                break;

            case "disconnect_arduino":
                await Task.Run(DisconnectArduino).ConfigureAwait(false);

                break;

            case "reconnect_arduino":
                await Task.Run(ReconnectArduino).ConfigureAwait(false);

                break;

            //case "keypress":
            //    await Task.Run(() => KeyPress(message.Data)).ConfigureAwait(false);
            //    break;
            case "keyboard_output":
                await ArduinoCommunication.Utils.TypeFullString(arduino, message.Data, Logger).ConfigureAwait(false);

                break;

            default:
                //Unknown message
                break;
            }
        }
 public static TmThrottleController Create(EliteSharedState sharedState, vJoy vjoy, EliteVirtualJoysticks virtualJoysticks,
                                           vJoyMapper vJoyMapper, ArduinoCommunication.Arduino arduino)
 {
     return(new TmThrottleController()
     {
         Controller = Faz.SideWinderSC.Logic.TMWartHogThrottleController.RetrieveAll()?.First(),
         SharedState = sharedState,
         VirtualJoysticks = virtualJoysticks,
         vJoyMapper = vJoyMapper,
         Arduino = arduino
     });
 }
Beispiel #3
0
 public static Swff2Controller Create(EliteSharedState sharedState, vJoy vjoy,
                                      vJoyMapper vJoyMapper, ArduinoCommunication.Arduino arduino)
 {
     return(new Swff2Controller()
     {
         Controller = Faz.SideWinderSC.Logic.Swff2Controller.RetrieveAll()?.First(),
         SharedState = sharedState,
         vJoy = vjoy,
         vJoyMapper = vJoyMapper,
         Arduino = arduino,
         VisualState = new VisualState {
             Name = Name
         }
     });
 }
 public static Swff2Controller Create(EliteSharedState sharedState, vJoy vjoy, EliteVirtualJoysticks virtualJoysticks,
                                      vJoyMapper vJoyMapper, ArduinoCommunication.Arduino arduino)
 {
     try
     {
         return(new Swff2Controller()
         {
             Controller = Faz.SideWinderSC.Logic.Swff2Controller.RetrieveAll().First(),
             SharedState = sharedState,
             //vJoy = vjoy,
             VirtualJoysticks = virtualJoysticks,
             vJoyMapper = vJoyMapper,
             Arduino = arduino,
         });
     }
     catch (InvalidOperationException)
     {
     }
     return(null);
 }
 private void ConnectArduino()
 {
     arduino = new ArduinoCommunication.Arduino(settings.ArduinoCommPort, Log);
     ClientActions.ClientInformationAction(this, "Arduino Ready");
 }
Beispiel #6
0
        public void StartControllers()
        {
            try
            {
                EliteSharedState sharedState = new EliteSharedState {
                    OrbitLines = true, HeadsUpDisplay = true
                };
                eliteControllers = new EliteControllers();

                eliteVirtualJoysticks = new EliteVirtualJoysticks();

                for (uint joyId = 1; joyId <= 6; joyId++)
                {
                    eliteVirtualJoysticks.Controllers.Add(new EliteVirtualJoystick
                    {
                        Joystick    = eliteVirtualJoysticks.Joystick,
                        JoystickId  = joyId,
                        VisualState = new VisualState {
                            Name = "vJoy " + joyId
                        }
                    });
                }

                eliteVirtualJoysticks.Initialize();

                //ipcServer = new IpcServer();
                //ipcServer.Start();

                if (true == arduinoCheckBox.IsChecked)
                {
                    arduino = new ArduinoCommunication.Arduino(settings.ArduinoCommPort);
                }

                if (true == swff2CheckBox.IsChecked)
                {
                    eliteControllers.Controllers.Add(
                        Sidewinder.ForceFeedback2.Swff2Controller.Create(
                            sharedState,
                            eliteVirtualJoysticks.Joystick,
                            vJoyMapper,
                            arduino));
                }

                if (true == tmWarthogCheckBox.IsChecked)
                {
                    eliteControllers.Controllers.Add(
                        Thrustmaster.Warthog.TmThrottleController.Create(
                            sharedState,
                            eliteVirtualJoysticks.Joystick,
                            vJoyMapper,
                            arduino));
                }

                if (true == chPedalsCheckBox.IsChecked)
                {
                    eliteControllers.Controllers.Add(
                        ChProducts.ChPedalsController.Create(
                            sharedState,
                            eliteVirtualJoysticks.Joystick,
                            vJoyMapper));
                }

                if (true == scCheckBox.IsChecked)
                {
                    eliteControllers.Controllers.Add(
                        Sidewinder.Commander.ScController.Create(
                            sharedState,
                            eliteVirtualJoysticks.Joystick,
                            vJoyMapper));
                }

                if (true == gvCheckBox.IsChecked)
                {
                    eliteControllers.Controllers.Add(
                        Sidewinder.GameVoice.SwGvController.Create(
                            sharedState,
                            eliteVirtualJoysticks.Joystick,
                            vJoyMapper));
                }
                if (true == bbi32CheckBox.IsChecked)
                {
                    eliteControllers.Controllers.Add(
                        Other.BBI32.ButtonBoxController.Create(
                            sharedState,
                            eliteVirtualJoysticks.Joystick,
                            vJoyMapper,
                            arduino));
                }

                if (true == kpCheckBox.IsChecked)
                {
                    eliteControllers.Controllers.Add(
                        GearHead.Keypad.GhKpController.Create(
                            sharedState,
                            eliteVirtualJoysticks.Joystick,
                            vJoyMapper));
                }

                controllersList.DataContext = eliteControllers;
                //vControllersList.DataContext = eliteVirtualJoysticks;

                eliteControllers.Initialize();
                //textBox.Text = "ready";

                ushort version = (ushort)Utils.GetvJoyVersion();
                //Utils.RefreshvJoySpecific(version);

                //var test = Utils.Disable(version);

                textBox.Text = String.Format("ready: {0}", version.ToString());

                //strategicCommander = Sidewinder.Commander.ScController.GetController();
                //gameVoice = SwGvController.GetController();
                //chPedals = ChProducts.ChPedalsController.GetController();
                //swff2 = Sidewinder.ForceFeedback2.Swff2Controller.GetController();
                //tmThrottle = Thrustmaster.Warthog.TmThrottleController.GetController();

                //strategicCommander.SharedState = sharedState;
                //tmThrottle.SharedState = sharedState;

                //var gameVoice = Faz.SideWinderSC.Logic.SwgvController.RetrieveAll().First();
                //gameVoice.SetLights(new Faz.SideWinderSC.Logic.SwscLight[] { Faz.SideWinderSC.Logic.SwscLight.Button1 });

                //var pedals = Faz.SideWinderSC.Logic.CHPedalsController.RetrieveAll().First();

                //pedals.Initialize();

                //var ff2 = Faz.SideWinderSC.Logic.Swff2Controller.RetrieveAll().First();
                //ff2.Initialize();

                //var throttle = Faz.SideWinderSC.Logic.TMWartHogThrottleController.RetrieveAll().First();
                //throttle.Initialize();

                // 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);
                //        return;
                //    case VjdStat.VJD_STAT_MISS:
                //        Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id);
                //        return;
                //    default:
                //        Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id);
                //        return;
                //};

                // Check which axes are supported
                //bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
                //bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y);
                //bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z);
                //bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX);
                //bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ);
                //// Get the number of buttons and POV Hat switchessupported by this vJoy device
                //int nButtons = joystick.GetVJDButtonNumber(id);
                //int ContPovNumber = joystick.GetVJDContPovNumber(id);
                //int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

                // Print results
                //Console.WriteLine("\nvJoy Device {0} capabilities:\n", id);
                //Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons);
                //Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber);
                //Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber);
                //Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No");
                //Console.WriteLine("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No");
                //Console.WriteLine("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No");
                //Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No");
                //Console.WriteLine("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No");

                //// 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);

                //int X, Y, Z, ZR, XR;
                //uint count = 0;
                //long maxval = 0;

                //X = 20;
                ///Y = 30;
                //Z = 40;
                //XR = 60;
                //ZR = 80;

                //joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);

                //bool res;
                // Reset this device to default values
                //joystick.ResetVJD(id);

                //strategicCommander.vJoy = joystick;

                //strategicCommander.Controller.Initialize();

                //gameVoice.vJoy = joystick;
                //gameVoice.Controller.Initialize();

                //chPedals.vJoy = joystick;
                //chPedals.Controller.Initialize();

                //swff2.vJoy = joystick;
                //swff2.Controller.Initialize();

                //tmThrottle.vJoy = joystick;
                //tmThrottle.vJoyId = 1;
                //tmThrottle.Controller.Initialize();

                //// Feed the device in endless loop
                //while (true)
                //{
                //    // Set position of 4 axes
                //    res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X);
                //    res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y);
                //    res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z);
                //    res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX);
                //    res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ);

                //    // Press/Release Buttons
                //    res = joystick.SetBtn(true, id, count / 50);
                //    res = joystick.SetBtn(false, id, 1 + count / 50);

                //    // If Continuous POV hat switches installed - make them go round
                //    // For high values - put the switches in neutral state
                //    if (ContPovNumber > 0)
                //    {
                //        if ((count * 70) < 30000)
                //        {
                //            res = joystick.SetContPov(((int)count * 70), id, 1);
                //            res = joystick.SetContPov(((int)count * 70) + 2000, id, 2);
                //            res = joystick.SetContPov(((int)count * 70) + 4000, id, 3);
                //            res = joystick.SetContPov(((int)count * 70) + 6000, id, 4);
                //        }
                //        else
                //        {
                //            res = joystick.SetContPov(-1, id, 1);
                //            res = joystick.SetContPov(-1, id, 2);
                //            res = joystick.SetContPov(-1, id, 3);
                //            res = joystick.SetContPov(-1, id, 4);
                //        };
                //    };

                //    // If Discrete POV hat switches installed - make them go round
                //    // From time to time - put the switches in neutral state
                //    if (DiscPovNumber > 0)
                //    {
                //        if (count < 550)
                //        {
                //            joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1);
                //            joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2);
                //            joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3);
                //            joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4);
                //        }
                //        else
                //        {
                //            joystick.SetDiscPov(-1, id, 1);
                //            joystick.SetDiscPov(-1, id, 2);
                //            joystick.SetDiscPov(-1, id, 3);
                //            joystick.SetDiscPov(-1, id, 4);
                //        };
                //    };

                //    System.Threading.Thread.Sleep(20);
                //    X += 150; if (X > maxval) X = 0;
                //    Y += 250; if (Y > maxval) Y = 0;
                //    Z += 350; if (Z > maxval) Z = 0;
                //    XR += 220; if (XR > maxval) XR = 0;
                //    ZR += 200; if (ZR > maxval) ZR = 0;
                //    count++;

                //    if (count > 640)
                //        count = 0;

                //} // While (Robust)

                //testing = ScController.GetController();
                //testing.Controller.Initialize();
            }
            catch (Exception ex)
            {
                textBox.Text = ex.ToString();
            }
        }
Beispiel #7
0
        public void TestMethod1()
        {
            try
            {
                List <Controller>     Controllers           = new List <Controller>();
                EliteVirtualJoysticks eliteVirtualJoysticks = new EliteVirtualJoysticks();
                vJoyMapper            vJoyMapper            = new vJoyMapper();
                EliteSharedState      SharedState           = new EliteSharedState {
                    OrbitLines = true, HeadsUpDisplay = true
                };
                ArduinoCommunication.Arduino arduino = null;

                Settings settings = Settings.Load();

                var ffb2 = new vJoyMapping.Microsoft.Sidewinder.ForceFeedback2.Controller
                {
                    Arduino          = arduino,
                    Name             = "Force Feedback 2",
                    SharedState      = SharedState,
                    Settings         = settings,
                    VirtualJoysticks = eliteVirtualJoysticks
                };

                Controllers.Add(ffb2);

                var swgv = new vJoyMapping.Microsoft.Sidewinder.GameVoice.Controller
                {
                    Arduino          = arduino,
                    Name             = "Game Voice",
                    SharedState      = SharedState,
                    Settings         = settings,
                    VirtualJoysticks = eliteVirtualJoysticks
                };

                Controllers.Add(swgv);

                var swsc = new vJoyMapping.Microsoft.Sidewinder.StrategicCommander.Controller
                {
                    Arduino          = arduino,
                    Name             = "Strategic Commander",
                    SharedState      = SharedState,
                    Settings         = settings,
                    VirtualJoysticks = eliteVirtualJoysticks
                };

                Controllers.Add(swsc);

                var warthog = new vJoyMapping.Thrustmaster.Warthog.Throttle.Controller
                {
                    Arduino          = arduino,
                    Name             = "Warthog Throttle",
                    SharedState      = SharedState,
                    Settings         = settings,
                    VirtualJoysticks = eliteVirtualJoysticks
                };

                Controllers.Add(warthog);

                var pedals = new vJoyMapping.CHProducts.ProPedals.Controller
                {
                    Arduino          = arduino,
                    Name             = "Pro Pedals",
                    SharedState      = SharedState,
                    Settings         = settings,
                    VirtualJoysticks = eliteVirtualJoysticks
                };

                Controllers.Add(pedals);

                var bbi32 = new vJoyMapping.LeoBodnar.BBI32.Controller
                {
                    Arduino          = arduino,
                    Name             = "BBI32",
                    SharedState      = SharedState,
                    Settings         = settings,
                    VirtualJoysticks = eliteVirtualJoysticks
                };

                Controllers.Add(bbi32);

                // State Handlers
                var subscription = SharedState.GearChanged.Subscribe(
                    x => ffb2.CallActivateButton(vJoyTypes.Virtual, MappedButtons.LandingGearToggle, 200));

                while (true)
                {
                    Thread.Sleep(1000);
                }
            }
            catch (Exception)
            {
                ;
            }
        }
Beispiel #8
0
 public static ButtonBoxController Create(EliteSharedState sharedState, vJoy vjoy, vJoyMapper vJoyMapper, ArduinoCommunication.Arduino arduino)
 {
     return(new ButtonBoxController()
     {
         Controller = BBI32Controller.RetrieveAll()?.First(),
         SharedState = sharedState,
         vJoy = vjoy,
         vJoyMapper = vJoyMapper,
         Arduino = arduino,
         VisualState = new VisualState {
             Name = Name
         }
     });
 }