Skip to content

Commit 9521102

Browse files
blackspherefollowerqdot
authored andcommitted
feat: Adding support for Aneros Vivi
1 parent 99126fd commit 9521102

File tree

3 files changed

+181
-0
lines changed

3 files changed

+181
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// <copyright file="AnerosViviTests.cs" company="Nonpolynomial Labs LLC">
2+
// Buttplug C# Source Code File - Visit https://buttplug.io for more info about the project.
3+
// Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
4+
// Licensed under the BSD 3-Clause license. See LICENSE file in the project root for full license information.
5+
// </copyright>
6+
7+
// Test file, disable ConfigureAwait checking.
8+
// ReSharper disable ConsiderUsingConfigureAwait
9+
10+
usingSystem.Collections.Generic;
11+
usingSystem.Diagnostics.CodeAnalysis;
12+
usingSystem.Threading.Tasks;
13+
usingButtplug.Core.Messages;
14+
usingButtplug.Devices;
15+
usingButtplug.Devices.Protocols;
16+
usingButtplug.Test.Devices.Protocols.Utils;
17+
usingJetBrains.Annotations;
18+
usingNUnit.Framework;
19+
20+
namespaceButtplug.Test.Devices.Protocols
21+
{
22+
[SuppressMessage("StyleCop.CSharp.DocumentationRules","SA1600:ElementsMustBeDocumented",Justification="Test classes can skip documentation requirements")]
23+
[TestFixture]
24+
publicclassAnerosViviTests
25+
{
26+
[NotNull]
27+
privateProtocolTestUtilstestUtil;
28+
29+
[SetUp]
30+
publicasyncTaskInit()
31+
{
32+
testUtil=newProtocolTestUtils();
33+
awaittestUtil.SetupTest<AnerosProtocol>("Massage Demo");
34+
}
35+
36+
[Test]
37+
publicvoidTestAllowedMessages()
38+
{
39+
testUtil.TestDeviceAllowedMessages(newDictionary<System.Type,uint>()
40+
{
41+
{typeof(StopDeviceCmd),0},
42+
{typeof(SingleMotorVibrateCmd),0},
43+
{typeof(VibrateCmd),2},
44+
});
45+
}
46+
47+
// StopDeviceCmd noop test handled in GeneralDeviceTests
48+
49+
[Test]
50+
publicasyncTaskTestStopDeviceCmd()
51+
{
52+
varexpected=
53+
newList<(byte[],string)>()
54+
{
55+
(newbyte[]{0xF1,0x40},Endpoints.Tx),
56+
(newbyte[]{0xF2,0x40},Endpoints.Tx),
57+
};
58+
59+
awaittestUtil.TestDeviceMessage(newSingleMotorVibrateCmd(4,0.5),expected,false);
60+
61+
expected=
62+
newList<(byte[],string)>()
63+
{
64+
(newbyte[]{0xF1,0x00},Endpoints.Tx),
65+
(newbyte[]{0xF2,0x00},Endpoints.Tx),
66+
};
67+
68+
awaittestUtil.TestDeviceMessage(newStopDeviceCmd(4),expected,false);
69+
}
70+
71+
[Test]
72+
publicasyncTaskTestSingleMotorVibrateCmd()
73+
{
74+
varexpected=
75+
newList<(byte[],string)>()
76+
{
77+
(newbyte[]{0xF1,0x40},Endpoints.Tx),
78+
(newbyte[]{0xF2,0x40},Endpoints.Tx),
79+
};
80+
81+
awaittestUtil.TestDeviceMessage(newSingleMotorVibrateCmd(4,0.5),expected,false);
82+
}
83+
84+
[Test]
85+
publicasyncTaskTestVibrateCmd()
86+
{
87+
varexpected=
88+
newList<(byte[],string)>()
89+
{
90+
(newbyte[]{0xF1,0x40},Endpoints.Tx),
91+
(newbyte[]{0xF2,0x00},Endpoints.Tx),
92+
};
93+
94+
awaittestUtil.TestDeviceMessage(VibrateCmd.Create(4,1,0.5,1),expected,false);
95+
}
96+
97+
[Test]
98+
publicvoidTestInvalidVibrateCmd()
99+
{
100+
testUtil.TestInvalidVibrateCmd(2);
101+
}
102+
}
103+
}

