|
1 |
| -// <copyright file="KiirooOnyx21Protocol.cs" company="Nonpolynomial Labs LLC"> |
| 1 | +// <copyright file="KiirooGen21Protocol.cs" company="Nonpolynomial Labs LLC"> |
2 | 2 | // Buttplug C# Source Code File - Visit https://buttplug.io for more info about the project.
|
3 | 3 | // Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
4 | 4 | // Licensed under the BSD 3-Clause license. See LICENSE file in the project root for full license information.
|
5 | 5 | // </copyright>
|
6 | 6 |
|
7 | 7 | usingSystem;
|
| 8 | +usingSystem.Collections.Generic; |
8 | 9 | usingSystem.Threading;
|
9 | 10 | usingSystem.Threading.Tasks;
|
10 | 11 | usingButtplug.Core.Logging;
|
|
13 | 14 |
|
14 | 15 | namespaceButtplug.Devices.Protocols
|
15 | 16 | {
|
| 17 | +// ReSharper disable once InconsistentNaming |
16 | 18 | internalclassKiirooGen21Protocol:ButtplugDeviceProtocol
|
17 | 19 | {
|
| 20 | +privatereadonlydouble[]_vibratorSpeeds={0,0,0}; |
18 | 21 | privatedouble_lastPosition;
|
19 | 22 |
|
| 23 | +// ReSharper disable once InconsistentNaming |
| 24 | +internalstructKiirooGen21Type |
| 25 | +{ |
| 26 | +publicstringBrand; |
| 27 | +publicstringName; |
| 28 | +publicboolHasLinear; |
| 29 | +publicuintVibeCount; |
| 30 | +publicuint[]VibeOrder; |
| 31 | +} |
| 32 | + |
| 33 | +internalstaticreadonlyDictionary<string,KiirooGen21Type>DevInfos=newDictionary<string,KiirooGen21Type>() |
| 34 | +{ |
| 35 | +{ |
| 36 | +"Cliona", |
| 37 | +newKiirooGen21Type |
| 38 | +{ |
| 39 | +Brand="Kiiroo", |
| 40 | +Name="Cliona", |
| 41 | +HasLinear=false, |
| 42 | +VibeCount=1, |
| 43 | +VibeOrder=new[]{0u,1u,2u}, |
| 44 | +} |
| 45 | +}, |
| 46 | +{ |
| 47 | +"Pearl2.1", |
| 48 | +newKiirooGen21Type |
| 49 | +{ |
| 50 | +Brand="Kiiroo", |
| 51 | +Name="Pearl 2.1", |
| 52 | +HasLinear=false, |
| 53 | +VibeCount=1, |
| 54 | +VibeOrder=new[]{0u,1u,2u}, |
| 55 | +} |
| 56 | +}, |
| 57 | +{ |
| 58 | +"OhMiBod 4.0", |
| 59 | +newKiirooGen21Type |
| 60 | +{ |
| 61 | +Brand="OhMiBod", |
| 62 | +Name="Esca 2", |
| 63 | +HasLinear=false, |
| 64 | +VibeCount=1, |
| 65 | +VibeOrder=new[]{0u,1u,2u}, |
| 66 | +} |
| 67 | +}, |
| 68 | +{ |
| 69 | +"Onyx2.1", |
| 70 | +newKiirooGen21Type |
| 71 | +{ |
| 72 | +Brand="Kiiroo", |
| 73 | +Name="Onyx 2.1", |
| 74 | +HasLinear=true, |
| 75 | +VibeCount=0, |
| 76 | +VibeOrder=new[]{0u,1u,2u}, |
| 77 | +} |
| 78 | +}, |
| 79 | +{ |
| 80 | +"Titan1.1", |
| 81 | +newKiirooGen21Type |
| 82 | +{ |
| 83 | +Brand="Kiiroo", |
| 84 | +Name="Titan 1.1", |
| 85 | +HasLinear=true, |
| 86 | +VibeCount=1,// actually 3 |
| 87 | +VibeOrder=new[]{0u,1u,2u}, |
| 88 | +} |
| 89 | +}, |
| 90 | +}; |
| 91 | + |
| 92 | +privatereadonlyKiirooGen21Type_devInfo; |
| 93 | + |
20 | 94 | publicKiirooGen21Protocol([NotNull]IButtplugLogManageraLogManager,
|
21 |
| -IButtplugDeviceImplaInterface) |
| 95 | +[NotNull]IButtplugDeviceImplaInterface) |
22 | 96 | :base(aLogManager,
|
23 |
| -"Kiiroo Onyx2.1", |
24 |
| -aInterface) |
| 97 | +"Kiiroo Unknown", |
| 98 | +aInterface) |
25 | 99 | {
|
26 |
| -// Setup message function array |
27 |
| -AddMessageHandler<FleshlightLaunchFW12Cmd>(HandleFleshlightLaunchFW12Cmd); |
28 |
| -AddMessageHandler<LinearCmd>(HandleLinearCmd,newMessageAttributes(){FeatureCount=1}); |
| 100 | +if(DevInfos.ContainsKey(aInterface.Name)) |
| 101 | +{ |
| 102 | +Name=$"{DevInfos[aInterface.Name].Brand}{DevInfos[aInterface.Name].Name}"; |
| 103 | +_devInfo=DevInfos[aInterface.Name]; |
| 104 | +} |
| 105 | +else |
| 106 | +{ |
| 107 | +BpLogger.Warn($"Cannot identify device {Name}, defaulting to Pearl2 settings."); |
| 108 | +_devInfo=DevInfos["Pearl2.1"]; |
| 109 | +} |
| 110 | + |
29 | 111 | AddMessageHandler<StopDeviceCmd>(HandleStopDeviceCmd);
|
| 112 | + |
| 113 | +if(_devInfo.VibeCount>0) |
| 114 | +{ |
| 115 | +AddMessageHandler<VibrateCmd>(HandleVibrateCmd, |
| 116 | +newMessageAttributes{FeatureCount=_devInfo.VibeCount}); |
| 117 | +AddMessageHandler<SingleMotorVibrateCmd>(HandleSingleMotorVibrateCmd); |
| 118 | +} |
| 119 | + |
| 120 | +if(_devInfo.HasLinear) |
| 121 | +{ |
| 122 | +AddMessageHandler<LinearCmd>(HandleLinearCmd, |
| 123 | +newMessageAttributes{FeatureCount=1}); |
| 124 | +AddMessageHandler<FleshlightLaunchFW12Cmd>(HandleFleshlightLaunchFW12Cmd); |
| 125 | +} |
30 | 126 | }
|
31 | 127 |
|
32 |
| -privateTask<ButtplugMessage>HandleStopDeviceCmd(ButtplugDeviceMessageaMsg,CancellationTokenaToken) |
| 128 | +privateasyncTask<ButtplugMessage>HandleStopDeviceCmd([NotNull]ButtplugDeviceMessageaMsg,CancellationTokenaToken) |
33 | 129 | {
|
34 |
| -BpLogger.Debug("Stopping Device "+Name); |
35 |
| -returnTask.FromResult<ButtplugMessage>(newOk(aMsg.Id)); |
| 130 | +BpLogger.Debug($"Stopping Device {Name}"); |
| 131 | + |
| 132 | +if(_devInfo.VibeCount==0) |
| 133 | +{ |
| 134 | +returnnewOk(aMsg.Id); |
| 135 | +} |
| 136 | + |
| 137 | +returnawaitHandleVibrateCmd(VibrateCmd.Create(aMsg.DeviceIndex,aMsg.Id,0,_devInfo.VibeCount),aToken).ConfigureAwait(false); |
| 138 | +} |
| 139 | + |
| 140 | +privateasyncTask<ButtplugMessage>HandleSingleMotorVibrateCmd([NotNull]ButtplugDeviceMessageaMsg,CancellationTokenaToken) |
| 141 | +{ |
| 142 | +varcmdMsg=CheckMessageHandler<SingleMotorVibrateCmd>(aMsg); |
| 143 | + |
| 144 | +returnawaitHandleVibrateCmd(VibrateCmd.Create(aMsg.DeviceIndex,aMsg.Id,cmdMsg.Speed,_devInfo.VibeCount),aToken).ConfigureAwait(false); |
| 145 | +} |
| 146 | + |
| 147 | +privateasyncTask<ButtplugMessage>HandleVibrateCmd([NotNull]ButtplugDeviceMessageaMsg,CancellationTokenaToken) |
| 148 | +{ |
| 149 | +varcmdMsg=CheckGenericMessageHandler<VibrateCmd>(aMsg,_devInfo.VibeCount); |
| 150 | + |
| 151 | +varchanged=false; |
| 152 | +foreach(varviincmdMsg.Speeds) |
| 153 | +{ |
| 154 | +if(Math.Abs(_vibratorSpeeds[vi.Index]-vi.Speed)<0.0001) |
| 155 | +{ |
| 156 | +continue; |
| 157 | +} |
| 158 | + |
| 159 | +_vibratorSpeeds[vi.Index]=vi.Speed; |
| 160 | +changed=true; |
| 161 | +} |
| 162 | + |
| 163 | +if(!changed&&SentVibration) |
| 164 | +{ |
| 165 | +returnnewOk(cmdMsg.Id); |
| 166 | +} |
| 167 | + |
| 168 | +SentVibration=true; |
| 169 | + |
| 170 | +vardata=new[] |
| 171 | +{ |
| 172 | +(byte)0x01, |
| 173 | +(byte)Convert.ToUInt16(_vibratorSpeeds[_devInfo.VibeOrder[0]]*100), |
| 174 | +}; |
| 175 | + |
| 176 | +awaitInterface.WriteValueAsync(data,aToken).ConfigureAwait(false); |
| 177 | +returnnewOk(aMsg.Id); |
36 | 178 | }
|
37 | 179 |
|
38 | 180 | privateasyncTask<ButtplugMessage>HandleLinearCmd(ButtplugDeviceMessageaMsg,CancellationTokenaToken)
|
|
0 commit comments