Skip to content

Commit 57246e1

Browse files
committed
chore: Cleanup unused static vars in BluetoothInfo, fix header order
Was trying to have static info in BluetoothInfo classes for tests, but ended up not needing it. Cleaned up, as well as header order in Vorze tests.
1 parent 68d5443 commit 57246e1

3 files changed

Lines changed: 110 additions & 126 deletions

File tree

Buttplug.Server.Test/Bluetooth/Devices/VorzeSATests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Buttplug.Core.Messages;
1+
using System.Collections.Generic;
2+
using Buttplug.Core.Messages;
23
using Buttplug.Server.Bluetooth.Devices;
34
using Buttplug.Server.Test.Util;
45
using JetBrains.Annotations;
56
using NUnit.Framework;
6-
using System.Collections.Generic;
77

88
// TODO Clean up/simplify how we handle per-device testing here.
99
namespace Buttplug.Server.Test.Bluetooth.Devices

Buttplug.Server/Bluetooth/Devices/FleshlightLaunch.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ public enum Chrs : uint
1717
Cmd = 2,
1818
};
1919

20-
public static string[] NamesInfo = { "Launch" };
21-
22-
public static string[] NamePrefixesInfo = { };
23-
24-
public static Guid[] ServicesInfo = { new Guid("88f80580-0000-01e6-aace-0002a5d5c51b") };
25-
26-
public static Dictionary<uint, Guid> CharacteristicsInfo { get; } = new Dictionary<uint, Guid>()
20+
public Dictionary<uint, Guid> Characteristics { get; } = new Dictionary<uint, Guid>()
2721
{
2822
// tx
2923
{ (uint)Chrs.Tx, new Guid("88f80581-0000-01e6-aace-0002a5d5c51b") },
@@ -35,13 +29,11 @@ public enum Chrs : uint
3529
{ (uint)Chrs.Cmd, new Guid("88f80583-0000-01e6-aace-0002a5d5c51b") },
3630
};
3731

38-
public Dictionary<uint, Guid> Characteristics { get; } = CharacteristicsInfo;
39-
40-
public Guid[] Services { get; } = ServicesInfo;
32+
public Guid[] Services { get; } = { new Guid("88f80580-0000-01e6-aace-0002a5d5c51b") };
4133

42-
public string[] Names { get; } = NamesInfo;
34+
public string[] Names { get; } = { "Launch" };
4335

44-
public string[] NamePrefixes { get; } = NamePrefixesInfo;
36+
public string[] NamePrefixes { get; } = { };
4537

4638
public IButtplugDevice CreateDevice(
4739
IButtplugLogManager aLogManager,

Buttplug.Server/Bluetooth/Devices/KiirooGen2Vibe.cs

Lines changed: 104 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ public enum Chrs : uint
1717
RxAccel = 2,
1818
}
1919

20-
public static string[] NamesInfo { get; } =
20+
public string[] Names { get; } =
2121
{
2222
"Pearl2",
2323
"Fuse",
2424
"Virtual Blowbot",
2525
};
2626

27-
public static string[] NamePrefixesInfo { get; } = { };
27+
public string[] NamePrefixes { get; } = { };
2828

29-
public static Guid[] ServicesInfo { get; } = { new Guid("88f82580-0000-01e6-aace-0002a5d5c51b") };
29+
public Guid[] Services { get; } = { new Guid("88f82580-0000-01e6-aace-0002a5d5c51b") };
3030

31-
public static Dictionary<uint, Guid> CharacteristicsInfo { get; } = new Dictionary<uint, Guid>()
31+
public Dictionary<uint, Guid> Characteristics { get; } = new Dictionary<uint, Guid>()
3232
{
3333
// tx
3434
{ (uint)Chrs.Tx, new Guid("88f82581-0000-01e6-aace-0002a5d5c51b") },
@@ -40,14 +40,6 @@ public enum Chrs : uint
4040
{ (uint)Chrs.RxAccel, new Guid("88f82584-0000-01e6-aace-0002a5d5c51b") },
4141
};
4242

