Example #1
0
        static async Task RunRandom(ButtplugClient client, ButtplugClientDevice device)
        {
            var rnd = new Random();

            while (true)
            {
                var delay = rnd.NextDouble() * 0.5 + rnd.NextDouble() * rnd.NextDouble() * 10.0;
                try
                {
                    if (IsVorze(device))
                    {
                        await device.SendVorzeA10CycloneCmd(Convert.ToUInt32(rnd.Next(101)), rnd.Next(2) == 0?true : false);
                    }
                    else
                    {
                        bool   shouldStop = rnd.NextDouble() < 0.35;
                        double strength   = shouldStop ? 0 : rnd.NextDouble();
                        await device.SendVibrateCmd(strength);
                    }
                }
                catch (ButtplugDeviceException e)
                {
                    Console.WriteLine($"Device error: {e}");
                    device = await AttemptReconnect(client, device);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unknown exception, attempting reconnect anyway. Exception: " + e);
                    device = await AttemptReconnect(client, device);
                }
                await Task.Delay(TimeSpan.FromSeconds(delay));
            }
        }
Example #2
0
 private void RemoveDevice(ButtplugClientDevice device)
 {
     if (_devices.TryGetValue(device.Index, out var localDevice))
     {
         RemoveDevice(localDevice);
     }
 }
Example #3
0
        public async Task Set(ButtplugClientDevice device, IntermediateCommandInformation information)
        {
            if (_client == null)
            {
                return;
            }

            if (device.AllowedMessages.ContainsKey(nameof(SingleMotorVibrateCmd)))
            {
                double speedFrom = CommandConverter.LaunchToVibrator(information.DeviceInformation.PositionFromOriginal);
                double speedTo   = CommandConverter.LaunchToVibrator(information.DeviceInformation.PositionToOriginal);

                double speed = speedFrom * (1 - information.Progress) + speedTo * information.Progress * information.DeviceInformation.SpeedMultiplier;
                speed = information.DeviceInformation.TransformSpeed(speed);

                try
                {
                    await _clientLock.WaitAsync();

                    ButtplugMessage response = await _client.SendDeviceMessage(device,
                                                                               new SingleMotorVibrateCmd(device.Index, speed));

                    await CheckResponse(response);
                }
                finally
                {
                    _clientLock.Release();
                }
            }
        }
