Esempio n. 1
0
        public async void StopServer()
        {
            _kiirooEmulator.StopServer();
            await _bpServer.SendMessage(new StopScanning());

            await _bpServer.SendMessage(new StopAllDevices());
        }
Esempio n. 2
0
        public async void RequestServerInfoTest()
        {
            var s       = new ButtplugServer("TestClient", 100);
            var results = new List <ButtplugMessage> {
                await s.SendMessage(new RequestServerInfo("TestClient"))
            };

            results.AddRange(await s.SendMessage("[{\"RequestServerInfo\":{\"Id\":1, \"ClientName\":\"TestClient\"}}]"));

            foreach (var reply in results)
            {
                ServerInfo r;

                try
                {
                    r = (ServerInfo)reply;
                }
                catch (InvalidCastException)
                {
                    Assert.True(reply is ServerInfo);
                    continue;
                }

                Assert.True(r.MajorVersion == Assembly.GetAssembly(typeof(ServerInfo)).GetName().Version.Major);
                Assert.True(r.MinorVersion == Assembly.GetAssembly(typeof(ServerInfo)).GetName().Version.Minor);
                Assert.True(r.BuildVersion == Assembly.GetAssembly(typeof(ServerInfo)).GetName().Version.Build);
            }
        }
Esempio n. 3
0
        public async void NonRequestServerInfoFirstTest()
        {
            var s = new ButtplugServer("TestClient", 100);

            Assert.True(await s.SendMessage(new Core.Messages.Test("Test")) is Error);
            Assert.True(await s.SendMessage(new RequestServerInfo("TestClient")) is ServerInfo);
            Assert.True(await s.SendMessage(new Core.Messages.Test("Test")) is Core.Messages.Test);
        }
        private async void OnWindowClosing(object aSender, CancelEventArgs aE)
        {
            // If server is live, stop scanning, and clear our handler.
            if (_bpServer != null)
            {
                await _bpServer?.SendMessage(new StopScanning());
            }
            var window = Window.GetWindow(this);

            window.Closing -= OnWindowClosing;
        }
        private async void CheckDeviceCount(ButtplugServer aServer, int aExpectedCount)
        {
            var deviceListMsg = await aServer.SendMessage(new RequestDeviceList());

            Assert.True(deviceListMsg is DeviceList);
            Assert.Equal(((DeviceList)deviceListMsg).Devices.Length, aExpectedCount);
        }
        private void CheckDeviceCount(ButtplugServer aServer, int aExpectedCount)
        {
            var deviceListMsg = aServer.SendMessage(new RequestDeviceList()).GetAwaiter().GetResult();

            Assert.True(deviceListMsg is DeviceList);
            Assert.AreEqual(((DeviceList)deviceListMsg).Devices.Length, aExpectedCount);
        }
Esempio n. 7
0
        public MainWindow()
        {
            InitializeComponent();
            if (Application.Current == null)
            {
                return;
            }

            ButtplugTab.SetServerDetails("Kiiroo Emulator", 0);
            _bpServer = ButtplugTab.GetServer();
            _bpServer.SendMessage(new RequestServerInfo("Kiiroo Emulator")).Wait();
            InitializeComponent();
            _kiirooEmulator = new KiirooPlatformEmulator();
            _kiirooEmulator.OnKiirooPlatformEvent += HandleKiirooPlatformMessage;
            _kiirooEmulator.OnException           += HandleKiirooPlatformMessage;
            _translator = new KiirooMessageTranslator();
            _translator.VibrateEvent += OnVibrateEvent;
            _ops = new List <DispatcherOperation>();
            var emu = new KiirooEmulatorPanel();

            ButtplugTab.AddDevicePanel(_bpServer);
            ButtplugTab.SetApplicationTab("Kiiroo Emulator", emu);
            Closing += ClosingHandler;
            StartServer();
            emu.ServerStatusChanged            += OnServerStatusChanged;
            ButtplugTab.SelectedDevicesChanged += SelectionChangedHandler;

            var config = new ButtplugConfig("B******g");

            ButtplugTab.GetAboutControl().CheckUpdate(config, "b******g-csharp");
        }
