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 setContraction(int speed) { if (lastContraction != speed) { lastContraction = speed; if (isLocal()) { try { //moves to new position in 1 second device.SendLinearCmd(1000, (double)speed / maxLinear); } catch (ButtplugDeviceException) { MelonLogger.Error("Toy not connected"); } } else { VRCWSIntegration.SendMessage(new VibratorControllerMessage(connectedTo, Commands.SetAir, this, speed)); } } }
public async Task Set(double position, uint duration) { if (disposed) { return; } if (client == null) { return; } if (!device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.LinearCmd)) { return; } position = Math.Max(Math.Min(position, 1d), 0d); if (currentPos == position) { return; } currentPos = position; position = position * (MaxPosition - MinPosition) + MinPosition; try { await _clientLock.WaitAsync(); await device.SendLinearCmd(duration, position); //ButtplugMessage response = await _client.SendDeviceMessage(device, message); //await CheckResponse(response); } finally { _clientLock.Release(); } }