Esempio n. 1
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;
        }
    }
Esempio n. 2
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);
        }
    }
Esempio n. 3
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);
        }
    }