Пример #1
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();
            }
        }
Пример #2
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();
                }
            }
        }