Ejemplo n.º 1
0
 public void OnClickButtonConnect(string macID, string serial, bool isConnecting, bool isConnected)
 {
     // attached method for ScanElementClone
             #pragma warning disable CS0162
     if (isLogging)
     {
         Debug.Log(TAG + "OnClickButtonConnect, " + ((isConnecting || isConnected) ? "disconnecting: " : "connecting: ") + macID + " (" + serial + ")");
     }
             #pragma warning restore CS0162
     if (MovesenseController.isInitialized)
     {
         if (isConnecting || isConnected)
         {
             MovesenseController.Disconnect(macID);
         }
         else
         {
             MovesenseController.Connect(macID);
         }
     }
     else
     {
         Debug.LogError(TAG + "OnClickButtonConnect, MovesenseController is NOT initialized. Did you forget to add MovesenseController object in the scene?");
     }
 }
Ejemplo n.º 2
0
    void OnMovesenseControllerCallbackEvent(object sender, MovesenseController.EventArgs e)
    {
        //Debug.Log("OnMovesenseControllerCallbackEvent, Type: " + e.Type + ", invoked by: " + e.InvokeMethod);
        switch (e.Type)
        {
        case MovesenseController.EventType.CONNECTING:
            for (int i = 0; i < e.OriginalEventArgs.Count; i++)
            {
                var ce = (ConnectCallback.EventArgs)e.OriginalEventArgs[i];

                Debug.Log("OnMovesenseControllerCallbackEvent, CONNECTING " + ce.MacID);
            }
            break;

        case MovesenseController.EventType.CONNECTED:
            for (int i = 0; i < e.OriginalEventArgs.Count; i++)
            {
                var ce = (ConnectCallback.EventArgs)e.OriginalEventArgs[i];

                Debug.Log("OnMovesenseControllerCallbackEvent, CONNECTED " + ce.MacID + ", subscribing linearAcceleration");

                MovesenseController.Subscribe(ce.Serial, SubscriptionPath.LinearAcceleration, SampleRate.slowest);
            }
            break;

        case MovesenseController.EventType.NOTIFICATION:
            for (int i = 0; i < e.OriginalEventArgs.Count; i++)
            {
                var ne = (NotificationCallback.EventArgs)e.OriginalEventArgs[i];

                Debug.Log("OnMovesenseControllerCallbackEvent, NOTIFICATION for " + ne.Serial + ", SubscriptionPath: " + ne.Subscriptionpath + ", Data: " + ne.Data);
            }
            break;
        }
    }
Ejemplo n.º 3
0
    void Start()
    {
        // attach event
        MovesenseController.Event += OnMovesenseControllerCallbackEvent;

        // Let's just subscribe all devices if we had more than one
        foreach (var device in MovesenseDevice.Devices)
        {
            MovesenseController.Subscribe(device.Serial, SubscriptionPath.AngularVelocity, SampleRate.medium);
            MovesenseController.Subscribe(device.Serial, SubscriptionPath.LinearAcceleration, SampleRate.medium);
        }
    }
Ejemplo n.º 4
0
    IEnumerator Connect(string macID)
    {
        if (MovesenseController.isInitialized)
        {
            yield return(0);

            MovesenseController.Connect(macID);
        }
        else
        {
            yield return(new WaitForSeconds(0.1F));            // wait for MovesenseController to be initialized

            MovesenseController.Connect(macID);
        }
    }
Ejemplo n.º 5
0
    public void OnClickButtonSubscribe(int index)
    {
                #pragma warning disable CS0162
        if (isLogging)
        {
            Debug.Log(TAG + "OnClickButtonSubscribe, Button: " + buttonsSubscription[index].name);
        }
                #pragma warning restore CS0162

        // Toggle state
        bool isOn = (buttonsSubscription[index].image.sprite.name.Split('_')[1] == "On") ? true : false;
        buttonsSubscription[index].image.sprite = isOn?buttonOff:buttonOn;
        isOn = !isOn;

        string serial = MovesenseDevice.Devices[connectedElementHighlitedIndex].Serial;

        string subscriptionPath = null;
        int?   sampleRate       = null;
        string subscriptionChar = null;         // only for logging

        switch (index)
        {
        case 0:
            subscriptionPath = SubscriptionPath.LinearAcceleration;
            sampleRate       = SampleRate.slowest;
            subscriptionChar = "LinearAcceleration";
            break;

        case 1:
            subscriptionPath = SubscriptionPath.AngularVelocity;
            sampleRate       = SampleRate.slowest;
            subscriptionChar = "AngularVelocity";
            break;

        case 2:
            subscriptionPath = SubscriptionPath.MagneticField;
            sampleRate       = SampleRate.slowest;
            subscriptionChar = "MagneticField";
            break;

        case 3:
            subscriptionPath = SubscriptionPath.HeartRate;
            subscriptionChar = "HeartRate";
            break;

        case 4:
            subscriptionPath = SubscriptionPath.Temperature;
            subscriptionChar = "Temperature";
            break;
        }

                #pragma warning disable CS0162
        if (isLogging)
        {
            Debug.Log(TAG + "onClickButtonSubscribe, " + (isOn ? "" : "un") + "subscribe " + subscriptionChar + " for " + serial);
        }
                #pragma warning restore CS0162

        if (isOn)
        {
            MovesenseController.Subscribe(serial, subscriptionPath, sampleRate);
        }
        else
        {
            MovesenseController.UnSubscribe(serial, subscriptionPath);
            // clear values
            Invoke("RefreshPanelSubscriptionDelayed", 0.2F);
        }

        // ButtonVisualize gets active, if any Subscription is active
        if (MovesenseDevice.isAnySubscribed(SubscriptionPath.AngularVelocity, SubscriptionPath.LinearAcceleration))
        {
            buttonVisualize.gameObject.SetActive(true);
        }
        else
        {
            buttonVisualize.gameObject.SetActive(false);
        }
    }