private async Task <ButtplugMessage> HandleLinearCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckMessageHandler <LinearCmd>(aMsg); if (cmdMsg.Vectors.Count > 1) { throw new ButtplugDeviceException( "LinearCmd requires 1 vector for this device.", cmdMsg.Id); } var command = new byte[11]; // Vector commands start with 0x02; command[0] = 0x02; // Since we're simulating linear movement here, we'll move both belts in the same direction. command[1] = (byte)RealTouchComponents.U; // If we're moving backward, add 0x80 to our direction component. if (cmdMsg.Vectors[0].Position < _currentPosition) { command[1] += 0x80; } var speed = FleshlightHelper.GetSpeed(Math.Abs(cmdMsg.Vectors[0].Position - _currentPosition), cmdMsg.Vectors[0].Duration); _currentPosition = cmdMsg.Vectors[0].Position; // This is our speed, or "magnitude" in CDK-speak. Right now, we'll // use the position differential like the fleshlight. Not super // thrilled with this idea, but blame everyone who decided the // Fleshlight Launch was the only f*****g toy to ever exist. // // Also, on my RealTouches, if the speed goes below about 40, things // basically stop moving. Make sure our speed doesn't dip below that. const double speedMin = 40; command[2] = (byte)(speedMin + ((0xff - speedMin) * speed)); Debug.WriteLine((byte)(0xff * speed)); // This is our duration, in milliseconds, 16-bit, LE across the two bytes. command[3] = (byte)(cmdMsg.Vectors[0].Duration & 0xff); command[4] = (byte)((cmdMsg.Vectors[0].Duration & 0xff00) >> 0x8); // In envelope, Same magnitude/duration as last 3 bytes. // g[5] = inMagnitude // g[6] = inDuration & 0xff // g[7] = (inDuration & 0xff00) >> 0x8 // Out envelope, Same magnitude/duration as last 3 bytes. // g[9] = outMagnitude // g[9] = outDuration & 0xff // g[10] = (outDuration & 0xff00) >> 0x8 var cmd = GetCommandArray(command); await Interface.WriteValueAsync(cmd, aToken); return(new Ok(aMsg.Id)); }
private async Task <ButtplugMessage> HandleLinearCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <LinearCmd>(aMsg, 1); var v = cmdMsg.Vectors[0]; // For now, generate speeds that are similar to the fleshlight // launch. The scale is actually far different, but this is better // than nothing. return(await HandleFleshlightLaunchFW12Cmd(new FleshlightLaunchFW12Cmd(cmdMsg.DeviceIndex, Convert.ToUInt32(FleshlightHelper.GetSpeed(Math.Abs(_lastPosition - v.Position), v.Duration) * 99), Convert.ToUInt32(v.Position * 99), cmdMsg.Id), aToken).ConfigureAwait(false)); }
private async Task <ButtplugMessage> HandleLinearCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckGenericMessageHandler <LinearCmd>(aMsg, 1); var v = cmdMsg.Vectors[0]; return(await HandleFleshlightLaunchFW12Cmd(new FleshlightLaunchFW12Cmd(cmdMsg.DeviceIndex, Convert.ToUInt32(FleshlightHelper.GetSpeed(Math.Abs(_lastPosition - v.Position), v.Duration) * 99), Convert.ToUInt32(v.Position * 99), cmdMsg.Id), aToken).ConfigureAwait(false)); }
private async Task <ButtplugMessage> HandleLinearCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken) { var cmdMsg = CheckMessageHandler <LinearCmd>(aMsg); if (cmdMsg.Vectors.Count != 1) { throw new ButtplugDeviceException(BpLogger, "LinearCmd requires 1 vector for this device.", cmdMsg.Id); } foreach (var v in cmdMsg.Vectors) { if (v.Index != 0) { throw new ButtplugDeviceException(BpLogger, $"Index {v.Index} is out of bounds for LinearCmd for this device.", cmdMsg.Id); } return(await HandleFleshlightLaunchCmd(new FleshlightLaunchFW12Cmd(cmdMsg.DeviceIndex, Convert.ToUInt32(FleshlightHelper.GetSpeed(Math.Abs((_position / 100) - v.Position), v.Duration) * 99), Convert.ToUInt32(v.Position * 99), cmdMsg.Id), aToken).ConfigureAwait(false)); } return(new Ok(aMsg.Id)); }