Skip to content

Commit ce84064

Browse files
committed
feat: Add base motorbunny protocol with vibration
Add Motorbunny support, with vibration. Still need to add rotation.
1 parent cf964e7 commit ce84064

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

Buttplug/Devices/Configuration/DeviceConfigurationManager.cs

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ protected DeviceConfigurationManager()
6565
AddProtocol("realtouch",typeof(RealTouchProtocol));
6666
AddProtocol("svakom",typeof(SvakomProtocol));
6767
AddProtocol("realov",typeof(RealovProtocol));
68+
AddProtocol("motorbunny",typeof(MotorbunnyProtocol));
6869

6970
// ET312 turned off until deadlocks and caching are fixed. See #593, #594, #595
7071
// AddProtocol("erostek-et312", typeof(ErostekET312Protocol));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
usingSystem;
2+
usingSystem.Linq;
3+
usingSystem.Threading;
4+
usingSystem.Threading.Tasks;
5+
usingButtplug.Core.Logging;
6+
usingButtplug.Core.Messages;
7+
8+
namespaceButtplug.Devices.Protocols
9+
{
10+
internalclassMotorbunnyProtocol:ButtplugDeviceProtocol
11+
{
12+
privatedouble_vibratorSpeed;
13+
14+
publicMotorbunnyProtocol(IButtplugLogManageraLogManager,
15+
IButtplugDeviceImplaInterface)
16+
:base(aLogManager,
17+
"Motorbunny",
18+
aInterface)
19+
{
20+
AddMessageHandler<SingleMotorVibrateCmd>(HandleSingleMotorVibrateCmd);
21+
AddMessageHandler<VibrateCmd>(HandleVibrateCmd,newMessageAttributes(){FeatureCount=1});
22+
AddMessageHandler<StopDeviceCmd>(HandleStopDeviceCmd);
23+
}
24+
25+
privateasyncTask<ButtplugMessage>HandleStopDeviceCmd(ButtplugDeviceMessageaMsg,CancellationTokenaToken)
26+
{
27+
BpLogger.Debug("Stopping Device "+Name);
28+
returnawaitHandleSingleMotorVibrateCmd(newSingleMotorVibrateCmd(aMsg.DeviceIndex,0,aMsg.Id),aToken).ConfigureAwait(false);
29+
}
30+
31+
privateasyncTask<ButtplugMessage>HandleSingleMotorVibrateCmd(ButtplugDeviceMessageaMsg,CancellationTokenaToken)
32+
{
33+
varcmdMsg=CheckMessageHandler<SingleMotorVibrateCmd>(aMsg);
34+
35+
returnawaitHandleVibrateCmd(VibrateCmd.Create(cmdMsg.DeviceIndex,cmdMsg.Id,cmdMsg.Speed,1),aToken).ConfigureAwait(false);
36+
}
37+
38+
privateasyncTask<ButtplugMessage>HandleVibrateCmd(ButtplugDeviceMessageaMsg,CancellationTokenaToken)
39+
{
40+
varcmdMsg=CheckGenericMessageHandler<VibrateCmd>(aMsg,1);
41+
varv=cmdMsg.Speeds[0];
42+
43+
if(Math.Abs(v.Speed-_vibratorSpeed)<0.001&&SentVibration)
44+
{
45+
returnnewOk(cmdMsg.Id);
46+
}
47+
48+
SentVibration=true;
49+
50+
// If speed is zero, send the magic stop packet, otherwise *weird* things happen.
51+
if((cmdMsg.Speeds[0].Speed*255)<5)
52+
{
53+
awaitInterface.WriteValueAsync(newbyte[]{0xf0,0x00,0x00,0x00,0x00,0xec},aToken).ConfigureAwait(false);
54+
returnnewOk(aMsg.Id);
55+
}
56+
57+
58+
varcmdData=newbyte[]{0xff};
59+
60+
for(vari=0;i<7;++i)
61+
{
62+
cmdData=cmdData.Concat(newbyte[]{(byte)(cmdMsg.Speeds[0].Speed*255),0x14}).ToArray();
63+
}
64+
65+
bytecrc=0;
66+
67+
// Skip the first byte for the CRC
68+
for(varj=1;j<cmdData.Length;++j)
69+
{
70+
crc=(byte)(cmdData[j]+crc);
71+
}
72+
73+
cmdData=cmdData.Concat(newbyte[]{crc,0xec}).ToArray();
74+
75+
awaitInterface.WriteValueAsync(cmdData,aToken).ConfigureAwait(false);
76+
returnnewOk(aMsg.Id);
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)
close