Skip to content

Commit de81e26

Browse files
blackspherefollowerqdot
authored andcommitted
feat: Adding protocol support for WeVibe Vector
This should also work for the Moxie; however, these new devices seem to require pairing before they'll respond. I haven't worked out that magic yet though, but once paired the device does not required the pairing to be retained (the adapter address must be stored on the device). To get the Vector into pairing mode, hold down the power button for 5 seconds (it'll buzz, but don't release) then hit pair in Bluetooth LE explorer app. I'll investigate the pairing logic in that app at some point soon.
1 parent 6ccdf4a commit de81e26

1 file changed

Lines changed: 50 additions & 5 deletions

File tree

Buttplug/Devices/Protocols/WeVibeProtocol.cs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// </copyright>
66

77
using System;
8+
using System.Collections.Generic;
89
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
@@ -26,9 +27,25 @@ internal class WeVibeProtocol : ButtplugDeviceProtocol
2627
"Nova",
2728
"NOVAV2",
2829
"Sync",
30+
"Vector",
31+
};
32+
33+
private static readonly Dictionary<string, string> NameMap = new Dictionary<string, string>()
34+
{
35+
{ "Cougar", "4 Plus" },
36+
{ "4plus", "4 Plus" },
37+
{ "classic", "Classic" },
38+
{ "NOVAV2", "Nova" },
39+
};
40+
41+
private static readonly string[] EightBitSpeed =
42+
{
43+
"Moxie",
44+
"Vector",
2945
};
3046

3147
private readonly uint _vibratorCount = 1;
48+
private readonly bool _eightBitSpeed = false;
3249
private readonly double[] _vibratorSpeed = { 0, 0 };
3350

3451
public WeVibeProtocol(IButtplugLogManager aLogManager,
@@ -42,6 +59,16 @@ public WeVibeProtocol(IButtplugLogManager aLogManager,
4259
_vibratorCount = 2;
4360
}
4461

62+
if (NameMap.ContainsKey(aInterface.Name))
63+
{
64+
Name = $"WeVibe {NameMap[aInterface.Name]}";
65+
}
66+
67+
if (EightBitSpeed.Contains(aInterface.Name))
68+
{
69+
_eightBitSpeed = true;
70+
}
71+
4572
AddMessageHandler<SingleMotorVibrateCmd>(HandleSingleMotorVibrateCmd);
4673
AddMessageHandler<VibrateCmd>(HandleVibrateCmd, new MessageAttributes() { FeatureCount = _vibratorCount });
4774
AddMessageHandler<StopDeviceCmd>(HandleStopDeviceCmd);
@@ -82,18 +109,36 @@ private async Task<ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg,
82109

83110
SentVibration = true;
84111

85-
var rSpeedInt = Convert.ToUInt16(_vibratorSpeed[0] * 15);
86-
var rSpeedExt = Convert.ToUInt16(_vibratorSpeed[_vibratorCount - 1] * 15);
87-
88112
// 0f 03 00 bc 00 00 00 00
89113
var data = new byte[] { 0x0f, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00 };
90-
data[3] = Convert.ToByte(rSpeedExt); // External
91-
data[3] |= Convert.ToByte(rSpeedInt << 4); // Internal
114+
var rSpeedInt = 0;
115+
var rSpeedExt = 0;
116+
117+
if (_eightBitSpeed)
118+
{
119+
rSpeedInt = Convert.ToUInt16(_vibratorSpeed[0] * 12);
120+
rSpeedExt = Convert.ToUInt16(_vibratorSpeed[_vibratorCount - 1] * 12);
121+
122+
data[3] = Convert.ToByte(rSpeedExt + 3); // External
123+
data[4] = Convert.ToByte(rSpeedInt + 3); // Internal
124+
data[5] = Convert.ToByte(rSpeedInt == 0 ? 0 : 1);
125+
data[5] |= Convert.ToByte(rSpeedExt == 0 ? 0 : 2);
126+
}
127+
else
128+
{
129+
rSpeedInt = Convert.ToUInt16(_vibratorSpeed[0] * 15);
130+
rSpeedExt = Convert.ToUInt16(_vibratorSpeed[_vibratorCount - 1] * 15);
131+
132+
data[3] = Convert.ToByte(rSpeedExt); // External
133+
data[3] |= Convert.ToByte(rSpeedInt << 4); // Internal
134+
}
92135

93136
// ReSharper disable once InvertIf
94137
if (rSpeedInt == 0 && rSpeedExt == 0)
95138
{
96139
data[1] = 0x00;
140+
data[3] = 0x00;
141+
data[4] = 0x00;
97142
data[5] = 0x00;
98143
}
99144

0 commit comments

Comments
 (0)