Example #4
0
        // This function is run after all mods are loaded.
        protected override void OnPostInitialize()
        {
            base.OnPostInitialize();
            Debug.Log("[DGBP] PostInit");
            if (client.Connected)
            {
                if (client.Devices.Any())
                {
                    foreach (var dev in client.Devices)
                    {
                        foreach (var msgInfo in dev.AllowedMessages)
                        {
                            if (msgInfo.Key == typeof(VibrateCmd) && dev.Name != "XBox Compatible Gamepad (XInput)")
                            {
                                device             = dev;
                                shouldSendCommands = true;
                                break;
                            }
                        }

                        if (device != null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    Debug.Log("[DGBP] No devices found.");
                }
            }
        }
 private void listbox_update(bool add, ButtplugClientDevice buttplugClientDevice)
 {
     if (this.listBox_devices.InvokeRequired)
     {
         var d = new SafeCallDelegate(listbox_update);
         this.Invoke(d, new object[] { add, buttplugClientDevice });
     }
     else
     {
         if (add)
         {
             Device device = new Device(buttplugClientDevice.Name, client, buttplugClientDevice);
             this.listBox_devices.Items.Add(device);
             Console.WriteLine(device.name);
         }
         else
         {
             for (int i = listBox_devices.Items.Count - 1; i >= 0; i--)
             {
                 var device = listBox_devices.Items[i] as Device;
                 if (device.device == buttplugClientDevice)
                 {
                     device.Dispose();
                     this.listBox_devices.Items.RemoveAt(i);
                 }
             }
         }
     }
 }
Example #6
0
        public async Task TestDeviceScanning()
        {
            Task SendFunc(ButtplugClientDevice device, ButtplugMessage msg, CancellationToken token) => Task.CompletedTask;

            var testDevice = new ButtplugClientDevice(_logMgr, _client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>()
            {
                { "SingleMotorVibrateCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes(2) },
                { "StopDeviceCmd", new MessageAttributes() },
            });

            await _client.ConnectAsync();

            _client.ScanningFinished += (aSender, aArg) =>
            {
                SetEvent();
            };

            _client.DeviceAdded += (aSender, aArg) =>
            {
                testDevice.Should().BeEquivalentTo(aArg.Device);
                SetEvent();
            };
            await _client.StartScanningAsync();

            await WaitForEvent();

            await _client.StopScanningAsync();

            await WaitForEvent();
        }
 public ButtplugPanelDevice(ButtplugClientDevice aDev)
 {
     Enabled     = true;
     IsConnected = true;
     Device      = aDev ?? throw new ArgumentNullException(nameof(aDev));
     if (Device.AllowedMessages.TryGetValue(ServerMessage.Types.MessageAttributeType.VibrateCmd, out var vAttrs))
     {
         for (uint i = 0; i < vAttrs.FeatureCount; i++)
         {
             Vibrators.Add(i, true);
         }
     }
     if (Device.AllowedMessages.TryGetValue(ServerMessage.Types.MessageAttributeType.RotateCmd, out var rAttrs))
     {
         for (uint i = 0; i < rAttrs.FeatureCount; i++)
         {
             Rotators.Add(i, true);
         }
     }
     if (Device.AllowedMessages.TryGetValue(ServerMessage.Types.MessageAttributeType.LinearCmd, out var lAttrs))
     {
         for (uint i = 0; i < lAttrs.FeatureCount; i++)
         {
             Linears.Add(i, true);
         }
     }
 }
Example #8
0
        private void AddDevice(ButtplugClientDevice device)
        {
            var newDevice = new ButtplugDevice(device, this);

            _devices.Add(newDevice);
            OnDeviceFound(newDevice);
        }
 public ButtplugPanelDevice(ButtplugClientDevice aDev)
 {
     Enabled     = true;
     IsConnected = true;
     Device      = aDev ?? throw new ArgumentNullException(nameof(aDev));
     if (Device.AllowedMessages.TryGetValue(typeof(VibrateCmd), out var vAttrs) && vAttrs.FeatureCount != null)
     {
         for (uint i = 0; i < vAttrs.FeatureCount; i++)
         {
             Vibrators.Add(i, true);
         }
     }
     if (Device.AllowedMessages.TryGetValue(typeof(RotateCmd), out var rAttrs) && rAttrs.FeatureCount != null)
     {
         for (uint i = 0; i < rAttrs.FeatureCount; i++)
         {
             Rotators.Add(i, true);
         }
     }
     if (Device.AllowedMessages.TryGetValue(typeof(LinearCmd), out var lAttrs) && lAttrs.FeatureCount != null)
     {
         for (uint i = 0; i < lAttrs.FeatureCount; i++)
         {
             Linears.Add(i, true);
         }
     }
 }
Example #10
0
        private static async Task <VibrateStatus> HandleVibrateStart(ButtplugClientDevice device, VibrateStart vs, VibrateStatus status)
        {
            if (IsVorze(device))
            {
                var newDirection = random(2) == 0 ? true : false;
                await device.SendVorzeA10CycloneCmd(Convert.ToUInt32(vs.strength * 100), newDirection);

                return(await vs.time.MatchAsync(async time =>
                {
                    await Task.Delay(time);
                    await device.SendVorzeA10CycloneCmd(StrengthToVorzeRotation(status.strength), status.direction);
                    return status;
                }, () => new VibrateStatus(vs.strength, newDirection)));
            }
            else
            {
                await device.SendVibrateCmd(vs.strength);

                // TODO handle intervals
                return(await vs.time.MatchAsync(async time =>
                {
                    await Task.Delay(time);
                    await device.SendVibrateCmd(status.strength);
                    return status;
                }, () => new VibrateStatus(vs.strength, false)));
            }
        }
Example #11
0
        public async Task Set(ButtplugClientDevice device, IntermediateCommandInformation information)
        {
            if (_client == null)
            {
                return;
            }

            if (device.AllowedMessages.Contains(nameof(SingleMotorVibrateCmd)))
            {
                double speedFrom = LaunchToVibrator(information.DeviceInformation.PositionFromOriginal);
                double speedTo   = LaunchToVibrator(information.DeviceInformation.PositionToOriginal);

                double speed = Math.Min(1,
                                        Math.Max(0, speedFrom * (1 - information.Progress) + speedTo * information.Progress));

                try
                {
                    await _clientLock.WaitAsync();

                    ButtplugMessage response = await _client.SendDeviceMessage(device,
                                                                               new SingleMotorVibrateCmd(device.Index, speed, _client.nextMsgId));

                    await CheckResponse(response);
                }
                finally
                {
                    _clientLock.Release();
                }
            }
        }
Example #12
0
        async void HandleDeviceAdded(object aObj, DeviceAddedEventArgs aArgs)
        {
            _device = aArgs.Device;
            await _client.StopScanningAsync();

            Device.BeginInvokeOnMainThread(() =>
            {
                btnVibrate.IsEnabled = true;
            });
        }
Example #13
0
        public async Task Set(ButtplugClientDevice device, DeviceCommandInformation information)
        {
            if (_client == null)
            {
                return;
            }

            try
            {
                await _clientLock.WaitAsync();

                if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.LinearCmd))
                {
                    await device.SendLinearCmd(
                        (uint)information.DurationStretched.TotalMilliseconds,
                        information.PositionToTransformed);
                }
                else if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.VibrateCmd))
                {
                    switch (VibratorConversionMode)
                    {
                    case VibratorConversionMode.PositionToSpeed:
                        await device.SendVibrateCmd(information.TransformSpeed(CommandConverter.LaunchPositionToVibratorSpeed(information.PositionFromOriginal)));

                        break;

                    case VibratorConversionMode.PositionToSpeedInverted:
                        await device.SendVibrateCmd(information.TransformSpeed(CommandConverter.LaunchPositionToVibratorSpeed((byte)(99 - information.PositionFromOriginal))));

                        break;

                    case VibratorConversionMode.SpeedHalfDuration:
                    case VibratorConversionMode.SpeedFullDuration:
                        await device.SendVibrateCmd(information.TransformSpeed(CommandConverter.LaunchSpeedToVibratorSpeed(information.SpeedTransformed)));

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.RotateCmd))
                {
                    await device.SendRotateCmd(CommandConverter.LaunchToVorzeSpeed(information), information.PositionToTransformed > information.PositionFromTransformed);
                }
            }
            catch (Exception e)
            {
                RecordButtplugException("ButtplugAdapter.Set(bcd, dci)", e);
            }
            finally
            {
                _clientLock.Release();
            }
        }