Esempio n. 8
0
        private async void ScanButton_Click(object aSender, RoutedEventArgs aEvent)
        {
            // Disable button until we're done here
            ScanButton.Click -= ScanButton_Click;
            if ((string)ScanButton.Content == "Start Scanning")
            {
                StartScanning?.Invoke(this, new EventArgs());
                if (_bpServer != null)
                {
                    await _bpServer.SendMessage(new StartScanning());
                }

                ScanButton.Content = "Stop Scanning";
            }
            else
            {
                StopScanning?.Invoke(this, new EventArgs());
                if (_bpServer != null)
                {
                    await _bpServer?.SendMessage(new StopScanning());
                }

                ScanButton.Content = "Start Scanning";
            }

            ScanButton.Click += ScanButton_Click;
        }
Esempio n. 9
0
        public MainWindow()
        {
            InitializeComponent();
            if (Application.Current == null)
            {
                return;
            }
            ButtplugTab.GetLogControl().MaxLogs = 10000;

            ButtplugTab.SetServerDetails("Game Vibration Router Server", 0);
            _bpServer = ButtplugTab.GetServer();
            _log      = LogManager.GetCurrentClassLogger();
            ButtplugGameVibrationRouterInterface.VibrationCommandReceived     += OnVibrationCommand;
            ButtplugGameVibrationRouterInterface.VibrationPingMessageReceived += OnVibrationPingMessage;
            ButtplugGameVibrationRouterInterface.VibrationExceptionReceived   += OnVibrationException;
            ButtplugGameVibrationRouterInterface.VibrationExitReceived        += OnVibrationExit;
            Task.FromResult(_bpServer.SendMessage(new RequestServerInfo("B******g Game Vibration Router")));
            _processTab = new ProcessTab();
            _processTab.ProcessAttachRequested += OnAttachRequested;
            _processTab.ProcessDetachRequested += OnDetachRequested;
            ButtplugTab.SetApplicationTab("Processes", _processTab);
            ButtplugTab.AddDevicePanel(_bpServer);
            ButtplugTab.SelectedDevicesChanged += OnSelectedDevicesChanged;

            var config = new ButtplugConfig("B******g");

            ButtplugTab.GetAboutControl().CheckUpdate(config, "b******g-csharp");
        }
Esempio n. 10
0
 private async void OnVibrationCommand(object aObj, Vibration aVibration)
 {
     await Dispatcher.Invoke(async() =>
     {
         foreach (var device in _devices)
         {
             // For now, we only handle devices that can take vibration messages.
             if (!device.Messages.Contains(typeof(SingleMotorVibrateCmd).Name))
             {
                 continue;
             }
             await _bpServer.SendMessage(new SingleMotorVibrateCmd(device.Index,
                                                                   (aVibration.LeftMotorSpeed + aVibration.RightMotorSpeed) / (2.0 * 65535.0)));
         }
     });
 }
