Skip to content

Commit f16e69b

Browse files
blackspherefollowerqdot
authored andcommitted
Adding OhMiBod Fuse support
Also fixing some non-returned errors in the xinput driver
1 parent a83a328 commit f16e69b

3 files changed

Lines changed: 149 additions & 7 deletions

File tree

Buttplug.Server.Managers.XInputGamepadManager/XInputGamepadDevice.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ private Task<ButtplugMessage> HandleStopDeviceCmd(ButtplugDeviceMessage aMsg)
2929

3030
private Task<ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg)
3131
{
32-
var cmdMsg = aMsg as SingleMotorVibrateCmd;
33-
34-
if (cmdMsg is null)
32+
if (!(aMsg is SingleMotorVibrateCmd cmdMsg))
3533
{
3634
return Task.FromResult<ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"));
3735
}
@@ -47,15 +45,14 @@ private Task<ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage
4745

4846
private Task<ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg)
4947
{
50-
var cmdMsg = aMsg as VibrateCmd;
51-
if (cmdMsg is null)
48+
if (!(aMsg is VibrateCmd cmdMsg))
5249
{
5350
return Task.FromResult<ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler"));
5451
}
5552

5653
if (cmdMsg.Speeds.Count < 1 || cmdMsg.Speeds.Count > 2)
5754
{
58-
Task.FromResult<ButtplugMessage>(new Error(
55+
return Task.FromResult<ButtplugMessage>(new Error(
5956
"VibrateCmd requires between 1 and 2 vectors for this device.",
6057
Error.ErrorClass.ERROR_DEVICE,
6158
cmdMsg.Id));
@@ -65,7 +62,7 @@ private Task<ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg)
6562
{
6663
if (vi.Index < 0 || vi.Index >= 2)
6764
{
68-
Task.FromResult<ButtplugMessage>(new Error(
65+
return Task.FromResult<ButtplugMessage>(new Error(
6966
$"Index {vi.Index} is out of bounds for VibrateCmd for this device.",
7067
Error.ErrorClass.ERROR_DEVICE,
7168
cmdMsg.Id));

Buttplug.Server/Bluetooth/BluetoothSubtypeManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ protected BluetoothSubtypeManager([NotNull] IButtplugLogManager aLogManager)
2929
new LovenseRev5BluetoothInfo(),
3030
new LovenseRev6BluetoothInfo(),
3131
new MagicMotionBluetoothInfo(),
32+
new OhMiBodFuseBluetoothInfo(),
3233
new VibratissimoBluetoothInfo(),
3334
new VorzeA10CycloneInfo(),
3435
new WeVibeBluetoothInfo(),
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using Buttplug.Core;
5+
using Buttplug.Core.Messages;
6+
using JetBrains.Annotations;
7+
8+
namespace Buttplug.Server.Bluetooth.Devices
9+
{
10+
internal class OhMiBodFuseBluetoothInfo : IBluetoothDeviceInfo
11+
{
12+
public enum Chrs : uint
13+
{
14+
Tx = 0,
15+
RxTouch = 1,
16+
RxAccel = 2,
17+
}
18+
19+
public string[] Names { get; } = { "Fuse" };
20+
21+
public Guid[] Services { get; } = { new Guid("88f82580-0000-01e6-aace-0002a5d5c51b") };
22+
23+
public Guid[] Characteristics { get; } =
24+
{
25+
// tx
26+
new Guid("88f82581-0000-01e6-aace-0002a5d5c51b"),
27+
28+
// rx (touch)
29+
new Guid("88f82582-0000-01e6-aace-0002a5d5c51b"),
30+
31+
// rx (accellorometer?)
32+
new Guid("88f82584-0000-01e6-aace-0002a5d5c51b"),
33+
};
34+
35+
public IButtplugDevice CreateDevice(IButtplugLogManager aLogManager,
36+
IBluetoothDeviceInterface aInterface)
37+
{
38+
return new OhMiBodFuse(aLogManager, aInterface, this);
39+
}
40+
}
41+
42+
internal class OhMiBodFuse : ButtplugBluetoothDevice
43+
{
44+
private readonly double[] _vibratorSpeeds = { 0, 0 };
45+
46+
public OhMiBodFuse([NotNull] IButtplugLogManager aLogManager,
47+
[NotNull] IBluetoothDeviceInterface aInterface,
48+
[NotNull] IBluetoothDeviceInfo aInfo)
49+
: base(aLogManager,
50+
$"OhMiBod {aInterface.Name}",
51+
aInterface,
52+
aInfo)
53+
{
54+
MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
55+
MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes() { FeatureCount = 2 }));
56+
MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
57+
}
58+
59+
private async Task<ButtplugMessage> HandleStopDeviceCmd([NotNull] ButtplugDeviceMessage aMsg)
60+
{
61+
BpLogger.Debug("Stopping Device " + Name);
62+
return await HandleVibrateCmd(new VibrateCmd(aMsg.DeviceIndex,
63+
new List<VibrateCmd.VibrateSubcommand>()
64+
{
65+
new VibrateCmd.VibrateSubcommand(0, 0),
66+
new VibrateCmd.VibrateSubcommand(1, 0),
67+
},
68+
aMsg.Id));
69+
}
70+
71+
private async Task<ButtplugMessage> HandleSingleMotorVibrateCmd([NotNull] ButtplugDeviceMessage aMsg)
72+
{
73+
if (!(aMsg is SingleMotorVibrateCmd cmdMsg))
74+
{
75+
return BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler");
76+
}
77+
78+
if (Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001 && Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001)
79+
{
80+
return new Ok(cmdMsg.Id);
81+
}
82+
83+
return await HandleVibrateCmd(new VibrateCmd(cmdMsg.DeviceIndex,
84+
new List<VibrateCmd.VibrateSubcommand>()
85+
{
86+
new VibrateCmd.VibrateSubcommand(0, cmdMsg.Speed),
87+
new VibrateCmd.VibrateSubcommand(1, cmdMsg.Speed),
88+
},
89+
cmdMsg.Id));
90+
}
91+
92+
private async Task<ButtplugMessage> HandleVibrateCmd([NotNull] ButtplugDeviceMessage aMsg)
93+
{
94+
if (!(aMsg is VibrateCmd cmdMsg))
95+
{
96+
return BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler");
97+
}
98+
99+
if (cmdMsg.Speeds.Count < 1 || cmdMsg.Speeds.Count > 2)
100+
{
101+
return new Error(
102+
"VibrateCmd requires between 1 and 2 vectors for this device.",
103+
Error.ErrorClass.ERROR_DEVICE,
104+
cmdMsg.Id);
105+
}
106+
107+
var changed = false;
108+
foreach (var vi in cmdMsg.Speeds)
109+
{
110+
if (vi.Index >= 2)
111+
{
112+
return new Error(
113+
$"Index {vi.Index} is out of bounds for VibrateCmd for this device.",
114+
Error.ErrorClass.ERROR_DEVICE,
115+
cmdMsg.Id);
116+
}
117+
118+
if (Math.Abs(_vibratorSpeeds[vi.Index] - vi.Speed) < 0.0001)
119+
{
120+
continue;
121+
}
122+
123+
_vibratorSpeeds[vi.Index] = vi.Speed;
124+
changed = true;
125+
}
126+
127+
if (!changed)
128+
{
129+
return new Ok(cmdMsg.Id);
130+
}
131+
132+
var data = new[]
133+
{
134+
(byte)Convert.ToUInt16(_vibratorSpeeds[1] * 100),
135+
(byte)Convert.ToUInt16(_vibratorSpeeds[0] * 100),
136+
(byte)0x00,
137+
};
138+
139+
return await Interface.WriteValue(aMsg.Id,
140+
Info.Characteristics[(uint)FleshlightLaunchBluetoothInfo.Chrs.Tx],
141+
data);
142+
}
143+
}
144+
}

0 commit comments

Comments
 (0)