Exemple #1
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)));
            }
        }
        private async void Vibrate_Clicked(object sender, EventArgs e)
        {
            await _device.SendVibrateCmd(0.5);

            btnStop.IsEnabled    = true;
            btnVibrate.IsEnabled = false;
        }
Exemple #3
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();
            }
        }
        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();
            }
        }
Exemple #5
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));
            }
        }
        internal void setSpeed(int speed)
        {
            if (speed != lastSpeed)
            {
                lastSpeed  = speed;
                label.Text = $"Current Speed: {speed}";

                if (connectedTo == "all")
                {
                    foreach (var toy in allToys.Where(x => x.connectedTo != "all"))
                    {
                        toy.setSpeed(speed);
                        if (toy.supportsTwoVibrators)
                        {
                            toy.setEdgeSpeed(speed);
                        }
                    }
                    return;
                }
                if (isLocal())
                {
                    try
                    {
                        if (supportsTwoVibrators)
                        {
                            device.SendVibrateCmd(new List <double> {
                                (double)lastSpeed / maxSpeed, (double)lastEdgeSpeed / maxSpeed2
                            });
                        }
                        else
                        {
                            device.SendVibrateCmd((double)speed / maxSpeed);
                        }

                        //MelonLogger.Msg("set device speed to " + ((double)speed / maxSpeed));
                    } catch (ButtplugDeviceException) {
                        MelonLogger.Error("Toy not connected");
                    }
                }
                else
                {
                    VRCWSIntegration.SendMessage(new VibratorControllerMessage(connectedTo, Commands.SetSpeed, this, speed));
                }
            }
        }
Exemple #7
0
        private static void SendPlugUpdate()
        {
            if (!client.Connected || !shouldSendCommands)
            {
                return;
            }

            Debug.Log($"[DGBP] Setting plug vibe power to {currentVibePower}.");

            device.SendVibrateCmd(currentVibePower);
        }
Exemple #8
0
        public async Task <bool> SendVibrateCmd(uint speed)
        {
            if (VibrationMotorCount == 0)
            {
                return(false);
            }

            if (_busy)
            {
                return(false);
            }

            if (_runner != null)
            {
                _runner.Cancel();
            }

            _ = SetBusy();
            await _device.SendVibrateCmd(Math.Clamp(speed * 0.01f * _power_multiplier, 0f, 1f));

            return(true);
        }
Exemple #9
0
        public async Task Set(double position)
        {
            if (disposed)
            {
                return;
            }
            if (client == null)
            {
                return;
            }

            position = Math.Max(Math.Min(position, 1d), 0d);
            if (currentPos == position)
            {
                return;
            }

            bool direction = currentPos > position;

            currentPos = position;

            if (position != 0)
            {
                position = position * (MaxPosition - MinPosition) + MinPosition;
            }

            try
            {
                await _clientLock.WaitAsync();

                if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.VibrateCmd))
                {
                    await device.SendVibrateCmd(position);
                }
                else if (device.AllowedMessages.ContainsKey(typeof(RotateCmd)))
                {
                    await device.SendRotateCmd(StrengthToRotation(position), random(2) == 0);
                }
                else if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.RotateCmd))
                {
                    await device.SendRotateCmd(Math.Pow(position, 2), direction);
                }
            }
            finally
            {
                _clientLock.Release();
            }
        }
Exemple #10
0
        public async Task Set(ButtplugClientDevice device, IntermediateCommandInformation information)
        {
            if (_client == null)
            {
                return;
            }

            if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.VibrateCmd))
            {
                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;
                }

                case VibratorConversionMode.SpeedTimesLengthFullDuration:
                {
                    speed = CommandConverter.LaunchSpeedAndLengthToVibratorSpeed(
                        information.DeviceInformation.SpeedOriginal,
                        information.DeviceInformation.PositionFromTransformed,
                        information.DeviceInformation.PositionToTransformed);
                    speed = information.DeviceInformation.TransformSpeed(speed);
                    break;
                }

                case VibratorConversionMode.SpeedTimesLengthHalfDuration:
                {
                    if (information.Progress < 0.5)
                    {
                        speed = CommandConverter.LaunchSpeedAndLengthToVibratorSpeed(
                            information.DeviceInformation.SpeedOriginal,
                            information.DeviceInformation.PositionFromTransformed,
                            information.DeviceInformation.PositionToTransformed);
                        speed = information.DeviceInformation.TransformSpeed(speed);
                    }
                    else
                    {
                        speed = 0.0;
                    }

                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }

                try
                {
                    await _clientLock.WaitAsync();

                    await device.SendVibrateCmd(speed);

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

                    //await CheckResponse(response);
                }
                catch (Exception e)
                {
                    RecordButtplugException("ButtplugAdapter.Set(bcd, ici)", e);
                }
                finally
                {
                    _clientLock.Release();
                }
            }
        }
Exemple #11
0
 public async Task vibe(ButtplugClientDevice toy)
 {
     await toy.SendVibrateCmd(getPower());
 }