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; } }
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(); } }
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; }
public IGem GetGem(String address) { AppleGem gem = AppleGem.FindGemByAddress(address); if (gem == null) { gem = new AppleGem(address); if (ready) { StartScan(); } } return(gem); }
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); } }
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]); }