66
77using System ;
88using System . Collections . Generic ;
9+ using System . Linq ;
910using System . Threading ;
1011using System . Threading . Tasks ;
1112using Buttplug . Core . Logging ;
@@ -20,6 +21,7 @@ internal class LiBoType
2021 public string Name ;
2122 public uint VibeCount ;
2223 public uint [ ] VibeOrder = new uint [ ] { 0 , 1 } ;
24+ public bool MultiCharacteristic = true ;
2325 }
2426
2527 internal static readonly Dictionary < string , LiBoType > DevInfos =
@@ -74,6 +76,47 @@ internal class LiBoType
7476 VibeCount = 1 ,
7577 }
7678 } ,
79+ {
80+ "Gugudai" ,
81+ new LiBoType ( )
82+ {
83+ Name = "Carlos" ,
84+ VibeCount = 2 , // Suction as vibe
85+ }
86+ } ,
87+ {
88+ "ShaYu" ,
89+ new LiBoType ( )
90+ {
91+ Name = "Shark" ,
92+ VibeCount = 2 ,
93+ MultiCharacteristic = false ,
94+ }
95+ } ,
96+ {
97+ "Yuyi" ,
98+ new LiBoType ( )
99+ {
100+ Name = "Lina" ,
101+ VibeCount = 1 ,
102+ }
103+ } ,
104+ {
105+ "LuWuShuang" ,
106+ new LiBoType ( )
107+ {
108+ Name = "Adel" ,
109+ VibeCount = 1 ,
110+ }
111+ } ,
112+ {
113+ "LiBo" ,
114+ new LiBoType ( )
115+ {
116+ Name = "Lily" ,
117+ VibeCount = 2 ,
118+ }
119+ } ,
77120 } ;
78121
79122 private readonly LiBoType _devInfo ;
@@ -145,20 +188,43 @@ private async Task<ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg,
145188 _vibratorSpeed [ v . Index ] = v . Speed ;
146189 }
147190
148- if ( changed [ _devInfo . VibeOrder [ 0 ] ] || ! SentVibration )
191+ // Shark specific handling
192+ if ( _devInfo . VibeCount == 2 && ! _devInfo . MultiCharacteristic )
149193 {
150- var ep = Endpoints . Tx ;
151- if ( _devInfo . VibeCount == 1 && ( uint ) Math . Ceiling ( _vibratorSpeed [ _devInfo . VibeOrder [ 0 ] ] * 0x64 ) == 0 )
194+ if ( ! changed . Select ( x => x ) . Any ( ) && SentVibration )
152195 {
153- ep = Endpoints . TxMode ;
196+ return new Ok ( aMsg . Id ) ;
154197 }
155198
199+ SentVibration = true ;
200+ byte data = 0x00 ;
201+ data |= ( byte ) ( ( byte ) Math . Ceiling ( _vibratorSpeed [ _devInfo . VibeOrder [ 0 ] ] * 0x03 ) << 4 ) ;
202+ data |= ( byte ) Math . Ceiling ( _vibratorSpeed [ _devInfo . VibeOrder [ 1 ] ] * 0x03 ) ;
203+ await Interface . WriteValueAsync (
204+ new [ ] { data } ,
205+ new ButtplugDeviceWriteOptions { Endpoint = Endpoints . Tx } ,
206+ aToken ) . ConfigureAwait ( false ) ;
207+
208+ return new Ok ( aMsg . Id ) ;
209+ }
210+
211+ if ( changed [ _devInfo . VibeOrder [ 0 ] ] || ! SentVibration )
212+ {
156213 // Map a 0 - 100% value to a 0 - 0x64 value since 0 * x == 0 this will turn off the vibe if
157214 // speed is 0.00
158215 await Interface . WriteValueAsync (
159216 new [ ] { Convert . ToByte ( ( uint ) Math . Ceiling ( _vibratorSpeed [ _devInfo . VibeOrder [ 0 ] ] * 0x64 ) ) } ,
160- new ButtplugDeviceWriteOptions { Endpoint = ep } ,
217+ new ButtplugDeviceWriteOptions { Endpoint = Endpoints . Tx } ,
161218 aToken ) . ConfigureAwait ( false ) ;
219+
220+ // Some devices don't really stop unless both characteristics are set to 0
221+ if ( _devInfo . VibeCount == 1 && ( uint ) Math . Ceiling ( _vibratorSpeed [ _devInfo . VibeOrder [ 0 ] ] * 0x64 ) == 0 )
222+ {
223+ await Interface . WriteValueAsync (
224+ new [ ] { Convert . ToByte ( ( uint ) Math . Ceiling ( _vibratorSpeed [ _devInfo . VibeOrder [ 0 ] ] * 0x64 ) ) } ,
225+ new ButtplugDeviceWriteOptions { Endpoint = Endpoints . TxMode } ,
226+ aToken ) . ConfigureAwait ( false ) ;
227+ }
162228 }
163229
164230 if ( _devInfo . VibeCount < 2 ||
0 commit comments