private static void Scan()
    {
        if (IsScanning)
        {
            return;
        }
#pragma warning disable CS0162
        if (isLogging)
        {
            Debug.Log(TAG + "Scan");
        }
#pragma warning restore CS0162
        IsIgnoringScanReport = false;
        IsScanning           = true;

        MovesenseDevice.RemoveUnconnected();

        if (Event != null)
        {
            Event(null, new EventArgs(EventType.REMOVE_UNCONNECTED, TAG + "Scan", null));
        }

#if UNITY_ANDROID && !UNITY_EDITOR
        scanPlugin.Call("Scan", uuidString);
#elif UNITY_IOS && !UNITY_EDITOR
        Scan_iOS(uuidString);
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR
#endif

        if (Event != null)
        {
            Event(null, new EventArgs(EventType.SYSTEM_SCANNING, TAG + "Scan", null));
        }
    }
Beispiel #2
0
    public void OnClickButtonSubscriptions()
    {
        if (isButtonSubscriptionsPressed)
        {
            isButtonSubscriptionsPressed = true;
            return;
        }
                #pragma warning disable CS0162
        if (isLogging)
        {
            Debug.Log(TAG + "onClickButtonSubscriptions");
        }
                #pragma warning restore CS0162

        // detach events
        ScanController.Event      -= OnScanControllerCallbackEvent;
        MovesenseController.Event -= OnMovesenseControllerCallbackEvent;

        ScanController.StopScan();

        MovesenseDevice.RemoveUnconnected();

        SceneManager.LoadScene(1);
    }
    private void Update()
    {
        if (Event != null)   // Feature in case you forgot to subscribe to the event, no data will be lost
        {
            connectLock.EnterUpgradeableReadLock();
            try {
                if (connectEventArgs.Count > 0)
                {
#pragma warning disable CS0162
                    if (isLogging)
                    {
                        Debug.Log(TAG + "Update, raising CONNECT-event");
                    }
#pragma warning restore CS0162
                    Event(null, new EventArgs(EventType.CONNECTED, TAG + "OnConnectCallbackEvent", connectEventArgs));
                    MovesenseDevice.RemoveUnconnected();
                    Subscribe(MovesenseDevice.Devices[0].Serial, SubscriptionPath.HeartRate, null);
                    connectLock.EnterWriteLock();
                    try {
                        connectEventArgs.Clear();
                    } finally {
                        connectLock.ExitWriteLock();
                    }
                }
            } finally {
                connectLock.ExitUpgradeableReadLock();
            }

            disConnectLock.EnterUpgradeableReadLock();
            try {
                if (disConnectEventArgs.Count > 0)
                {
#pragma warning disable CS0162
                    if (isLogging)
                    {
                        Debug.Log(TAG + "Update, raising DISCONNECT-event");
                    }
#pragma warning restore CS0162
                    Event(null, new EventArgs(EventType.DISCONNECTED, TAG + "OnConnectCallbackEvent", disConnectEventArgs));
                    disConnectLock.EnterWriteLock();
                    try {
                        disConnectEventArgs.Clear();
                    } finally {
                        disConnectLock.ExitWriteLock();
                    }
                }
            } finally {
                disConnectLock.ExitUpgradeableReadLock();
            }

            notificationLock.EnterUpgradeableReadLock();
            try {
                if (notificationCallbackEventArgs.Count > 0)
                {
#pragma warning disable CS0162
                    if (isLogging)
                    {
                        Debug.Log(TAG + "Update, raising NOTIFICATION-event");
                    }
#pragma warning restore CS0162
                    Event(null, new EventArgs(EventType.NOTIFICATION, TAG + "OnNotificationCallbackEvent", notificationCallbackEventArgs));
                    notificationLock.EnterWriteLock();
                    try {
                        notificationCallbackEventArgs.Clear();
                    } finally {
                        notificationLock.ExitWriteLock();
                    }
                }
            } finally {
                notificationLock.ExitUpgradeableReadLock();
            }

            responseLock.EnterUpgradeableReadLock();
            try {
                if (responseEventArgs.Count > 0)
                {
#pragma warning disable CS0162
                    if (isLogging)
                    {
                        Debug.Log(TAG + "Update, raising RESPONSE-event");
                    }
#pragma warning restore CS0162
                    Event(null, new EventArgs(EventType.RESPONSE, TAG + "OnResponseCallbackEvent", responseEventArgs));
                    responseLock.EnterWriteLock();
                    try {
                        responseEventArgs.Clear();
                    } finally {
                        responseLock.ExitWriteLock();
                    }
                }
            } finally {
                responseLock.ExitUpgradeableReadLock();
            }
        }
    }