private void OnDeviceDisconnected(int reason, BleDevice d) { BluetoothLEPlugin.BleReadyForSyncEvent -= OnReadyForSync; //s_LabelText = ""; m_currentDevice = null; if (b_Loggin) { Debug.Log(TAG + "got OnDeviceDisconnected with reason: " + (disconnectReason)reason + "(" + reason + ")\nBleReadyForSyncEvent unsubscribed"); } if (reason == 8) //manual Disconnect { m_status = "Disconnected\nFor new Measurement\npress Update"; BluetoothLEPlugin.BleDeviceFoundEvent -= OnDeviceFound; BluetoothLEPlugin.BleDeviceFoundEvent += OnDeviceFound; if (b_Loggin) { Debug.Log(TAG + "BleDeviceFoundEvent un-/resubscribed"); } //m_state = MenuState.START; m_state = MenuState.SCANNING; BluetoothLEPlugin.Scan(90); } else { m_status = "Got Disconnected-Event for:\n" + d.Adress + "\nreason: " + (disconnectReason)reason + "\nplease check and hit update"; clearMAC(); m_state = MenuState.START; } }
private IEnumerator StartDelayedScan(float seconds) { yield return(new WaitForSeconds(seconds)); try { m_status = "searching for Devices..."; if (b_Loggin) { Debug.Log("HeartRateScene: calling ScanForDevices"); } BluetoothLEPlugin.BleDeviceFoundEvent -= OnDeviceFound; BluetoothLEPlugin.BleDeviceFoundEvent += OnDeviceFound; if (b_Loggin) { Debug.Log("HeartRateScene: BleDeviceFoundEvent un-/resubscribed"); } BluetoothLEPlugin.Scan(90); } catch (BluetoothLEPluginException p) { Debug.Log(p.Message); if (b_Loggin) { Debug.Log("HeartRateScene: got Exception, checking Ble status"); } m_status = "Bluetooth low energy error checking status..."; BluetoothLEPlugin.CheckBLEStatus(); } }
public void UpdateButtonAction() { if (b_Loggin) { Debug.Log(TAG + "Update-Button hit"); } if (!b_initialized) { b_initialized = true; m_status = "Initializing native plugin"; BluetoothLEPlugin.Initialize(b_Loggin); #if UNITY_ANDROID StartCoroutine(StartDelayedScan(0)); #elif UNITY_IPHONE && !UNITY_EDITOR StartCoroutine(StartDelayedScan(0.2f)); #elif UNITY_STANDALONE_OSX || UNITY_EDITOR StartCoroutine(StartDelayedScan(0.2f)); #endif } else { clearMAC(); if (m_heartrate != null) { m_heartrate.Reset(); m_status = "disconnecting HeartRate"; m_heartrate.Disconnect(); } else { OnDeviceDisconnected(8, null); } } }
public void Sync(bool Log) { b_Loggin = Log; if (b_Loggin) { Debug.Log("HeartRate.cs: got Sync-Command from Scene"); } BluetoothLEPlugin.gotFeatures("heartrate"); }
public void writeControlPoint() { if (b_Loggin) { Debug.Log("HeartRate.cs: got ControlPoint-Command from Scene, sending to Device"); } byte[] ControlPoint_Cmd = { (byte)0x01 }; BluetoothLEPlugin.sendHR_ControlPoint(ControlPoint_Cmd); }
public virtual void Disconnect() { if (IsDebug) { Debug.Log("BleDevice: Disconnecting " + GetType().ToString() + " " + Name + ", Adress: " + Adress); } BluetoothLEPlugin.Disconnect(); BluetoothLEPlugin.BleDeviceConnectEvent -= OnDeviceConnected; BluetoothLEPlugin.BleValueChangeEvent -= OnDataReceived; if (IsDebug) { Debug.Log("BleDevice: BleDeviceConnectEvent and BleValueChangeEvent unsubscribed"); } }
public void UpdateButtonAction() { if (b_Loggin) { Debug.Log("HeartRateScene: Update-Button hit"); } BluetoothLEPlugin.Initialize(b_Loggin); m_status = "checking Bluetooth low energy"; #if UNITY_ANDROID StartCoroutine(StartDelayedScan(0)); #elif UNITY_IPHONE && !UNITY_EDITOR StartCoroutine(StartDelayedScan(0.2f)); #elif UNITY_STANDALONE_OSX || UNITY_EDITOR StartCoroutine(StartDelayedScan(0.2f)); #endif }
private void OnDeviceScan(int reason, bool StartScanAgain) { if (b_Loggin) { Debug.Log("HeartRateScene: got OnDeviceScan-Event with reason: " + (scanReason)reason); } if (reason == 4) //Timeout { m_status = "Scan aborted, reason: " + (scanReason)reason + "\nplease check and hit update"; if (m_adresses != null) { m_adresses.Clear(); } } else if (reason == 0) //Ble OK { m_status = "Scan possible, scanning..."; if (StartScanAgain) { #if UNITY_ANDROID StartCoroutine(StartDelayedScan(0)); #elif UNITY_IPHONE && !UNITY_EDITOR StartCoroutine(StartDelayedScan(0.2f)); #elif UNITY_STANDALONE_OSX || UNITY_EDITOR StartCoroutine(StartDelayedScan(0.2f)); #endif } } else { m_status = "Scan impossible, reason: " + (scanReason)reason + "\nPlease check and hit scan again"; if (reason == 3) { if (b_Loggin) { Debug.Log("HeartRateScene: OnDeviceScan with false, reason 3 (powered off)\ncalling EnableBluetooth"); } BluetoothLEPlugin.EnableBluetooth(); } } }
public virtual void Connect() { if (IsDebug) { Debug.Log("BleDevice: Connecting " + GetType().ToString() + " " + Name + ", Adress: " + Adress + ", UUID: " + DeviceServUUID); } BluetoothLEPlugin.BleDeviceDisconnectEvent -= OnDeviceDisconnected; //keep here!!! BluetoothLEPlugin.BleDeviceDisconnectEvent += OnDeviceDisconnected; BluetoothLEPlugin.BleDeviceConnectEvent -= OnDeviceConnected; BluetoothLEPlugin.BleDeviceConnectEvent += OnDeviceConnected; if (IsDebug) { Debug.Log("BleDevice: BleDeviceDisconnectEvent and BleDeviceConnectEvent un-/resubscribed"); } BluetoothLEPlugin.BleValueChangeEvent -= OnDataReceived; BluetoothLEPlugin.BleValueChangeEvent += OnDataReceived; if (IsDebug) { Debug.Log("BleDevice: BleValueChangeEvent un-/resubscribed"); } BluetoothLEPlugin.Connect(this); }
void Awake() { m_instance = this; Debug.Log("BluetoothLEPlugin.cs; Awake: m_instance: " + m_instance); }
void OnDisable() { BluetoothLEPlugin.Stop(); }