private static async Task <VibrateStatus> HandleVibrateStart(ButtplugClientDevice device, VibrateStart vs, VibrateStatus status) { if (IsVorze(device)) { var newDirection = random(2) == 0 ? true : false; await device.SendVorzeA10CycloneCmd(Convert.ToUInt32(vs.strength * 100), newDirection); return(await vs.time.MatchAsync(async time => { await Task.Delay(time); await device.SendVorzeA10CycloneCmd(StrengthToVorzeRotation(status.strength), status.direction); return status; }, () => new VibrateStatus(vs.strength, newDirection))); } else { await device.SendVibrateCmd(vs.strength); // TODO handle intervals return(await vs.time.MatchAsync(async time => { await Task.Delay(time); await device.SendVibrateCmd(status.strength); return status; }, () => new VibrateStatus(vs.strength, false))); } }
static async Task RunRandom(ButtplugClient client, ButtplugClientDevice device) { var rnd = new Random(); while (true) { var delay = rnd.NextDouble() * 0.5 + rnd.NextDouble() * rnd.NextDouble() * 10.0; try { if (IsVorze(device)) { await device.SendVorzeA10CycloneCmd(Convert.ToUInt32(rnd.Next(101)), rnd.Next(2) == 0?true : false); } else { bool shouldStop = rnd.NextDouble() < 0.35; double strength = shouldStop ? 0 : rnd.NextDouble(); await device.SendVibrateCmd(strength); } } catch (ButtplugDeviceException e) { Console.WriteLine($"Device error: {e}"); device = await AttemptReconnect(client, device); } catch (Exception e) { Console.WriteLine("Unknown exception, attempting reconnect anyway. Exception: " + e); device = await AttemptReconnect(client, device); } await Task.Delay(TimeSpan.FromSeconds(delay)); } }
public async Task Set(ButtplugClientDevice device, DeviceCommandInformation information) { if (_client == null) { return; } try { await _clientLock.WaitAsync(); if (device.AllowedMessages.ContainsKey(typeof(FleshlightLaunchFW12Cmd))) { await device.SendFleshlightLaunchFW12Cmd(information.SpeedTransformed, information.PositionToTransformed); } else if (device.AllowedMessages.ContainsKey(typeof(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(typeof(VorzeA10CycloneCmd))) { await device.SendVorzeA10CycloneCmd(CommandConverter.LaunchToVorzeSpeed(information), information.PositionToTransformed > information.PositionFromTransformed); } } catch (Exception e) { RecordButtplugException("ButtplugAdapter.Set(bcd, dci)", e); } finally { _clientLock.Release(); } }