Unity Plugin - Dongle
Introduction
This Unity plugin allows Windows devices to connect Lovense toys and send control commands.
Note: A Lovense USB Bluetooth adapter is required to use this plugin.
Compatibility
Unity version: >= 2019.4.0
Api Compatibility Level:
- For
.Net 4.x
, the import package name isdonglePlugin_.Net4.x.unitypackage
. - For
.Net Framework
, the import package name isdonglePlugin_.NetFramework.unitypackage
. - For
.Net Standard 2.0
, the import package name isdonglePlugin_.NetStandard2.0.unitypackage
. - For
.Net Standard 2.1
, the import package name isdonglePlugin_.NetStandard2.1.unitypackage
.
Import the plugin
Download the plugin package from here. The latest version of the current plugin is V1.4 click to view version records
donglePlugin_.Net4.x.unitypackage
donglePlugin_.NetFramework.unitypackage
Import the appropriate package based on your project's Api Compatibility Level.
Select all options and click import.
4.The file Assets/StreamingAssets/LovenseToySupportConfig.json is the configuration file for the toy support directive, and the version field represents the version of the information. The current latest version is 1.4
. If it is older than this version, it is recommended to download and replace the file.
Dowload: LovenseToySupportConfig.json
The LovenseDemo folder is an example that you can refer to. Removing it won't affect the functionality.
Guide
1. Search for attached toys.
public class YourLovenseToyUI: MonoBehaviour {
// do search
private void DoSearch() {
LovenseDongleTools.GetInstance().GetConnectedToys();
LovenseDongleTools.GetInstance().SearchToys()
}
//
private void onGetToy(LovenseDongleToy data) {
// Show the search result in the UI
}
void Awake() {
// Add listener
LovenseDongleTools.onGetToyEvent.AddListener(onGetToy);
}
void OnDestory() {
// Remove listener
LovenseDongleTools.onGetToyEvent.RemoveListener(onGetToy);
}
}
2. Connect or disConnect toys
public class YourLovenseToyUI: MonoBehaviour {
//do connect toys
private void DoConnect(List<string> ids) {
LovenseDongleTools.GetInstance().ConnectToys(ids);
}
//do disconnect toys
private void DoDisConnect(List<string> ids) {
LovenseDongleTools.GetInstance().DisConnectToys(ids)
}
private void OnConnectedChange(string toyId, bool connected) {
//Code executes when the connection state of the toy changes
}
void Awake() {
// Add listener
LovenseDongleTools.onConnectChangeEvent.AddListener(OnConnectedChange);
}
void OnDestroy() {
// Remove listener
LovenseDongleTools.onConnectChangeEvent.RemoveListener(OnConnectedChange);
}
}
3. Send commands
3.1 Get device type
public class YourLovenseToyUI : MonoBehaviour {
private void DoGetDeviceType(string id) {
LovenseDongleTools.GetInstance().GetDeviceType(id);
}
private void OnGetType(string id,string type) {
}
void Awake() {
// Add listener
LovenseDongleTools.onGetTypeEvent.AddListener(OnGetType);
}
void OnDestroy() {
// Remove listener:
LovenseDongleTools.onGetTypeEvent.RemoveListener(OnGetType);
}
}
3.2 Get battery
public class YourLovenseToyUI : MonoBehaviour {
private void DoGetBattery(string id) {
LovenseDongleTools.GetInstance().GetBattery(id);
}
private void OnGetBattery(string id, string battery){
}
void Awake() {
// Add listener
LovenseDongleTools.onGetBatteryEvent.AddListener(OnGetBattery);
}
void OnDestroy() {
// Remove listener:
LovenseDongleTools.onGetBatteryEvent.RemoveListener(OnGetBattery);
}
}
3.3 Send function commands
public class YourLovenseToyUI : MonoBehaviour {
private void DoSendCommands(List<string> ids, List<LovenseCommand> commands, float timeSec, float loopRunningSec , float loopPauseSec ) {
LovenseDongleTools.GetInstance().SendFunctions(ids, commands, timeSec, loopRunningSec, loopPauseSec);
}
private void OnErrorCodeResult(int code){
//...
}
void Awake() {
// Add listener
LovenseDongleTools.onResultCodeEvent.AddListener(OnErrorCodeResult);
}
void OnDestroy() {
// Remove listener:
LovenseDongleTools.onResultCodeEvent.RemoveListener(OnErrorCodeResult);
}
}
3.4 Send pattern commands
public class YourLovenseToyUI : MonoBehaviour {
private void DoSendPattern(List<string> ids, List<LovenseCommandType> types, List<int> strengthValues,float timeSec,int intervalsMs ) {
LovenseDongleTools.GetInstance().SendPattern(ids, types, strengthValues, timeSec,oneTime,intervalsMs);
}
private void OnErrorCodeResult(int code){
//action failed
}
void Awake() {
// Add listener
LovenseDongleTools.onResultCodeEvent.AddListener(OnErrorCodeResult);
}
void OnDestroy() {
// Remove listener:
LovenseDongleTools.onResultCodeEvent.RemoveListener(OnErrorCodeResult);
}
}
strengthValues: Changes in intensity
intervalsMs: Time interval for intensity switching in milliseconds
timeSec: Total running time in seconds
3.5 Send preset commands
public class YourLovenseToyUI : MonoBehaviour {
private void DoSendPreset(List<string> ids, int mode, float timeSec) {
LovenseDongleTools.GetInstance().SendPreset(new List<string>() { thisToy.id }, mode, timeSec);
}
private void OnErrorCodeResult(int code){
//action failed
}
void Awake() {
// Add listener
LovenseDongleTools.onResultCodeEvent.AddListener(OnErrorCodeResult);
}
void OnDestroy() {
// Remove listener:
LovenseDongleTools.onResultCodeEvent.RemoveListener(OnErrorCodeResult);
}
}
mode:we provide four preset patterns:0 is earthquake
,1 is fireworks
,2 is pulse
,3 is wave
3.6 Send stop command
public class YourLovenseToyUI : MonoBehaviour {
private void DoSendStop(List<string> ids) {
LovenseDongleTools.GetInstance().StopAll(ids);
}
private void OnErrorCodeResult(int code){
//action failed
}
void Awake() {
// Add listener
LovenseDongleTools.onResultCodeEvent.AddListener(OnErrorCodeResult);
}
void OnDestroy() {
// Remove listener:
LovenseDongleTools.onResultCodeEvent.RemoveListener(OnErrorCodeResult);
}
}
3.7 Add interface for Data Reporting
public class YourLovenseToyUI : MonoBehaviour {
private void DoAddDataReporting(string toyId,bool open) {
LovenseDongleTools.GetInstance().SetDataReportingMode(toyId,true); //Only by using this function and setting it to true will the toy data be reported
}
//callback function.
private void OnGetReportingData(LovenseDataReportingEventType type,int target,int value){
//code
}
void Awake() {
LovenseDongleTools.GetInstance().AddDataReportingListener(toyId,OnGetReportingData);
}
void OnDestroy() {
// Remove listener:
LovenseDongleTools.GetInstance().RemoveDataReportingListener(toyId,OnGetReportingData);
}
}
Interface
LovenseDongleTools
Method
GetInstance
Description:
Get the singleton instance of LovenseDongleTools
Parameters: None
Return: LovenseDongleTools instance
GetBattery
Description:
Obtain the power of the toy,when completed, the onGetBatteryEvent event will be triggered.
Parameters:
Name Type Default Required Description toyId string yes The toy ID you want to obtain battery power Return: None
GetDeviceType
Description:
Obtain the power of the toy,when completed, the onGetTypeEvent event will be triggered.
Parameters:
Name Type Default Required Description toyId string yes The toy ID you want to obtain toy type Return: None
GetConnectedToys
Description:
Obtain toys in a connected state, when completed, the onGetToyEvent event will be triggered.
Parameters:None
Return: None
SearchToys
Description:
Search for nearby toys, when the search is completed, the onGetToyEvent event will be triggered.
Parameters: None
Return: None
SendFunctions
Description:
Send function commands to the toys.
Parameters:
Name Type Default Required Description toyIds List<string> yes The toys ID you want to obtain power from commands List<LovenseCommand> yes See LovenseCommand timeSec float yes Total running time in second, 0
represents no limitloopRunningSec float 0
no time running for each command loop in second loopPauseSec float 0
no time gap for each command loop in second Return: None
SendPattern
Description:
Send a series of functions to the toys, they will execute all the functions in
types
according to the order of the level invalues
with the interval ofintervalsMs
.Parameters:
Name Type Default Required Description toyIds List<string> yes The toys you want to control types List<LovenseCommandType> yes See LovenseCommandType strengthValues List<int> yes The order of the levels timeSec float yes The total runtime in second, "0" = indefinite time length. intervalsMs int 150 no The level interval in milliseconds, should be greater than 100, default 150 Return: None
SendPreset
Description:
Send a preset command to the toys.
Parameters:
Name Type Default Required Description toys List<string> yes The toys you want to control mode int yes The preset name to send, we provide four preset patterns: 0: earthquake
,1:fireworks
,2:pulse
,3:wave
timeSec float yes The total runtime in second, "0" = indefinite time length. Return: None
StopAll
Description:
Send a stop command to the toys.
Parameters:
Name Type Description toyIds List<string> The toys you want to stop Return: None
SetDataReportingMode
Description:
Set the switch for toy data reporting function.
Parameters:
Name Type Default Required Description toyId string yes The toys you want to set open bool yes Whether the data reporting function is enabled or not Return: None
CheckDataReportingEnable
Description:
Check if the toy supports data reporting function. If so, onGetToyDataReportingEnabled will be triggered.
Parameters:
Name Type Default Required Description toyId string yes The toys you want to check Return: None
AddDataReportingListener
Description:
Add a data reporting listener.
Parameters:
Name Type Description toyIds string The toys you want to add data reporting listener event UnityAction(string toyId,LovenseDataReportingEventType type,int targer, int value) callback function Return: None
RemoveDataReportingListener
Description:
Remove a data reporting listener.
Parameters:
Name Type Description toyIds string The toys you want to add data reporting listener event UnityAction(string toyId,LovenseDataReportingEventType type,int targer,int value) callback function Return: None
GetSupportCommandsByType(string type)
Description:
Obtain Command types supported by toys through their types
Parameters:
Name Type Description type string the type of toy Return: List<LovenseCommandType>
PatternV2SetUp(string toyId, List<PositionPatternValue> addPatternList)
Description:
Send a series of positions to Solace Pro. The onPatternV2Event event will be triggered.
Parameters:
Name Type Description toyId string The toy you want to set up addPatternList List<PositionPatternValue> the series value of PatternV2 Return: None
PlayPatternV2(string toyId)
Description:
Play the predefined pattern. The onPatternV2Event event will be triggered.
Parameters:
Name Type Description toyId string The toy you want to play. Return: None
StopPatternV2(string toyId)
Description:
Stop playing the predefined pattern. The onPatternV2Event event will be triggered.
Parameters:
Name Type Description toyId string The toy you want to stop. Return: None
SetPosition(string toyId,int position)
Description:
Controls the stroker to move to a specified position(0~100).
Parameters:
Name Type Description toyId string The toy you want to control. position int The position of the strokerr Return: None
Event
onGetToyEvent
Description:
Triggered when a new toy is discovered
Callback Parameters:
Name Type Description toy LovenseDongleToy the new toy which recently been discovered
onGetTypeEvent
Description:
Triggered when getting toy's type is complete.
Callback Parameters:
Name Type Description toyId string The toy's ID type string The toy's type
onGetBatteryEvent
Description:
Triggered when getting toy's battery is complete.
Callback Parameters:
Name Type Description toyId string The toy's ID battery string The toy's battery life. Will have a s
prefix when the toy is in a status that the return value is not reliable. e.g. When the toy is viberating and toy's battery life is 90, the return value will bes90
onConnectChangeEvent
Description:
Triggered when connected toy's connection status is changed.
Callback Parameters:
Name Type Description toyId string The toy's ID connected bool Connection status
onResultCodeEvent
Description:
Triggered when an error occurs during connection or control
Callback Parameters:
Name Type Description code int ID where the error occurred code:
Value Description 99 No Lovense USB Bluetooth adapter 100 Lovense USB Bluetooth adapter initialization completed 101 Lovense USB Bluetooth adapter is inserted 102 Lovense USB Bluetooth adapter is Removed 400 Command does not exist or command is not supported 401 parameter error 402 JSON format error 403 Toy not connected 404 This toy does not exist 406 Toy connection is full 501 Scanning toys, some commands are not supported 505 Other errors
onGetToyDataReportingEnabled
Description:
Triggered when a toy is found to have a data reporting function
Callback Parameters:
Name Type Description code int Toy ID
onPatternV2Event
Description:
Triggered when executing PatternV2.
Callback Parameters:
Name Type Description type PatternV2ActionType What kind of PatternV2 Action id string The toy's ID code int The response code of this action code(if type is PatternV2ActionType.SETUP):
Value Description 0 The PatternV2 status is stoped 1 The PatternV2 status is paused 2 The PatternV2 status is stoped 3 The PatternV2 status is playing, but the series value of PatternV2 is empty
LovenseDongleToy
Description:
The information of the Lovense toy
Properties:
Name Type Description id string The toy's id name string The toy's name, such as "nora" uuid string The toy's uuid isConnected int The toy's connection status type string The toy's type battery int The toy's battery level, from 0
to100
,[GetBattery] needs to be called to updateisSupportDataReporting bool Determine if the toy currently support data reporting. Need the toy to be connected in order to synchronize.
LovenseCommand
Description:
The toy control command
Properties:
Name Type Description type LovenseCommandType See below value int Function level
Function Level:
Type | Range |
---|---|
VIBRATE | 0 - 20 |
VIBRATE1 | 0 - 20 |
VIBRATE2 | 0 - 20 |
VIBRATE3 | 0 - 20 |
ROTATE | 0 - 20 |
PUMP | 0 - 3 |
THRUSTING | 0 - 20 |
FINGERING | 0 - 20 |
SUCTION | 0 - 20 |
DEPTH | 0-3 |
GETBATTERY | |
GETTYPE |
LovenseCommandType
Description:
The enum of the toy function type.
Enum:
Value VIBRATE VIBRATE1 VIBRATE2 VIBRATE3 ROTATE PUMP THRUSTING FINGERING SUCTION DEPTH GETBATTERY GETTYPE POSITION
The DEPTH command is a setting command that requires the THRUSTRING command to take effect.
LovenseDataReportingEventType
Description:
The enum of the toy data reporting event type.
Enum:
Value Description KEY_DOWN Trigger when a key is pressed KEY_UP Trigger when a key is up VIBTATE Trigger when the toy vibrates ROTATE Trigger when the toy rotate SHAKE Trigger when the toy shake MOVEMENT Trigger when the toy movement DEEP Trigger when the toy vibrates AIR_IN Trigger when the toy is inflated AIR_OUT Trigger when the toy deflates AIR_CLOSE Trigger when inflating or deflating is turned off AIR_OPEN Trigger when inflating or deflating is turned on BATTERY Trigger when the battery level changes SHAKE_TIMES Trigger when user shakes the toy every time
LovenseSolaceProCommand
Description:
Extends from LovenseCommand,specially designed for use with SolacePro.
Properties:
Name Type Description strokeLow int The stroke Value at the low end strokeHigh int The stroke Value at the high end, strokeHigh - strokeLow must be greater than 20
PositionPatternValue
Description:
The position command.
Properties:
Name Type Description time int the time in milliseconds position int The position of the stroker(0-100)
PatternV2ActionType
Description:
The enum of the PatternV2 action type.
Enum:
Value SETUP PLAY_OR_STOP
Version Records
[Version1.4] - 2024-08-23
1.Support SolacePro,Update
2.Update the configuration file to version1.4.
3.Modify UI structure.
[Version1.3] - 2023-11-15
1.Command sending optimization.
2.Add Depth command.
3.Update the configuration file to version1.3.
[Version1.2] - 2023-10-20
- 1.Add Vibrate3 command.
[Version1.1] - 2023-09-28
- 1.Add shake event.
[Version1.0] - 2023-09-12
1.Functions
2.Pattern
3.Preset
4.Connect/DisConnect
5.Type/Battery
6.Data Reporting Interface