Skip to content

Commit 93dc60a

Browse files
blackspherefollowerqdot
authored andcommitted
Adding support for the MagicMotion Smart Mini Vibe
1 parent 1bdb5e9 commit 93dc60a

4 files changed

Lines changed: 103 additions & 6 deletions

File tree

Buttplug.Server.Managers.UWPBluetoothManager/UWPBluetoothDeviceFactory.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Windows.Devices.Bluetooth;
99
using Windows.Devices.Bluetooth.Advertisement;
1010
using Windows.Devices.Bluetooth.GenericAttributeProfile;
11+
using System.Collections.Generic;
1112

1213
namespace Buttplug.Server.Managers.UWPBluetoothManager
1314
{
@@ -32,30 +33,35 @@ public UWPBluetoothDeviceFactory([NotNull] IButtplugLogManager aLogManager, [Not
3233

3334
public bool MayBeDevice(BluetoothLEAdvertisement aAdvertisement)
3435
{
35-
if (_deviceInfo.Names.Any() && !_deviceInfo.Names.Contains(aAdvertisement.LocalName))
36+
var advertName = aAdvertisement.LocalName;
37+
var advertGUIDs = new List<Guid>();
38+
advertGUIDs.AddRange(aAdvertisement.ServiceUuids);
39+
40+
if (_deviceInfo.Names.Any() && !_deviceInfo.Names.Contains(advertName))
3641
{
3742
return false;
3843
}
39-
else if (_deviceInfo.Names.Any() && !aAdvertisement.ServiceUuids.Any())
44+
45+
if (_deviceInfo.Names.Any() && !advertGUIDs.Any())
4046
{
41-
_bpLogger.Debug("Found " + aAdvertisement.LocalName + " for " + _deviceInfo.GetType().ToString());
47+
_bpLogger.Debug("Found " + advertName + " for " + _deviceInfo.GetType().ToString());
4248
_bpLogger.Debug("No advertised services?");
4349
return true;
4450
}
4551

46-
_bpLogger.Debug("Found " + aAdvertisement.LocalName + " for " + _deviceInfo.GetType().ToString());
52+
_bpLogger.Debug("Found " + advertName + " for " + _deviceInfo.GetType().ToString());
4753
foreach (var s in _deviceInfo.Services)
4854
{
4955
_bpLogger.Debug("Expecting " + s.ToString());
5056
}
5157

52-
foreach (var s in aAdvertisement.ServiceUuids)
58+
foreach (var s in advertGUIDs)
5359
{
5460
_bpLogger.Debug("Got " + s.ToString());
5561
}
5662

5763
// Intersect doesn't intersect until the enumerator is called
58-
var sv = _deviceInfo.Services.Intersect(aAdvertisement.ServiceUuids);
64+
var sv = _deviceInfo.Services.Intersect(advertGUIDs);
5965
foreach (var s in sv)
6066
{
6167
_bpLogger.Debug("Matched " + s.ToString());
@@ -91,6 +97,11 @@ public async Task<IButtplugDevice> CreateDeviceAsync([NotNull] BluetoothLEDevice
9197
return null;
9298
}
9399

100+
foreach (var s in chrResult.Characteristics)
101+
{
102+
_bpLogger.Trace("Found characteristics UUID: " + s.Uuid + " (" + aDevice.Name + ")");
103+
}
104+
94105
var chrs = from x in chrResult.Characteristics
95106
where _deviceInfo.Characteristics.Contains(x.Uuid)
96107
select x;

Buttplug.Server/Bluetooth/BluetoothSubtypeManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protected BluetoothSubtypeManager([NotNull] IButtplugLogManager aLogManager)
2525
new LovenseRev1BluetoothInfo(),
2626
new LovenseRev2BluetoothInfo(),
2727
new LovenseRev3BluetoothInfo(),
28+
new MagicMotionBluetoothInfo(),
2829
new VibratissimoBluetoothInfo(),
2930
new VorzeA10CycloneInfo(),
3031
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Text;
3+
using System.Threading.Tasks;
4+
using Buttplug.Core;
5+
using Buttplug.Core.Messages;
6+
7+
namespace Buttplug.Server.Bluetooth.Devices
8+
{
9+
internal class MagicMotionBluetoothInfo : IBluetoothDeviceInfo
10+
{
11+
public enum Chrs : uint
12+
{
13+
Tx = 0,
14+
Rx,
15+
}
16+
17+
/*
18+
* This has 6 services! Not sure what does what yet
19+
*
20+
* 78667579-7b48-43db-b8c5-7928a6b0a335 // Magic Motion's primary
21+
* 00001800-0000-1000-8000-00805f9b34fb
22+
* 00001801-0000-1000-8000-00805f9b34fb
23+
* 3d3cbc0e-f76b-11e3-8fcd-b2227cce2b54 // Unknown service
24+
* 0000180f-0000-1000-8000-00805f9b34fb
25+
* 0000180a-0000-1000-8000-00805f9b34fb
26+
*/
27+
28+
public Guid[] Services { get; } = { new Guid("78667579-7b48-43db-b8c5-7928a6b0a335") };
29+
30+
public string[] Names { get; } =
31+
{
32+
"Smart Mini Vibe"
33+
};
34+
35+
public Guid[] Characteristics { get; } =
36+
{
37+
// tx characteristic
38+
new Guid("78667579-7b48-43db-b8c5-7928a6b0a335"),
39+
40+
// other characteristic... this one's advertised
41+
new Guid("78667579-a914-49a4-8333-aa3c0cd8fedc"),
42+
};
43+
44+
public IButtplugDevice CreateDevice(IButtplugLogManager aLogManager,
45+
IBluetoothDeviceInterface aInterface)
46+
{
47+
return new MagicMotion(aLogManager,
48+
aInterface);
49+
}
50+
}
51+
52+
internal class MagicMotion : ButtplugBluetoothDevice
53+
{
54+
public MagicMotion(IButtplugLogManager aLogManager,
55+
IBluetoothDeviceInterface aInterface)
56+
: base(aLogManager,
57+
$"MagicMotion Device ({aInterface.Name})",
58+
aInterface)
59+
{
60+
MsgFuncs.Add(typeof(SingleMotorVibrateCmd), HandleSingleMotorVibrateCmd);
61+
MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
62+
}
63+
64+
private async Task<ButtplugMessage> HandleStopDeviceCmd(ButtplugDeviceMessage aMsg)
65+
{
66+
return await HandleSingleMotorVibrateCmd(new SingleMotorVibrateCmd(aMsg.DeviceIndex, 0, aMsg.Id));
67+
}
68+
69+
private async Task<ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg)
70+
{
71+
var cmdMsg = aMsg as SingleMotorVibrateCmd;
72+
if (cmdMsg is null)
73+
{
74+
return BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler");
75+
}
76+
77+
var data = new byte[] { 0x0b, 0xff, 0x04, 0x0a, 0x32, 0x32, 0x00, 0x04, 0x08, 0x00, 0x64, 0x00 };
78+
data[9] = Convert.ToByte(cmdMsg.Speed * byte.MaxValue);
79+
80+
// While there are 3 lovense revs right now, all of the characteristic arrays are the same.
81+
return await Interface.WriteValue(aMsg.Id, (uint)MagicMotionBluetoothInfo.Chrs.Tx, data);
82+
}
83+
}
84+
}

Buttplug.Server/Buttplug.Server.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<Compile Include="Bluetooth\ButtplugBluetoothDevice.cs" />
5252
<Compile Include="Bluetooth\Devices\FleshlightLaunch.cs" />
5353
<Compile Include="Bluetooth\Devices\Kiiroo.cs" />
54+
<Compile Include="Bluetooth\Devices\MagicMotion.cs" />
5455
<Compile Include="Bluetooth\Devices\Vibratissimo.cs" />
5556
<Compile Include="Bluetooth\Devices\Lovense.cs" />
5657
<Compile Include="Bluetooth\Devices\VorzeA10Cyclone.cs" />

0 commit comments

Comments
 (0)