Example #14
0
        public DeviceContainer(ButtplugClientDevice device, ILogger <DeviceRegister> logger, uint command_delay, uint power_factor)
        {
            _device           = device;
            _logger           = logger;
            _command_delay    = (int)command_delay;
            _power_multiplier = Math.Clamp(power_factor / 100.0f, 0f, 1f);

            //This is just convenience, should the B******g server crash while the device is on,
            //so when the device comes back we first stop whatever it was doing.
            _ = StopDeviceCmd();
        }
Example #15
0
        public NewItemPage(ButtplugClientDevice device)
        {
            InitializeComponent();

            Item = new Item
            {
                Device = device,
            };

            BindingContext = this;
        }
        /// <summary>
        /// Called when a device is removed by intiface.
        /// </summary>
        public void OnDeviceRemoved(ButtplugClientDevice device)
        {
            if (!devices.ContainsKey(device.Name))
            {
                _logger.LogDebug($"Can't find ${device.Name} Trying to remove a nonexisting device.");
                return;
            }

            _logger.LogInformation("Device Removed: " + device.Name);

            devices.Remove(device.Name);
        }
Example #17
0
        public async Task Set(ButtplugClientDevice device, DeviceCommandInformation information)
        {
            if (_client == null)
            {
                return;
            }

            try
            {
                await _clientLock.WaitAsync();

                if (device.AllowedMessages.ContainsKey(typeof(FleshlightLaunchFW12Cmd)))
                {
                    await device.SendFleshlightLaunchFW12Cmd(information.SpeedTransformed, information.PositionToTransformed);
                }
                else if (device.AllowedMessages.ContainsKey(typeof(VibrateCmd)))
                {
                    switch (VibratorConversionMode)
                    {
                    case VibratorConversionMode.PositionToSpeed:
                        await device.SendVibrateCmd(information.TransformSpeed(CommandConverter.LaunchPositionToVibratorSpeed(information.PositionFromOriginal)));

                        break;

                    case VibratorConversionMode.PositionToSpeedInverted:
                        await device.SendVibrateCmd(information.TransformSpeed(CommandConverter.LaunchPositionToVibratorSpeed((byte)(99 - information.PositionFromOriginal))));

                        break;

                    case VibratorConversionMode.SpeedHalfDuration:
                    case VibratorConversionMode.SpeedFullDuration:
                        await device.SendVibrateCmd(information.TransformSpeed(CommandConverter.LaunchSpeedToVibratorSpeed(information.SpeedTransformed)));

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else if (device.AllowedMessages.ContainsKey(typeof(VorzeA10CycloneCmd)))
                {
                    await device.SendVorzeA10CycloneCmd(CommandConverter.LaunchToVorzeSpeed(information), information.PositionToTransformed > information.PositionFromTransformed);
                }
            }
            catch (Exception e)
            {
                RecordButtplugException("ButtplugAdapter.Set(bcd, dci)", e);
            }
            finally
            {
                _clientLock.Release();
            }
        }
Example #18
0
        public async Task Set(ButtplugClientDevice device, DeviceCommandInformation information)
        {
            if (_client == null)
            {
                return;
            }

            try
            {
                await _clientLock.WaitAsync();

                ButtplugDeviceMessage message = null;

                if (device.AllowedMessages.ContainsKey(nameof(FleshlightLaunchFW12Cmd)))
                {
                    message = new FleshlightLaunchFW12Cmd(device.Index, information.SpeedTransformed, information.PositionToTransformed);
                }
                else if (device.AllowedMessages.ContainsKey(nameof(KiirooCmd)))
                {
                    message = new KiirooCmd(device.Index, CommandConverter.LaunchToKiiroo(information.PositionToOriginal, 0, 4));
                }

                /*else if (device.AllowedMessages.ContainsKey(nameof(VibrateCmd)))
                 * {
                 *  message = new VibrateCmd(device.Index, new List<VibrateCmd.VibrateSubcommand>{new VibrateCmd.VibrateSubcommand(0, LaunchToVibrator(information.PositionFromOriginal))});
                 * }*/
                else if (device.AllowedMessages.ContainsKey(nameof(SingleMotorVibrateCmd)))
                {
                    message = new SingleMotorVibrateCmd(device.Index, information.TransformSpeed(CommandConverter.LaunchToVibrator(information.PositionFromOriginal)));
                }
                else if (device.AllowedMessages.ContainsKey(nameof(VorzeA10CycloneCmd)))
                {
                    message = new VorzeA10CycloneCmd(device.Index, CommandConverter.LaunchToVorzeSpeed(information), information.PositionToTransformed > information.PositionFromTransformed);
                }
                else if (device.AllowedMessages.ContainsKey(nameof(LovenseCmd)))
                {
                    //message = new LovenseCmd(device.Index, LaunchToLovense(position, speed));
                }

                if (message == null)
                {
                    return;
                }

                ButtplugMessage response = await _client.SendDeviceMessage(device, message);
                await CheckResponse(response);
            }
            finally
            {
                _clientLock.Release();
            }
        }
Example #19
0
        public void TestClientDeviceEquality()
        {
            var logMgr = new ButtplugLogManager();
            var client = new ButtplugClient("Test Device Client", new ButtplugEmbeddedConnector("Test Device Server"));

            Task SendFunc(ButtplugClientDevice device, ButtplugMessage msg, CancellationToken token) => Task.CompletedTask;

            var testDevice = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>()
            {
                { "SingleMotorVibrateCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes(2) },
                { "StopDeviceCmd", new MessageAttributes() },
            });
            var testDevice2 = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>()
            {
                { "SingleMotorVibrateCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes(2) },
                { "StopDeviceCmd", new MessageAttributes() },
            });
            var testDevice3 = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>()
            {
                { "SingleMotorVibrateCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes(2) },
            });
            var testDevice4 = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>()
            {
                { "SingleMotorVibrateCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes(2) },
                { "FleshlightLaunchFW12Cmd", new MessageAttributes() },
            });
            var testDevice5 = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>()
            {
                { "SingleMotorVibrateCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes(2) },
                { "StopDeviceCmd", new MessageAttributes() },
                { "RotateCmd", new MessageAttributes(1) },
            });

            var newClient       = new ButtplugClient("Other Test Device Client", new ButtplugEmbeddedConnector("Other Test Device Server"));
            var otherTestDevice = new ButtplugClientDevice(logMgr, newClient, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>()
            {
                { "SingleMotorVibrateCmd", new MessageAttributes() },
                { "VibrateCmd", new MessageAttributes(2) },
                { "StopDeviceCmd", new MessageAttributes() },
            });

            testDevice.Should().BeEquivalentTo(testDevice2);
            testDevice.Should().NotBe(testDevice3);
            testDevice.Should().NotBe(testDevice4);
            testDevice.Should().NotBe(testDevice5);
            testDevice.Should().NotBe(otherTestDevice);
        }
Example #20
0
        public Device(String name, ButtplugClient client, ButtplugClientDevice device)
        {
            this.name           = name;
            this.device         = device;
            this.client         = client;
            this.active         = false;
            this.running_events = new List <Running_Event>();

            thread = new Thread(UpdateLoop)
            {
                IsBackground = true
            };
            thread.Start();
        }
Example #21
0
        public async void Stop(ButtplugClientDevice device)
        {
            if (_client == null)
            {
                return;
            }

            if (!device.AllowedMessages.Contains(nameof(StopDeviceCmd)))
            {
                return;
            }

            ButtplugMessage response = await _client.SendDeviceMessage(device, new StopDeviceCmd(device.Index, _client.nextMsgId));

            await CheckResponse(response);
        }
Example #22
0
        private void AddDevice(ButtplugClientDevice device)
        {
            var newDevice = new ButtplugDevice(device, this);

            _devices.AddOrUpdate(newDevice.Index,
                                 (newIdx) =>
            {
                OnDeviceFound(newDevice);
                return(newDevice);
            },
                                 (updateIdx, oldDev) =>
            {
                OnDeviceRemoved(oldDev);
                OnDeviceFound(newDevice);
                return(newDevice);
            });
        }
Example #23
0
        public async void Stop(ButtplugClientDevice device)
        {
            if (_client == null)
            {
                return;
            }

            if (!device.AllowedMessages.ContainsKey(typeof(StopDeviceCmd)))
            {
                return;
            }

            await device.StopDeviceCmd();

            //ButtplugMessage response = await _client.SendDeviceMessage(device, new StopDeviceCmd(device.Index));
            //await CheckResponse(response);
        }
Example #24
0
        private void Client_DeviceAddedOrRemoved(object sender, DeviceEventArgs deviceEventArgs)
        {
            ButtplugClientDevice device = deviceEventArgs.Device;

            DeviceEventArgs.DeviceAction action = deviceEventArgs.Action;

            switch (action)
            {
            case DeviceEventArgs.DeviceAction.ADDED:
                AddDevice(device);
                break;

            case DeviceEventArgs.DeviceAction.REMOVED:
                RemoveDevice(device);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #25
0
        public async void Stop(ButtplugClientDevice device)
        {
            if (_client == null)
            {
                return;
            }

            if (!device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.StopDeviceCmd))
            {
                return;
            }

            try
            {
                await device.SendStopDeviceCmd();
            }
            catch (Exception e)
            {
                RecordButtplugException("ButtplugAdapter.Stop", e);
            }
        }
Example #26
0
        private void SelectionChangedHandler(object aObj, List <ButtplugDeviceInfo> aDevices)
        {
            foreach (var dev in aDevices)
            {
                var cdev = new ButtplugClientDevice(dev.Index, dev.Name, dev.Messages);
                _clientPanel.Devices.AddOrUpdate(dev.Index, cdev, (idx, old) => cdev);
            }

            List <uint> ids = new List <uint>();

            foreach (var dev in aDevices)
            {
                ids.Add(dev.Index);
            }

            foreach (var dev in _clientPanel.Devices.Values)
            {
                if (!ids.Contains(dev.Index))
                {
                    _clientPanel.Devices.TryRemove(dev.Index, out var old);
                }
            }
        }
        /// <summary>
        /// Called when a device is announced by intiface.
        /// </summary>
        public void OnDeviceAdded(ButtplugClientDevice device)
        {
            string name      = device.Name;
            string real_name = name;

            ToySettings toy = _settings.GetToy(device.Name);

            if (toy != null && toy.VisibleName != null && toy.VisibleName.Length > 0)
            {
                name = DeCollideDeviceName(toy.VisibleName);
            }
            else
            {
                name = DeCollideDeviceName(name);
            }

            uint toy_delay = BridgeSettings.MIN_COMMAND_RATE;
            uint toy_power = 100;

            if (toy != null)
            {
                if (toy.CommandRate.HasValue)
                {
                    toy_delay = Math.Max(BridgeSettings.MIN_COMMAND_RATE, toy.CommandRate.Value);
                }

                if (toy.PowerFactor.HasValue)
                {
                    toy_power = toy.PowerFactor.Value;
                }
            }

            devices.Add(name, new DeviceContainer(device, _logger, toy_delay, toy_power));

            _logger.LogInformation(String.Format("\nNew device detected\n{0} ({1})\n  Update rate: {2}ms\n  Power: {3}%", name, real_name, toy_delay, toy_power));
        }
Example #28
0
        public async void Stop(ButtplugClientDevice device)
        {
            if (_client == null)
            {
                return;
            }

            if (!device.AllowedMessages.ContainsKey(typeof(StopDeviceCmd)))
            {
                return;
            }

            try
            {
                await device.StopDeviceCmd();

                //ButtplugMessage response = await _client.SendDeviceMessage(device, new StopDeviceCmd(device.Index));
                //await CheckResponse(response);
            }
            catch (Exception e)
            {
                RecordButtplugException("ButtplugAdapter.Stop", e);
            }
        }
Example #29
0
        public async Task Set(ButtplugClientDevice device, DeviceCommandInformation information)
        {
            if (_client == null)
            {
                return;
            }

            try
            {
                await _clientLock.WaitAsync();

                ButtplugDeviceMessage message = null;

                if (device.AllowedMessages.ContainsKey(typeof(FleshlightLaunchFW12Cmd)))
                {
                    message = new FleshlightLaunchFW12Cmd(device.Index, information.SpeedTransformed, information.PositionToTransformed);
                }
                else if (device.AllowedMessages.ContainsKey(typeof(KiirooCmd)))
                {
                    message = new KiirooCmd(device.Index, CommandConverter.LaunchToKiiroo(information.PositionToOriginal, 0, 4));
                }

                /*else if (device.AllowedMessages.ContainsKey(nameof(VibrateCmd)))
                 * {
                 *  message = new VibrateCmd(device.Index, new List<VibrateCmd.VibrateSubcommand>{new VibrateCmd.VibrateSubcommand(0, LaunchPositionToVibratorSpeed(information.PositionFromOriginal))});
                 * }*/
                else if (device.AllowedMessages.ContainsKey(typeof(SingleMotorVibrateCmd)))
                {
                    switch (VibratorConversionMode)
                    {
                    case VibratorConversionMode.PositionToSpeed:
                        message = new SingleMotorVibrateCmd(device.Index, information.TransformSpeed(CommandConverter.LaunchPositionToVibratorSpeed(information.PositionFromOriginal)));
                        break;

                    case VibratorConversionMode.PositionToSpeedInverted:
                        message = new SingleMotorVibrateCmd(device.Index, information.TransformSpeed(CommandConverter.LaunchPositionToVibratorSpeed((byte)(99 - information.PositionFromOriginal))));
                        break;

                    case VibratorConversionMode.SpeedHalfDuration:
                    case VibratorConversionMode.SpeedFullDuration:
                        message = new SingleMotorVibrateCmd(device.Index, information.TransformSpeed(CommandConverter.LaunchSpeedToVibratorSpeed(information.SpeedTransformed)));
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else if (device.AllowedMessages.ContainsKey(typeof(VorzeA10CycloneCmd)))
                {
                    message = new VorzeA10CycloneCmd(device.Index, CommandConverter.LaunchToVorzeSpeed(information), information.PositionToTransformed > information.PositionFromTransformed);
                }
                else if (device.AllowedMessages.ContainsKey(typeof(LovenseCmd)))
                {
                    //message = new LovenseCmd(device.Index, LaunchToLovense(position, speed));
                }

                if (message == null)
                {
                    return;
                }

                await device.SendMessageAsync(message);

                //ButtplugMessage response = await _client.SendDeviceMessage(device, message);
                //await CheckResponse(response);
            }
            finally
            {
                _clientLock.Release();
            }
        }
Example #30
0
        public async Task Set(ButtplugClientDevice device, IntermediateCommandInformation information)
        {
            if (_client == null)
            {
                return;
            }

            if (device.AllowedMessages.ContainsKey(typeof(SingleMotorVibrateCmd)))
            {
                double speed;
                switch (VibratorConversionMode)
                {
                case VibratorConversionMode.PositionToSpeed:
                {
                    double speedFrom = CommandConverter.LaunchPositionToVibratorSpeed(information.DeviceInformation.PositionFromOriginal);
                    double speedTo   = CommandConverter.LaunchPositionToVibratorSpeed(information.DeviceInformation.PositionToOriginal);

                    speed = speedFrom * (1 - information.Progress) + speedTo * information.Progress * information.DeviceInformation.SpeedMultiplier;
                    speed = information.DeviceInformation.TransformSpeed(speed);

                    break;
                }

                case VibratorConversionMode.PositionToSpeedInverted:
                {
                    double speedFrom = CommandConverter.LaunchPositionToVibratorSpeed((byte)(99 - information.DeviceInformation.PositionFromOriginal));
                    double speedTo   = CommandConverter.LaunchPositionToVibratorSpeed((byte)(99 - information.DeviceInformation.PositionToOriginal));

                    speed = speedFrom * (1 - information.Progress) + speedTo * information.Progress * information.DeviceInformation.SpeedMultiplier;
                    speed = information.DeviceInformation.TransformSpeed(speed);

                    break;
                }

                case VibratorConversionMode.SpeedHalfDuration:
                {
                    if (information.Progress < 0.5)
                    {
                        speed = CommandConverter.LaunchSpeedToVibratorSpeed(information.DeviceInformation.SpeedTransformed);
                    }
                    else
                    {
                        speed = 0.0;
                    }

                    break;
                }

                case VibratorConversionMode.SpeedFullDuration:
                {
                    speed = CommandConverter.LaunchSpeedToVibratorSpeed(information.DeviceInformation.SpeedTransformed);
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }

                try
                {
                    await _clientLock.WaitAsync();

                    await device.SendMessageAsync(new SingleMotorVibrateCmd(device.Index, speed));

                    //ButtplugMessage response = await device.SendMessageAsync(new SingleMotorVibrateCmd(device.Index, speed));

                    //await CheckResponse(response);
                }
                finally
                {
                    _clientLock.Release();
                }
            }
        }