Adjuvo / SenseGlove-Unity

The latest stable Unity SDK for the SenseGlove.
MIT License
35 stars 10 forks source link

Detecting glove state. #15

Closed Ketoma closed 5 years ago

Ketoma commented 5 years ago

Hello SenseGlove Team, We are developing an application where we want to be able to monitor the state of both gloves (connected/detected, and when connection is lost). The goal is to be able to take certain action when connection to the glove is lost - for what ever reason. I have looked into the exposed/public variables and events in DeviceScanner class and SenseGlove_Object class. However, I only found events which are fired when the glove is detected. These events are fired ounce during the application lifetime, when the glove is first detected and added to the list, thus it is not also possible to listen when the glove is re-connected.

Is there a way to listen to glove disconnection and re-connection? Thanks for the support you can provide.

MaxLammers commented 5 years ago

Dear Ketoma,

Monitoring the connection state is currently done internally in the SenseGloveCs.dll library. You can request a the current Connection status using SenseGlove_Object's IsConnected accessor, which returns true is the hardware connection is active, and false if it has disconnected.

I can add this feature to a future release of the Sense Glove Unity SDK. But for now, you can add this snippet of Code to the SenseGlove_Object's Update() function, or in a separate script that you're using.

SenseGlove_Object senseGlove;
bool wasConnected = false;

public void CheckConnection()
{
    bool isConnected = senseGlove.IsConnected; //when adding this function inside SenseGlove_Object, change this line to this.IsConnected.
    if (isConnected && !wasConnected)
    {
        // Connection has been established - Do something!
    }
    else if (!isConnected && wasConnected)
    {
        // Connection has been lost- Do something!
    }
    wasConnected = isConnected;
}
Ketoma commented 5 years ago

Hey Max, Many thanks for your feedback and the snippet. That works :)