Esempio n. 11
0
        public MainWindow()
        {
            InitializeComponent();
            if (Application.Current == null)
            {
                return;
            }
            ButtplugTab.GetLogControl().MaxLogs = 10000;

            ButtplugTab.SetServerDetails("Game Vibration Router Server", 0);
            _bpServer = ButtplugTab.GetServer();
            _log      = LogManager.GetCurrentClassLogger();
            ButtplugGameVibrationRouterInterface.VibrationCommandReceived     += OnVibrationCommand;
            ButtplugGameVibrationRouterInterface.VibrationPingMessageReceived += OnVibrationPingMessage;
            ButtplugGameVibrationRouterInterface.VibrationExceptionReceived   += OnVibrationException;
            ButtplugGameVibrationRouterInterface.VibrationExitReceived        += OnVibrationExit;
            Task.FromResult(_bpServer.SendMessage(new RequestServerInfo("B******g Game Vibration Router")));
            _graphTab = new VibeGraphTab();
            ButtplugTab.SetOtherTab("Vibes", _graphTab);
            _processTab = new ProcessTab();
            _processTab.ProcessAttachRequested += OnAttachRequested;
            _processTab.ProcessDetachRequested += OnDetachRequested;
            ButtplugTab.SetApplicationTab("Processes", _processTab);
            ButtplugTab.AddDevicePanel(_bpServer);
            ButtplugTab.SelectedDevicesChanged += OnSelectedDevicesChanged;

            _graphTab.MultiplierChanged += MultiplierChanged;
            _graphTab.BaselineChanged   += BaselineChanged;
            _graphTab.PassthruChanged   += PassthruChanged;

            var config = new ButtplugConfig("B******g");

            ButtplugTab.GetAboutControl().CheckUpdate(config, "b******g-csharp");

            runTimer = new Timer {
                Interval = 100, AutoReset = true
            };
            runTimer.Elapsed += AddPoint;

            commandTimer = new Timer {
                Interval = 50, AutoReset = true
            };
            commandTimer.Elapsed += OnVibrationTimer;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
        }
Esempio n. 12
0
        private async void OnVibrationTimer(object aObj, ElapsedEventArgs e)
        {
            if (_lastVibration == _lastSentVibration && !_speedNeedsRecalc)
            {
                return;
            }

            await Dispatcher.Invoke(async() =>
            {
                foreach (var device in _devices)
                {
                    if (device.SupportsMessage(typeof(VibrateCmd)))
                    {
                        if (device.Messages.TryGetValue("VibrateCmd", out var attrs))
                        {
                            try
                            {
                                uint vibeCount = attrs.FeatureCount ?? 0;
                                List <VibrateCmd.VibrateSubcommand> vibratorSettings = new List <VibrateCmd.VibrateSubcommand>();

                                double averageVibeSpeed = (_lastVibration.LeftMotorSpeed + _lastVibration.RightMotorSpeed) / (2.0 * 65535.0);

                                // Calculate the vibe speed by first adding the multiplier to the averaged speed
                                // Then check if it's above the baseline, if not default to the baseline
                                // If it is then make sure we don't go above 1.0 speed or things start breaking
                                double vibeSpeed = Math.Min(Math.Max(averageVibeSpeed *_vibrationMultiplier, _vibrationBaseline), 1.0);

                                for (uint i = 0; i < vibeCount; i++)
                                {
                                    vibratorSettings.Add(new VibrateCmd.VibrateSubcommand(i, vibeSpeed));
                                }

                                await _bpServer.SendMessage(new VibrateCmd(device.Index, vibratorSettings));
                            }
                            catch (Exception ex)
                            {
                                _log.Error(ex);
                            }
                        }
                    }
                }
            });

            _speedNeedsRecalc  = false;
            _lastSentVibration = _lastVibration;
        }
Esempio n. 13
0
 private async void OnVibrationTimer(object aObj, ElapsedEventArgs e)
 {
     if (_lastVibration == _lastSentVibration)
     {
         return;
     }
     _lastSentVibration = _lastVibration;
     await Dispatcher.Invoke(async() =>
     {
         foreach (var device in _devices)
         {
             // For now, we only handle devices that can take vibration messages.
             if (!device.SupportsMessage(typeof(SingleMotorVibrateCmd)))
             {
                 continue;
             }
             double vibeSpeed = (_lastVibration.LeftMotorSpeed + _lastVibration.RightMotorSpeed) / (2.0 * 65535.0);
             await _bpServer.SendMessage(new SingleMotorVibrateCmd(device.Index,
                                                                   Math.Min(vibeSpeed *_vibrationMultiplier, 1.0)));
         }
     });
 }