예제 #1
0
        private static void OnStateChanged(IntPtr gem, NativeWrapper.GemState state)
        {
            AppleGem _gem = FindGemByPointer(gem);

            Debug.LogFormat("{0}, {1}", _gem.Address, state);

            if (_gem == null)
            {
                throw new Exception("OnStateChanged called on non-existing/disconnected gem");
            }

            switch (state)
            {
            case NativeWrapper.GemState.Connected:
                _gem.State = GemState.Connected;
                break;

            case NativeWrapper.GemState.Connecting:
                _gem.State = GemState.Connecting;
                break;

            case NativeWrapper.GemState.Disconnected:
                _gem.State = GemState.Disconnected;
                break;

            case NativeWrapper.GemState.Disconnecting:
                _gem.State = GemState.Disconnecting;
                break;
            }
        }
예제 #2
0
        static void OnDeviceDiscovered(IntPtr gem, int rssi)
        {
            string address = NativeWrapper.getGemAddress(gem);

            Debug.Log("OnDeviceDiscovered: " + address + ", rssi: " + rssi);
            AppleGem _gem = AppleGem.FindGemByAddress(address);

            if (_gem != null)
            {
                if (_gem.GemPointer == IntPtr.Zero)
                {
                    _gem.GemPointer = gem;
                    _gem.Connect();
                }
                else if (_gem.GemPointer != gem)
                {
                    Debug.LogWarningFormat("Two pointers ({0},{1}) for the same Gem address {2}", _gem.GemPointer, gem, address);
                }

                // check if other gems are pending, if found then don't stop the scan
                foreach (AppleGem iosGem in AppleGem.Gems)
                {
                    if (iosGem.GemPointer == IntPtr.Zero)
                    {
                        return;
                    }
                }

                instance.StopScan();
            }
        }
예제 #3
0
        private static void OnTapData(IntPtr gem, uint direction)
        {
            AppleGem _gem = FindGemByPointer(gem);

            if (_gem == null)
            {
                throw new Exception("OnTapData called on non-existing/disconnected gem");
            }

            _gem.tapOccured = true;
        }
예제 #4
0
        public IGem GetGem(String address)
        {
            AppleGem gem = AppleGem.FindGemByAddress(address);

            if (gem == null)
            {
                gem = new AppleGem(address);

                if (ready)
                {
                    StartScan();
                }
            }

            return(gem);
        }
예제 #5
0
        private static void OnErrorOccured(IntPtr gem, int error)
        {
            AppleGem _gem = FindGemByPointer(gem);

            if (_gem == null)
            {
                throw new Exception("OnErrorOccured called on non-existing/disconnected gem");
            }

            if (error == 6)
            {
                Debug.LogErrorFormat("{0}: timed out, trying to reconnect...", _gem.Address);
                _gem.Connect();
            }
            else
            {
                Debug.LogErrorFormat("{0}: error: {1}", _gem.Address, error);
            }
        }
예제 #6
0
        private static void OnCombinedData(IntPtr gem, IntPtr quaternion, IntPtr acceleration)
        {
            float[] q = new float[4];
            Marshal.Copy(quaternion, q, 0, 4);

            float[] acc = new float[3];
            Marshal.Copy(acceleration, acc, 0, 3);

            AppleGem _gem = FindGemByPointer(gem);

            if (_gem == null)
            {
                throw new Exception("OnCombinedData called on non-existing/disconnected gem");
            }

            _gem.LastQuaternion   = new Quaternion(q[1], q[2], q[3], q[0]);
            _gem.LastAcceleration = new Vector3(acc[0], acc[1], acc[2]);

            //LastAcceleration = new Vector3(acc[0], acc[1], acc[2]);
        }