private async Task <ButtplugMessage> HandleLinearCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as LinearCmd; if (cmdMsg is null) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (cmdMsg.Vectors.Count != 1) { return(new Error( "LinearCmd requires 1 vector for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } foreach (var v in cmdMsg.Vectors) { if (v.Index != 0) { return(new Error( $"Index {v.Index} is out of bounds for LinearCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } return(await HandleFleshlightLaunchRawCmd(new FleshlightLaunchFW12Cmd(cmdMsg.DeviceIndex, Convert.ToUInt32(FleshlightHelper.GetSpeed(Math.Abs(_lastPosition - v.Position), v.Duration) * 99), Convert.ToUInt32(v.Position * 99), cmdMsg.Id))); } return(new Ok(aMsg.Id)); }
private Task <ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as SingleMotorVibrateCmd; if (cmdMsg is null) { return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"))); } var v = new Vibration { LeftMotorSpeed = (ushort)(cmdMsg.Speed * ushort.MaxValue), RightMotorSpeed = (ushort)(cmdMsg.Speed * 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))); } return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, e.Message))); } return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id))); }
private Task <ButtplugMessage> HandleFleshlightLaunchCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is FleshlightLaunchFW12Cmd cmdMsg)) { return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"))); } lock (_movementLock) { _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> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as SingleMotorVibrateCmd; if (cmdMsg is null) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } var rSpeed = Convert.ToUInt16(cmdMsg.Speed * 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(rSpeed); // External data[3] |= Convert.ToByte(rSpeed << 4); // Internal if (rSpeed == 0) { data[1] = 0x00; data[5] = 0x00; } return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)WeVibeBluetoothInfo.Chrs.Tx], data)); }
private async Task <ButtplugMessage> HandleRotateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is RotateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (cmdMsg.Rotations.Count != 1) { return(new Error( "RotateCmd requires 1 vector for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } foreach (var i in cmdMsg.Rotations) { if (i.Index != 0) { return(new Error( $"Index {i.Index} is out of bounds for RotateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } return(await HandleVorzeA10CycloneCmd(new VorzeA10CycloneCmd(cmdMsg.DeviceIndex, Convert.ToUInt32(i.Speed * 99), i.Clockwise, cmdMsg.Id))); } return(new Ok(cmdMsg.Id)); }
private async Task <ButtplugMessage> HandleVibrateCmd([NotNull] 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)); } _vibratorSpeed = v.Speed; } return(await HandleKiirooRawCmd(new KiirooCmd(aMsg.DeviceIndex, Convert.ToUInt16(_vibratorSpeed * 4), 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 || cmdMsg.Speeds.Count > _vibratorCount) { return(new Error( $"VibrateCmd requires between 1 and {_vibratorCount} vectors for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } var changed = false; foreach (var v in cmdMsg.Speeds) { if (v.Index >= _vibratorCount) { 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[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.WriteValue(aMsg.Id, (uint)WeVibeBluetoothInfo.Chrs.Tx, data)); }
private async Task <ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is SingleMotorVibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } return(await HandleVibrateCmd(VibrateCmd.Create(cmdMsg.DeviceIndex, cmdMsg.Id, cmdMsg.Speed, _vibratorCount))); }
private async Task <ButtplugMessage> HandleKiirooRawCmd([NotNull] ButtplugDeviceMessage aMsg) { if (!(aMsg is KiirooCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } return(await Interface.WriteValue(cmdMsg.Id, Encoding.ASCII.GetBytes($"{cmdMsg.Position},\n"))); }
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 < 1 || cmdMsg.Speeds.Count > 2) { return(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 || vi.Index >= 2) { return(Task.FromResult <ButtplugMessage>(new Error( $"Index {vi.Index} is out of bounds for VibrateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id))); } _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))); } return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, e.Message))); } 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; } var rSpeed = Convert.ToUInt16(_vibratorSpeed * 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(rSpeed); // External data[3] |= Convert.ToByte(rSpeed << 4); // Internal if (rSpeed == 0) { data[1] = 0x00; data[5] = 0x00; } return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)WeVibeBluetoothInfo.Chrs.Tx], data)); }
private async Task <ButtplugMessage> HandleVibrateCmd([NotNull] ButtplugDeviceMessage aMsg) { if (!(aMsg is VibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (cmdMsg.Speeds.Count < 1 || cmdMsg.Speeds.Count > _devInfo.VibeCount) { return(new Error( "VibrateCmd requires between 1 and 2 vectors for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } var changed = false; foreach (var vi in cmdMsg.Speeds) { if (vi.Index >= _devInfo.VibeCount) { return(new Error( $"Index {vi.Index} is out of bounds for VibrateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } if (Math.Abs(_vibratorSpeeds[vi.Index] - vi.Speed) < 0.0001) { continue; } _vibratorSpeeds[vi.Index] = vi.Speed; changed = true; } if (!changed) { return(new Ok(cmdMsg.Id)); } 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), }; return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)FleshlightLaunchBluetoothInfo.Chrs.Tx], data)); }
private Task <ButtplugMessage> HandleRotateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is RotateCmd cmdMsg)) { return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"))); } if (cmdMsg.Rotations.Count != 1) { return(Task.FromResult <ButtplugMessage>(new Error( "RotateCmd requires 1 vector for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id))); } var changed = false; foreach (var i in cmdMsg.Rotations) { if (i.Index != 0) { return(Task.FromResult <ButtplugMessage>(new Error( $"Index {i.Index} is out of bounds for RotateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id))); } changed |= _clockwise != i.Clockwise; changed |= Math.Abs(_speed - i.Speed) > 0.001; _clockwise = i.Clockwise; _speed = i.Speed; } if (!changed) { return(Task.FromResult <ButtplugMessage>(new Ok(cmdMsg.Id))); } // [6] pause 0x30 + 0-1 // [7] speed 0x30 + 0-10 // [9] mode 0x30 + 0-9 (0 forwards, 1 backwards, 2+ patterns) var data = new byte[] { 0x00, 0x3C, 0x30, 0x31, 0x35, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x01, 0x02, 0x03, 0x68, 0x3E }; data[6] += 0; data[7] += Convert.ToByte(_clockwise ? 0 : 1); data[8] += Convert.ToByte(_speed * 10); return(WriteData(data) ? Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id)) : Task.FromResult <ButtplugMessage>(new Error("Failed to send command", Error.ErrorClass.ERROR_DEVICE, aMsg.Id))); }
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")); } return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)YoucupsBluetoothInfo.Chrs.Tx], Encoding.ASCII.GetBytes($"$SYS,{(int)(cmdMsg.Speed * 8), 1}?"))); }
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")); } // While there are 3 lovense revs right now, all of the characteristic arrays are the same. return(await Interface.WriteValue(aMsg.Id, (uint)LovenseRev1BluetoothInfo.Chrs.Tx, Encoding.ASCII.GetBytes($"Vibrate:{(int)(cmdMsg.Speed * 20)};"))); }
private async Task <ButtplugMessage> HandleKiirooRawCmd([NotNull] ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as KiirooCmd; if (cmdMsg is null) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } return(await Interface.WriteValue(cmdMsg.Id, (uint)KiirooBluetoothInfo.Chrs.Tx, Encoding.ASCII.GetBytes($"{cmdMsg.Position},\n"))); }
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 != _vibratorCount) { return(new Error( $"VibrateCmd requires between 1 and {_vibratorCount} vectors for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } var changed = false; foreach (var v in cmdMsg.Speeds) { if (v.Index >= _vibratorCount) { 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[v.Index]) > 0.001)) { continue; } changed = true; _vibratorSpeed[v.Index] = v.Speed; } if (!changed) { return(new Ok(cmdMsg.Id)); } // Map a 0 - 100% value to a 0 - 3 value since 0 * x == 0 this will turn off the vibe if // speed is 0.00 int mode = (int)Math.Ceiling(_vibratorSpeed[0] * 3); var data = new byte[] { Convert.ToByte(mode) }; return(await Interface.WriteValue(aMsg.Id, (uint)LiBoBluetoothInfo.Chrs.WriteVibrate, data)); }
private async Task <ButtplugMessage> HandleFleshlightLaunchRawCmd(ButtplugDeviceMessage aMsg) { // TODO: Split into Command message and Control message? (Issue #17) var cmdMsg = aMsg as FleshlightLaunchFW12Cmd; if (cmdMsg is null) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } return(await Interface.WriteValue(aMsg.Id, (uint)FleshlightLaunchBluetoothInfo.Chrs.Tx, new[] { (byte)cmdMsg.Position, (byte)cmdMsg.Speed })); }
private async Task <ButtplugMessage> HandleRotateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is RotateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } var dirChange = false; var speedChange = false; if (cmdMsg.Rotations.Count != 1) { return(new Error( "RotateCmd requires 1 vector for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } foreach (var vi in cmdMsg.Rotations) { if (vi.Index != 0) { return(new Error( $"Index {vi.Index} is out of bounds for RotateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } speedChange = Math.Abs(_rotateSpeed - vi.Speed) > 0.0001; _rotateSpeed = vi.Speed; dirChange = _clockwise != vi.Clockwise; } if (dirChange) { _clockwise = !_clockwise; await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)LovenseRev1BluetoothInfo.Chrs.Tx], Encoding.ASCII.GetBytes($"RotateChange;")); } if (!speedChange) { return(new Ok(cmdMsg.Id)); } return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)LovenseRev1BluetoothInfo.Chrs.Tx], Encoding.ASCII.GetBytes($"Rotate:{(int)(_rotateSpeed * 20)};"))); }
private Task <ButtplugMessage> HandleVorzeA10CycloneCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is VorzeA10CycloneCmd cmdMsg)) { return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"))); } return(HandleRotateCmd(new RotateCmd(cmdMsg.DeviceIndex, new List <RotateCmd.RotateSubcommand> { new RotateCmd.RotateSubcommand(0, Convert.ToDouble(cmdMsg.Speed) / 99, cmdMsg.Clockwise), }, cmdMsg.Id))); }
private async Task <ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is SingleMotorVibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } return(await HandleVibrateCmd(new VibrateCmd(cmdMsg.DeviceIndex, new List <VibrateCmd.VibrateSubcommand>() { new VibrateCmd.VibrateSubcommand(0, cmdMsg.Speed) }, cmdMsg.Id))); }
private async Task <ButtplugMessage> HandleFleshlightLaunchRawCmd(ButtplugDeviceMessage aMsg) { // TODO: Split into Command message and Control message? (Issue #17) if (!(aMsg is FleshlightLaunchFW12Cmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } _lastPosition = Convert.ToDouble(cmdMsg.Position) / 99; return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)FleshlightLaunchBluetoothInfo.Chrs.Tx], new[] { (byte)cmdMsg.Position, (byte)cmdMsg.Speed })); }
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; } 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(_vibratorSpeed * byte.MaxValue); data[1] = 0x00; return(await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)VibratissimoBluetoothInfo.Chrs.TxSpeed], data)); }
private async Task <ButtplugMessage> HandleVorzeA10CycloneCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as VorzeA10CycloneCmd; if (cmdMsg is null) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } var rawSpeed = (byte)(((byte)(cmdMsg.Clockwise ? 1 : 0)) << 7 | (byte)cmdMsg.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) { if (!(aMsg is VibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } if (cmdMsg.Speeds.Count < 1 || cmdMsg.Speeds.Count > 6) { return(new Error( "VibrateCmd requires 1-6 commands for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } var newVibratorSpeeds = (byte[])_vibratorSpeeds.Clone(); foreach (var v in cmdMsg.Speeds) { if (v.Index > 5) { return(new Error( $"Index {v.Index} is out of bounds for VibrateCmd for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } newVibratorSpeeds[v.Index] = (byte)(v.Speed * MaxSpeed); } if (newVibratorSpeeds.SequenceEqual(_vibratorSpeeds)) { return(new Ok(aMsg.Id)); } _vibratorSpeeds = newVibratorSpeeds; if (!_updateValueTimer.Enabled) { // Run the update handler once to start the command MysteryVibeUpdateHandler(null, null); // Start the timer to it will keep updating _updateValueTimer.Enabled = true; } return(new Ok(aMsg.Id)); }
private async Task <ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) { if (!(aMsg is SingleMotorVibrateCmd cmdMsg)) { return(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); } var speeds = new List <VibrateCmd.VibrateSubcommand>(); for (uint i = 0; i < _vibratorCount; i++) { speeds.Add(new VibrateCmd.VibrateSubcommand(i, cmdMsg.Speed)); } return(await HandleVibrateCmd(new VibrateCmd(cmdMsg.DeviceIndex, speeds, cmdMsg.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 == 0 || cmdMsg.Speeds.Count > _vibratorCount) { return(new Error( _vibratorCount == 1 ? "VibrateCmd requires 1 vector for this device." : $"VibrateCmd requires between 1 and {_vibratorCount} vectors for this device.", Error.ErrorClass.ERROR_DEVICE, cmdMsg.Id)); } foreach (var v in cmdMsg.Speeds) { if (v.Index >= _vibratorCount) { 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 - _vibratorSpeeds[v.Index]) < 0.0001) { continue; } _vibratorSpeeds[v.Index] = v.Speed; var vId = _vibratorCount == 1 ? string.Empty : string.Empty + (v.Index + 1); var res = await Interface.WriteValue(aMsg.Id, Info.Characteristics[(uint)LovenseRev1BluetoothInfo.Chrs.Tx], Encoding.ASCII.GetBytes($"Vibrate{vId}:{(int)(_vibratorSpeeds[v.Index] * 20)};")); if ((res as Ok) == null) { return(res); } } return(new Ok(cmdMsg.Id)); }
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[] { 0x0b, 0xff, 0x04, 0x0a, 0x32, 0x32, 0x00, 0x04, 0x08, 0x00, 0x64, 0x00 }; data[9] = Convert.ToByte(cmdMsg.Speed * 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 Task <ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as SingleMotorVibrateCmd; if (cmdMsg is null) { return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"))); } var speeds = new List <VibrateCmd.VibrateSubcommand>(); for (uint i = 0; i < 2; i++) { speeds.Add(new VibrateCmd.VibrateSubcommand(i, cmdMsg.Speed)); } return(HandleVibrateCmd(new VibrateCmd(cmdMsg.DeviceIndex, speeds, cmdMsg.Id))); }
private Task <ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) { var cmdMsg = aMsg as SingleMotorVibrateCmd; if (cmdMsg is null) { return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"))); } var v = new Vibration { LeftMotorSpeed = (ushort)(cmdMsg.Speed * ushort.MaxValue), RightMotorSpeed = (ushort)(cmdMsg.Speed * ushort.MaxValue), }; _device.SetVibration(v); return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id))); }