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(); } }
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(); } }
internal void rotate() { if (isLocal()) { try { clockwise = !clockwise; device.SendRotateCmd(lastSpeed, clockwise); } catch (ButtplugDeviceException) { MelonLogger.Error("Toy not connected"); } } else { VRCWSIntegration.SendMessage(new VibratorControllerMessage(connectedTo, Commands.SetRotate, this)); } }