Buttplug/Devices/Configuration/DeviceConfigurationManager.cs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static DeviceConfigurationManager Manager
4444
protectedDeviceConfigurationManager()
4545
{
4646
// Names in this list must match the device config file keys.
47+
AddProtocol("aneros",typeof(AnerosProtocol));
4748
AddProtocol("lovense",typeof(LovenseProtocol));
4849
AddProtocol("kiiroo-v2",typeof(KiirooGen2Protocol));
4950
AddProtocol("cueme",typeof(CuemeProtocol));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// <copyright file="AnerosProtocol.cs" company="Nonpolynomial Labs LLC">
2+
// Buttplug C# Source Code File - Visit https://buttplug.io for more info about the project.
3+
// Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
4+
// Licensed under the BSD 3-Clause license. See LICENSE file in the project root for full license information.
5+
// </copyright>
6+
7+
usingSystem;
8+
usingSystem.Threading;
9+
usingSystem.Threading.Tasks;
10+
usingButtplug.Core.Logging;
11+
usingButtplug.Core.Messages;
12+
13+
namespaceButtplug.Devices.Protocols
14+
{
15+
internalclassAnerosProtocol:ButtplugDeviceProtocol
16+
{
17+
privatereadonlydouble[]_vibratorSpeeds={0,0};
18+
19+
publicAnerosProtocol(IButtplugLogManageraLogManager,
20+
IButtplugDeviceImplaInterface)
21+
:base(aLogManager,
22+
"Aneros Vivi",
23+
aInterface)
24+
{
25+
AddMessageHandler<SingleMotorVibrateCmd>(HandleSingleMotorVibrateCmd);
26+
AddMessageHandler<VibrateCmd>(HandleVibrateCmd,newMessageAttributes(){FeatureCount=2});
27+
AddMessageHandler<StopDeviceCmd>(HandleStopDeviceCmd);
28+
}
29+
30+
privateasyncTask<ButtplugMessage>HandleStopDeviceCmd(ButtplugDeviceMessageaMsg,CancellationTokenaToken)
31+
{
32+
BpLogger.Debug("Stopping Device "+Name);
33+
returnawaitHandleSingleMotorVibrateCmd(newSingleMotorVibrateCmd(aMsg.DeviceIndex,0,aMsg.Id),aToken).ConfigureAwait(false);
34+
}
35+
36+
privateasyncTask<ButtplugMessage>HandleSingleMotorVibrateCmd(ButtplugDeviceMessageaMsg,CancellationTokenaToken)
37+
{
38+
varcmdMsg=CheckMessageHandler<SingleMotorVibrateCmd>(aMsg);
39+
40+
returnawaitHandleVibrateCmd(VibrateCmd.Create(cmdMsg.DeviceIndex,cmdMsg.Id,cmdMsg.Speed,2),aToken).ConfigureAwait(false);
41+
}
42+
43+
privateasyncTask<ButtplugMessage>HandleVibrateCmd(ButtplugDeviceMessageaMsg,CancellationTokenaToken)
44+
{
45+
varcmdMsg=CheckGenericMessageHandler<VibrateCmd>(aMsg,2);
46+
varchanged=new[]{false,false};
47+
48+
foreach(varvincmdMsg.Speeds)
49+
{
50+
if(Math.Abs(v.Speed-_vibratorSpeeds[v.Index])<0.001)
51+
{
52+
continue;
53+
}
54+
55+
changed[v.Index]=true;
56+
_vibratorSpeeds[v.Index]=v.Speed;
57+
}
58+
59+
if(changed[0]||!SentVibration)
60+
{
61+
awaitInterface.WriteValueAsync(
62+
newbyte[]{0xF1,(byte)Convert.ToUInt32(_vibratorSpeeds[0]*0x7F)},aToken)
63+
.ConfigureAwait(false);
64+
}
65+
66+
if(changed[1]||!SentVibration)
67+
{
68+
awaitInterface.WriteValueAsync(
69+
newbyte[]{0xF2,(byte)Convert.ToUInt32(_vibratorSpeeds[1]*0x7F)},aToken)
70+
.ConfigureAwait(false);
71+
}
72+
73+
SentVibration=true;
74+
returnnewOk(aMsg.Id);
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)
close