private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, _vibratorCount); foreach (var v in cmdMsg.Speeds) { if (Math.Abs(v.Speed - _vibratorSpeeds[v.Index]) < 0.0001) { continue; } _vibratorSpeeds[v.Index] = v.Speed; var vId = _vibratorCount == 1 ? string.Empty : string.Empty + (v.Index + 1); await Interface.WriteValueAsync( Encoding.ASCII.GetBytes($"Vibrate{vId}:{(int)(_vibratorSpeeds[v.Index] * 20)};"), aToken).ConfigureAwait(false); } return(new Ok(aMsg.Id)); }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is VibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (cmdMsg.Speeds.Count != 1) { return(new Error( "VibrateCmd requires 1 vector for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } foreach (var v in cmdMsg.Speeds) { if (v.Index != 0) { return(new Error( $"Index {v.Index} is out of bounds for VibrateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } if (Math.Abs(v.Speed - _vibratorSpeed) < 0.001) { return(new Ok(cmdMsg.Id)); } _vibratorSpeed = v.Speed; } var data = new byte[] { 0x0b, 0xff, 0x04, 0x0a, 0x32, 0x32, 0x00, 0x04, 0x08, 0x00, 0x64, 0x00 }; data[9] = Convert.ToByte(_vibratorSpeed * byte.MaxValue); // While there are 3 lovense revs right now, all of the characteristic arrays are the same. return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)MagicMotionBluetoothInfo.Chrs.Tx], data)); }
private async Task <ButtplugMessage> HandleVorzeA10CycloneCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckMessageHandler <VorzeA10CycloneCmd>(aMsg); if (_clockwise == cmdMsg.Clockwise && _speed == cmdMsg.Speed && SentRotation) { return(new Ok(cmdMsg.Id)); } SentRotation = true; _clockwise = cmdMsg.Clockwise; _speed = cmdMsg.Speed; var rawSpeed = (byte)((byte)(_clockwise ? 1 : 0) << 7 | (byte)_speed); await Interface.WriteValueAsync(new[] { (byte)_deviceType, (byte)_commandType, rawSpeed }, aToken).ConfigureAwait(false); return(new Ok(aMsg.Id)); }
private async Task <ButtplugMessage> HandleSingleMotorVibrateCmd([NotNull] ButtplugDeviceMessage aMsg) { if (!(aMsg is SingleMotorVibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001 && Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001) { return(new Ok(cmdMsg.Id)); } return(await HandleVibrateCmd(new VibrateCmd(cmdMsg.DeviceIndex, new List <VibrateCmd.VibrateSubcommand>() { new VibrateCmd.VibrateSubcommand(0, cmdMsg.Speed), new VibrateCmd.VibrateSubcommand(1, cmdMsg.Speed), }, cmdMsg.Id))); }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, 1); var v = cmdMsg.Speeds[0]; if (Math.Abs(v.Speed - _vibratorSpeed) < 0.001 && SentVibration) { return(new Ok(cmdMsg.Id)); } SentVibration = true; _vibratorSpeed = v.Speed; await Interface.WriteValueAsync( new byte[] { 0xC5, 0x55, (byte)Convert.ToUInt32(_vibratorSpeed * 0x32), 0xAA }, aToken) .ConfigureAwait(false); return(new Ok(aMsg.Id)); }
private async Task <ButtplugMessage> HandleSingleMotorVibrateCmd([NotNull] ButtplugDeviceMessage aMsg) { if (!(aMsg is SingleMotorVibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001 && Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001) { return(new Ok(cmdMsg.Id)); } var vCmds = new List <VibrateCmd.VibrateSubcommand>(); for (uint i = 0; i < _devInfo.VibeCount; i++) { vCmds.Add(new VibrateCmd.VibrateSubcommand(i, cmdMsg.Speed)); } return(await HandleVibrateCmd(new VibrateCmd(aMsg.DeviceIndex, vCmds, aMsg.Id))); }
private async Task <ButtplugMessage> HandleVorzeA10CycloneCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is VorzeA10CycloneCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (_clockwise == cmdMsg.Clockwise && _speed == cmdMsg.Speed) { return(new Ok(cmdMsg.Id)); } _clockwise = cmdMsg.Clockwise; _speed = cmdMsg.Speed; var rawSpeed = (byte)((byte)(_clockwise ? 1 : 0) << 7 | (byte)_speed); return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)VorzeA10CycloneInfo.Chrs.Tx], new byte[] { 0x01, 0x01, rawSpeed })); }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, _vibratorCount); var changed = false; foreach (var v in cmdMsg.Speeds) { if (!(Math.Abs(v.Speed - _vibratorSpeed[v.Index]) > 0.001)) { continue; } changed = true; _vibratorSpeed[v.Index] = v.Speed; } if (!changed) { return(new Ok(cmdMsg.Id)); } var rSpeedInt = Convert.ToUInt16(_vibratorSpeed[0] * 15); var rSpeedExt = Convert.ToUInt16(_vibratorSpeed[_vibratorCount - 1] * 15); // 0f 03 00 bc 00 00 00 00 var data = new byte[] { 0x0f, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00 }; data[3] = Convert.ToByte(rSpeedExt); // External data[3] |= Convert.ToByte(rSpeedInt << 4); // Internal // ReSharper disable once InvertIf if (rSpeedInt == 0 && rSpeedExt == 0) { data[1] = 0x00; data[5] = 0x00; } return(await Interface.WriteValueAsync(aMsg.Id, (uint)WeVibeBluetoothInfo.Chrs.Tx, data, false, aToken).ConfigureAwait(false)); }
private Task <ButtplugMessage> HandleFleshlightLaunchCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckMessageHandler <FleshlightLaunchFW12Cmd>(aMsg); _speed = (Convert.ToDouble(cmdMsg.Speed) / 99) * 100; _position = (Convert.ToDouble(cmdMsg.Position) / 99) * 100; _position = _position < 0 ? 0 : _position; _position = _position > 100 ? 100 : _position; _speed = _speed < 20 ? 20 : _speed; _speed = _speed > 100 ? 100 : _speed; // This is @funjack's algorithm for converting Fleshlight Launch commands into absolute // distance (percent) / duration (millisecond) values var distance = Math.Abs(_position - _currentPosition); var duration = FleshlightHelper.GetDuration(distance / 100, _speed / 100); // We convert those into "position" increments for our OnUpdate() timer event. _increment = 1.5 * (distance / (duration / _updateInterval)); return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id))); }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as VibrateCmd; if (cmdMsg is null) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (cmdMsg.Speeds.Count != 1) { return(new Error( "VibrateCmd requires 1 vector for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } foreach (var v in cmdMsg.Speeds) { if (v.Index != 0) { return(new Error( $"Index {v.Index} is out of bounds for VibrateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } if (v.Speed == _vibratorSpeed) { return(new Ok(cmdMsg.Id)); } _vibratorSpeed = v.Speed; } return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)YoucupsBluetoothInfo.Chrs.Tx], Encoding.ASCII.GetBytes($"$SYS,{(int)(_vibratorSpeed * 8), 1}?"))); }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, 1); var v = cmdMsg.Speeds[0]; if (Math.Abs(v.Speed - _vibratorSpeed) < 0.001 && SentVibration) { return(new Ok(cmdMsg.Id)); } _vibratorSpeed = v.Speed; SentVibration = true; // Byte 2 seems to be a monotonically increasing packet id of some kind Speed seems to be // 0-247 or so. Anything above that sets a pattern which isn't what we want here. var maxValue = (byte)247; var speed = (byte)(cmdMsg.Speeds[0].Speed * maxValue); var state = (byte)(cmdMsg.Speeds[0].Speed > 0.001 ? 1 : 0); var cmdData = new byte[] { 0xaa, 0x55, _packetId, 0x02, 0x03, 0x01, speed, state }; byte crc = 0; // Simple XOR of everything up to the 9th byte for CRC. foreach (var b in cmdData) { crc = (byte)(b ^ crc); } var data = cmdData.Concat(new byte[] { crc, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); this._packetId += 1; if (this._packetId > 255) { this._packetId = 0; } await Interface.WriteValueAsync(data.ToArray(), aToken).ConfigureAwait(false); return(new Ok(aMsg.Id)); }
private Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as VibrateCmd; if (cmdMsg is null) { return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"))); } if (cmdMsg.Speeds.Count < 1 || cmdMsg.Speeds.Count > 2) { Task.FromResult <ButtplugMessage>(new Error( "VibrateCmd requires between 1 and 2 vectors for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } foreach (var vi in cmdMsg.Speeds) { if (vi.Index == 0) { V1 = vi.Speed; } else if (vi.Index == 1) { V2 = vi.Speed; } else { Task.FromResult <ButtplugMessage>(new Error( $"Index {vi.Index} is out of bounds for VibrateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } } return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id))); }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, 1); var v = cmdMsg.Speeds[0]; if (Math.Abs(v.Speed - _vibratorSpeed) < 0.001) { return(new Ok(cmdMsg.Id)); } _vibratorSpeed = v.Speed; var data = new byte[] { 0x03, 0xff }; await Interface.WriteValueAsync(aMsg.Id, (uint)VibratissimoBluetoothInfo.Chrs.TxMode, data, false, aToken).ConfigureAwait(false); data[0] = Convert.ToByte(_vibratorSpeed * byte.MaxValue); data[1] = 0x00; return(await Interface.WriteValueAsync(aMsg.Id, (uint)VibratissimoBluetoothInfo.Chrs.TxSpeed, data, false, aToken).ConfigureAwait(false)); }
private async Task <ButtplugMessage> HandleRotateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <RotateCmd>(aMsg, 1); var vi = cmdMsg.Rotations[0]; if (_clockwise != vi.Clockwise) { _clockwise = !_clockwise; await Interface.WriteValueAsync(aMsg.Id, Encoding.ASCII.GetBytes("RotateChange;"), false, aToken).ConfigureAwait(false); } if (Math.Abs(_rotateSpeed - vi.Speed) < 0.0001) { return(new Ok(cmdMsg.Id)); } _rotateSpeed = vi.Speed; return(await Interface.WriteValueAsync(aMsg.Id, Encoding.ASCII.GetBytes($"Rotate:{(int)(_rotateSpeed * 20)};"), false, aToken).ConfigureAwait(false)); }
private async Task <ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as SingleMotorVibrateCmd; if (cmdMsg is null) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } var data = new byte[2]; data[0] = 0x03; data[1] = 0xFF; await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)VibratissimoBluetoothInfo.Chrs.TxMode], data); data[0] = Convert.ToByte(cmdMsg.Speed * byte.MaxValue); data[1] = 0x00; return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)VibratissimoBluetoothInfo.Chrs.TxSpeed], data)); }
private async Task <ButtplugMessage> HandleSingleMotorVibrateCmd([NotNull] ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as SingleMotorVibrateCmd; if (cmdMsg is null) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (_vibratorSpeed == cmdMsg.Speed) { return(new Ok(cmdMsg.Id)); } _vibratorSpeed = cmdMsg.Speed; return(await HandleVibrateCmd(new VibrateCmd(cmdMsg.DeviceIndex, new List <VibrateCmd.VibrateSubcommand>() { new VibrateCmd.VibrateSubcommand(0, cmdMsg.Speed) }, cmdMsg.Id))); }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, 2); foreach (var vi in cmdMsg.Speeds) { _vibratorSpeeds[vi.Index] = _vibratorSpeeds[vi.Index] < 0 ? 0 : _vibratorSpeeds[vi.Index] > 1 ? 1 : vi.Speed; } // This is gross, but in trying to keep with the "only take bytes in endpoints" rule, we // gotta deal with it. // todo Possible to optimize this but I currently do not care. var speedBytes = new List <byte>(); speedBytes.AddRange(BitConverter.GetBytes((ushort)(_vibratorSpeeds[0] * ushort.MaxValue))); speedBytes.AddRange(BitConverter.GetBytes((ushort)(_vibratorSpeeds[1] * ushort.MaxValue))); await Interface.WriteValueAsync(speedBytes.ToArray(), aToken); return(new Ok(aMsg.Id)); }
private async Task <ButtplugMessage> HandleFleshlightLaunchFW12Cmd(ButtplugDeviceMessage aMsg) { lock (_movementLock) { _speed = (aMsg as FleshlightLaunchFW12Cmd).Speed; _position = (aMsg as FleshlightLaunchFW12Cmd).Position; _position = _position < 0 ? 0 : _position; _position = _position > 100 ? 100 : _position; _speed = _speed < 20 ? 20 : _speed; _speed = _speed > 100 ? 100 : _speed; // This is @funjack's algorithm for converting Fleshlight Launch // commands into absolute distance (percent) / duration (millisecond) values double distance = Math.Abs(_position - _currentPosition); double mil = Math.Pow(_speed / 25000, -0.95); double duration = mil / (90 / distance); // We convert those into "position" increments for our OnUpdate() timer event. _increment = 1.5 * (distance / (duration / _updateInterval)); return(new Ok(aMsg.Id)); } }
private Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is VibrateCmd cmdMsg)) { return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"))); } if (cmdMsg.Speeds.Count == 0 || cmdMsg.Speeds.Count > _vibratorCount) { return(Task.FromResult <ButtplugMessage>(new Error("VibrateCmd requires 1 speed for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id))); } foreach (var v in cmdMsg.Speeds) { if (v.Index >= _vibratorCount) { return(Task.FromResult <ButtplugMessage>(new Error( $"Index {v.Index} is out of bounds for VibrateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id))); } var speed = (byte)Math.Floor(v.Speed * 255); _device.ControlOut( 0x02 << 5 | // Vendor Type 0x01 | // Interface Recipient 0x00, // Out Enpoint 1, speed, 0); } return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id))); }
private async Task <ButtplugMessage> HandleVibrateCmd([NotNull] ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, _devInfo.VibeCount); var changed = false; foreach (var vi in cmdMsg.Speeds) { if (Math.Abs(_vibratorSpeeds[vi.Index] - vi.Speed) < 0.0001) { continue; } _vibratorSpeeds[vi.Index] = vi.Speed; changed = true; } if (!changed && SentVibration) { return(new Ok(cmdMsg.Id)); } SentVibration = true; var data = new[] { (byte)Convert.ToUInt16(_vibratorSpeeds[_devInfo.VibeOrder[0]] * 100), (byte)Convert.ToUInt16(_vibratorSpeeds[_devInfo.VibeOrder[1]] * 100), (byte)Convert.ToUInt16(_vibratorSpeeds[_devInfo.VibeOrder[2]] * 100), }; await Interface.WriteValueAsync(data, aToken).ConfigureAwait(false); return(new Ok(aMsg.Id)); }
public async Task SendMessageAsync(ButtplugDeviceMessage aMsg, CancellationToken aToken = default(CancellationToken)) { ButtplugUtils.ArgumentNotNull(aMsg, nameof(aMsg)); if (!_owningClient.Connected) { throw new ButtplugClientConnectorException(_bpLogger, "Client that owns device is not connected"); } if (!_owningClient.Devices.Contains(this)) { throw new ButtplugDeviceException(_bpLogger, "Device no longer connected or valid"); } if (!AllowedMessages.ContainsKey(aMsg.GetType())) { throw new ButtplugDeviceException(_bpLogger, $"Device {Name} does not support message type {aMsg.GetType().Name}"); } aMsg.DeviceIndex = Index; await _sendClosure(this, aMsg, aToken).ConfigureAwait(false); }
private Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, 2); foreach (var vi in cmdMsg.Speeds) { _vibratorSpeeds[vi.Index] = _vibratorSpeeds[vi.Index] < 0 ? 0 : _vibratorSpeeds[vi.Index] > 1 ? 1 : vi.Speed; } var v = new Vibration { LeftMotorSpeed = (ushort)(_vibratorSpeeds[0] * ushort.MaxValue), RightMotorSpeed = (ushort)(_vibratorSpeeds[1] * ushort.MaxValue), }; try { _device?.SetVibration(v); } catch (Exception e) { if (_device?.IsConnected != true) { InvokeDeviceRemoved(); // Don't throw a spanner in the works return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id))); } throw new ButtplugDeviceException(BpLogger, e.Message, aMsg.Id); } return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id))); }
private async Task <ButtplugMessage> HandleStopDeviceCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { try { await _lock.WaitAsync(aToken).ConfigureAwait(false); try { await Poke((uint)ET312Consts.RAM.ChannelAIntensity, 0x00).ConfigureAwait(false); // Channel A: Set intensity value await Poke((uint)ET312Consts.RAM.ChannelBIntensity, 0x00).ConfigureAwait(false); // Channel B: Set intensity value _position = 0; _speed = 0; _increment = 0; return(new Ok(aMsg.Id)); } catch (Exception ex) { _lock.Release(); await DisconnectInternal(false).ConfigureAwait(false); if (ex is ErostekET312CommunicationException || ex is InvalidOperationException || ex is TimeoutException) { return(new Ok(aMsg.Id)); } throw; } } finally { _lock.Release(); } }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is VibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (cmdMsg.Speeds.Count != 1) { return(new Error( "VibrateCmd requires 1 vector for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } foreach (var v in cmdMsg.Speeds) { if (v.Index != 0) { return(new Error( $"Index {v.Index} is out of bounds for VibrateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } if (Math.Abs(v.Speed - _vibratorSpeed) < 0.001) { return(new Ok(cmdMsg.Id)); } _vibratorSpeed = v.Speed; } return(await Interface.WriteValue(aMsg.Id, Encoding.ASCII.GetBytes($"$SYS,{(int)(_vibratorSpeed * 8), 1}?"))); }
private async Task <ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <VibrateCmd>(aMsg, 1); var changed = false; foreach (var v in cmdMsg.Speeds) { if (!(Math.Abs(v.Speed - _vibratorSpeed) > 0.001)) { continue; } changed = true; _vibratorSpeed = v.Speed; } if (!changed && SentVibration) { return(new Ok(aMsg.Id)); } var speed = (uint)Math.Ceiling(_vibratorSpeed * 3); if (speed == 0) { speed = 255; } await Interface.WriteValueAsync( new[] { (byte)0x00, Convert.ToByte(speed) }, new ButtplugDeviceWriteOptions { Endpoint = Endpoints.Tx }, aToken).ConfigureAwait(false); return(new Ok(aMsg.Id)); }
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(); } }
private async Task <ButtplugMessage> HandleStopDeviceCmd(ButtplugDeviceMessage aMsg) { BpLogger.Debug("Stopping Device " + Name); return(await HandleVorzeA10CycloneCmd(new VorzeA10CycloneCmd(aMsg.DeviceIndex, 0, _clockwise, aMsg.Id))); }
private async Task <ButtplugMessage> HandleStopDeviceCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { BpLogger.Debug("Stopping Device " + Name); return(await HandleSingleMotorVibrateCmd(new SingleMotorVibrateCmd(aMsg.DeviceIndex, 0, aMsg.Id), aToken).ConfigureAwait(false)); }
private async Task <ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckMessageHandler <SingleMotorVibrateCmd>(aMsg); return(await HandleVibrateCmd(VibrateCmd.Create(cmdMsg.DeviceIndex, cmdMsg.Id, cmdMsg.Speed, 1), aToken).ConfigureAwait(false)); }
public Task <ButtplugMessage> HandleRotateCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { return(Task.FromResult(new Ok(ButtplugConsts.SystemMsgId) as ButtplugMessage)); }