public async Task Set(ButtplugClientDevice device, DeviceCommandInformation information) { if (_client == null) { return; } try { await _clientLock.WaitAsync(); ButtplugDeviceMessage message = null; if (device.AllowedMessages.ContainsKey(nameof(FleshlightLaunchFW12Cmd))) { message = new FleshlightLaunchFW12Cmd(device.Index, information.SpeedTransformed, information.PositionToTransformed); } else if (device.AllowedMessages.ContainsKey(nameof(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, LaunchToVibrator(information.PositionFromOriginal))}); * }*/ else if (device.AllowedMessages.ContainsKey(nameof(SingleMotorVibrateCmd))) { message = new SingleMotorVibrateCmd(device.Index, information.TransformSpeed(CommandConverter.LaunchToVibrator(information.PositionFromOriginal))); } else if (device.AllowedMessages.ContainsKey(nameof(VorzeA10CycloneCmd))) { message = new VorzeA10CycloneCmd(device.Index, CommandConverter.LaunchToVorzeSpeed(information), information.PositionToTransformed > information.PositionFromTransformed); } else if (device.AllowedMessages.ContainsKey(nameof(LovenseCmd))) { //message = new LovenseCmd(device.Index, LaunchToLovense(position, speed)); } if (message == null) { return; } ButtplugMessage response = await _client.SendDeviceMessage(device, message); await CheckResponse(response); } finally { _clientLock.Release(); } }
public void TestVorzeA10CycloneCmd() { var msg = new VorzeA10CycloneCmd(2, 50, true, 4); Assert.AreEqual(2, msg.DeviceIndex); Assert.AreEqual(4, msg.Id); Assert.AreEqual(50, msg.Speed); Assert.True(msg.Clockwise); Assert.Catch <ArgumentException>(() => { msg.Speed = 1000; }); var str1 = _parser.Serialize(msg, 1); Assert.AreEqual( "[{\"VorzeA10CycloneCmd\":{\"Clockwise\":true,\"Speed\":50,\"DeviceIndex\":2,\"Id\":4}}]", str1); var msgs = _parser.Deserialize(str1); Assert.AreEqual(1, msgs.Length); Assert.True(msgs[0] is VorzeA10CycloneCmd); msg = (VorzeA10CycloneCmd)msgs[0]; Assert.AreEqual(2, msg.DeviceIndex); Assert.AreEqual(4, msg.Id); Assert.AreEqual(50, msg.Speed); Assert.True(msg.Clockwise); var str0 = _parser.Serialize(msg, 0); Assert.AreEqual( "[{\"VorzeA10CycloneCmd\":{\"Clockwise\":true,\"Speed\":50,\"DeviceIndex\":2,\"Id\":4}}]", str1); msgs = _parser.Deserialize(str1); Assert.AreEqual(1, msgs.Length); Assert.True(msgs[0] is VorzeA10CycloneCmd); msg = (VorzeA10CycloneCmd)msgs[0]; Assert.AreEqual(2, msg.DeviceIndex); Assert.AreEqual(4, msg.Id); Assert.AreEqual(50, msg.Speed); Assert.True(msg.Clockwise); }
public void TestVorzeA10CycloneCmd() { void CheckMsg(VorzeA10CycloneCmd aMsg) { aMsg.Id.Should().Be(4); aMsg.DeviceIndex.Should().Be(2); aMsg.Speed.Should().Be(50); aMsg.Clockwise.Should().Be(true); } var msg = new VorzeA10CycloneCmd(2, 50, true, 4); CheckMsg(msg); var newMsg = CheckParsedVersion <VorzeA10CycloneCmd>(msg, 1, "[{\"VorzeA10CycloneCmd\":{\"Clockwise\":true,\"Speed\":50,\"DeviceIndex\":2,\"Id\":4}}]"); CheckMsg(newMsg); newMsg = CheckParsedVersion <VorzeA10CycloneCmd>(msg, 0, "[{\"VorzeA10CycloneCmd\":{\"Clockwise\":true,\"Speed\":50,\"DeviceIndex\":2,\"Id\":4}}]"); CheckMsg(newMsg); msg.Invoking(aMsg => aMsg.Speed = 1000).Should().Throw <ArgumentException>(); }
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(); } }