43-
public Dictionary<uint, Guid> Characteristics { get; } = CharacteristicsInfo;
44-
45-
public Guid[] Services { get; } = ServicesInfo;
46-
47-
public string[] Names { get; } = NamesInfo;
48-
49-
public string[] NamePrefixes { get; } = NamePrefixesInfo;
50-
5143
public IButtplugDevice CreateDevice(IButtplugLogManager aLogManager,
5244
IBluetoothDeviceInterface aInterface)
5345
{
@@ -71,7 +63,7 @@ internal struct KiirooGen2VibeType
7163
internal static readonly Dictionary<string, KiirooGen2VibeType> DevInfos = new Dictionary<string, KiirooGen2VibeType>()
7264
{
7365
{
74-
// If we don't know what the device is, use unknown, which may not work well but also
66+
// If we don't know what the device is, use unknown, which may not work well but also
7567
// won't crash.
7668
"Unknown",
7769
new KiirooGen2VibeType
@@ -108,18 +100,18 @@ internal struct KiirooGen2VibeType
108100
VibeOrder = new[] { 0u, 1u, 2u },
109101
}
110102
},
111-
};
112-
113-
private KiirooGen2VibeType _devInfo;
114-
115-
public KiirooGen2Vibe([NotNull] IButtplugLogManager aLogManager,
116-
[NotNull] IBluetoothDeviceInterface aInterface,
117-
[NotNull] IBluetoothDeviceInfo aInfo)
118-
: base(aLogManager,
119-
"Kiiroo Unknown",
120-
aInterface,
121-
aInfo)
122-
{
103+
};
104+
105+
private KiirooGen2VibeType _devInfo;
106+
107+
public KiirooGen2Vibe([NotNull] IButtplugLogManager aLogManager,
108+
[NotNull] IBluetoothDeviceInterface aInterface,
109+
[NotNull] IBluetoothDeviceInfo aInfo)
110+
: base(aLogManager,
111+
"Kiiroo Unknown",
112+
aInterface,
113+
aInfo)
114+
{
123115
if (DevInfos.ContainsKey(aInterface.Name))
124116
{
125117
Name = $"{DevInfos[aInterface.Name].Brand} {aInterface.Name}";
@@ -128,96 +120,96 @@ public KiirooGen2Vibe([NotNull] IButtplugLogManager aLogManager,
128120
else
129121
{
130122
_devInfo = DevInfos["Unknown"];
131-
}
132-
133-
MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
134-
MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes { FeatureCount = _devInfo.VibeCount }));
135-
MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
136-
}
137-
138-
private async Task<ButtplugMessage> HandleStopDeviceCmd([NotNull] ButtplugDeviceMessage aMsg)
139-
{
140-
BpLogger.Debug("Stopping Device " + Name);
141-
var vCmds = new List<VibrateCmd.VibrateSubcommand>();
142-
for (uint i = 0; i < _devInfo.VibeCount; i++)
143-
{
144-
vCmds.Add(new VibrateCmd.VibrateSubcommand(i, 0));
145-
}
146-
147-
return await HandleVibrateCmd(new VibrateCmd(aMsg.DeviceIndex, vCmds, aMsg.Id));
148-
}
149-
150-
private async Task<ButtplugMessage> HandleSingleMotorVibrateCmd([NotNull] ButtplugDeviceMessage aMsg)
151-
{
152-
if (!(aMsg is SingleMotorVibrateCmd cmdMsg))
153-
{
154-
return BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler");
155-
}
156-
157-
if (Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001 && Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001)
158-
{
159-
return new Ok(cmdMsg.Id);
160-
}
161-
162-
var vCmds = new List<VibrateCmd.VibrateSubcommand>();
163-
for (uint i = 0; i < _devInfo.VibeCount; i++)
164-
{
165-
vCmds.Add(new VibrateCmd.VibrateSubcommand(i, cmdMsg.Speed));
166-
}
167-
168-
return await HandleVibrateCmd(new VibrateCmd(aMsg.DeviceIndex, vCmds, aMsg.Id));
169-
}
170-
171-
private async Task<ButtplugMessage> HandleVibrateCmd([NotNull] ButtplugDeviceMessage aMsg)
172-
{
173-
if (!(aMsg is VibrateCmd cmdMsg))
174-
{
175-
return BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler");
176-
}
177-
178-
if (cmdMsg.Speeds.Count < 1 || cmdMsg.Speeds.Count > _devInfo.VibeCount)
179-
{
180-
return new Error(
181-
$"VibrateCmd requires between 1 and {_devInfo.VibeCount} vectors for this device.",
182-
Error.ErrorClass.ERROR_DEVICE,
183-
cmdMsg.Id);
184-
}
185-
186-
var changed = false;
187-
foreach (var vi in cmdMsg.Speeds)
188-
{
189-
if (vi.Index >= _devInfo.VibeCount)
190-
{
191-
return new Error(
192-
$"Index {vi.Index} is out of bounds for VibrateCmd for this device.",
193-
Error.ErrorClass.ERROR_DEVICE,
194-
cmdMsg.Id);
195-
}
196-
197-
if (Math.Abs(_vibratorSpeeds[vi.Index] - vi.Speed) < 0.0001)
198-
{
199-
continue;
200-
}
201-
202-
_vibratorSpeeds[vi.Index] = vi.Speed;
203-
changed = true;
204-
}
205-
206-
if (!changed)
207-
{
208-
return new Ok(cmdMsg.Id);
209-
}
210-
211-
var data = new[]
123+
}
124+
125+
MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
126+
MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes { FeatureCount = _devInfo.VibeCount }));
127+
MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
128+
}
129+
130+
private async Task<ButtplugMessage> HandleStopDeviceCmd([NotNull] ButtplugDeviceMessage aMsg)
131+
{
132+
BpLogger.Debug("Stopping Device " + Name);
133+
var vCmds = new List<VibrateCmd.VibrateSubcommand>();
134+
for (uint i = 0; i < _devInfo.VibeCount; i++)
135+
{
136+
vCmds.Add(new VibrateCmd.VibrateSubcommand(i, 0));
137+
}
138+
139+
return await HandleVibrateCmd(new VibrateCmd(aMsg.DeviceIndex, vCmds, aMsg.Id));
140+
}
141+
142+
private async Task<ButtplugMessage> HandleSingleMotorVibrateCmd([NotNull] ButtplugDeviceMessage aMsg)
143+
{
144+
if (!(aMsg is SingleMotorVibrateCmd cmdMsg))
145+
{
146+
return BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler");
147+
}
148+
149+
if (Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001 && Math.Abs(_vibratorSpeeds[0] - cmdMsg.Speed) < 0.0001)
150+
{
151+
return new Ok(cmdMsg.Id);
152+
}
153+
154+
var vCmds = new List<VibrateCmd.VibrateSubcommand>();
155+
for (uint i = 0; i < _devInfo.VibeCount; i++)
156+
{
157+
vCmds.Add(new VibrateCmd.VibrateSubcommand(i, cmdMsg.Speed));
158+
}
159+
160+
return await HandleVibrateCmd(new VibrateCmd(aMsg.DeviceIndex, vCmds, aMsg.Id));
161+
}
162+
163+
private async Task<ButtplugMessage> HandleVibrateCmd([NotNull] ButtplugDeviceMessage aMsg)
164+
{
165+
if (!(aMsg is VibrateCmd cmdMsg))
166+
{
167+
return BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler");
168+
}
169+
170+
if (cmdMsg.Speeds.Count < 1 || cmdMsg.Speeds.Count > _devInfo.VibeCount)
171+
{
172+
return new Error(
173+
$"VibrateCmd requires between 1 and {_devInfo.VibeCount} vectors for this device.",
174+
Error.ErrorClass.ERROR_DEVICE,
175+
cmdMsg.Id);
176+
}
177+
178+
var changed = false;
179+
foreach (var vi in cmdMsg.Speeds)
180+
{
181+
if (vi.Index >= _devInfo.VibeCount)
182+
{
183+
return new Error(
184+
$"Index {vi.Index} is out of bounds for VibrateCmd for this device.",
185+
Error.ErrorClass.ERROR_DEVICE,
186+
cmdMsg.Id);
187+
}
188+
189+
if (Math.Abs(_vibratorSpeeds[vi.Index] - vi.Speed) < 0.0001)
190+
{
191+
continue;
192+
}
193+
194+
_vibratorSpeeds[vi.Index] = vi.Speed;
195+
changed = true;
196+
}
197+
198+
if (!changed)
199+
{
200+
return new Ok(cmdMsg.Id);
201+
}
202+
203+
var data = new[]
212204
{
213205
(byte)Convert.ToUInt16(_vibratorSpeeds[_devInfo.VibeOrder[0]] * 100),
214206
(byte)Convert.ToUInt16(_vibratorSpeeds[_devInfo.VibeOrder[1]] * 100),
215207
(byte)Convert.ToUInt16(_vibratorSpeeds[_devInfo.VibeOrder[2]] * 100),
216-
};
217-
218-
return await Interface.WriteValue(aMsg.Id,
219-
(uint)FleshlightLaunchBluetoothInfo.Chrs.Tx,
220-
data);
221-
}
208+
};
209+
210+
return await Interface.WriteValue(aMsg.Id,
211+
(uint)FleshlightLaunchBluetoothInfo.Chrs.Tx,
212+
data);
213+
}
222214
}
223215
}

0 commit comments

Comments
 (0)