Exemple #1
0
 /// <summary>
 /// Will be called when <see cref="BluetoothLEDevice.ConnectionStatusChanged"/> is called.
 /// Used as a middleman to allow subscription from outside using <see cref="DeviceConnectionChanged"/>.
 /// </summary>
 private void ConnectionStatusChanged(BluetoothLEDevice sender, object args)
 {
     if (!Connected)
     {
         DisconnectBand();
     }
     DeviceConnectionChanged?.Invoke(DeviceIndex, Connected);
 }
Exemple #2
0
 private IoTCentral()
 {
     MessagingCenter.Subscribe <ResultMessage <IDevice> >(this, Constants.BLE_DEVICE_READY, (dev) => { DeviceReady?.Invoke(this, dev.Data); });
     MessagingCenter.Subscribe <ResultMessage <IoTCConnectionState> >(this, Constants.IOTC_DEVICE_CLIENT_CONNECTED, result =>
     {
         DeviceConnectionChanged?.Invoke(this, result.Data);
     });
     MessagingCenter.Subscribe <ResultMessage <IList <BluetoothServiceModel> > >(this, Constants.BLE_SERVICES_FETCHED, (services) => { ServicesFetched?.Invoke(this, services.Data); });
 }
Exemple #3
0
        private void RegisterDeviceConnectionChangedCallback()
        {
            Native.DeviceConnectionChangedCallback callback = (ref Native.CameraDeviceStruct device, bool status, IntPtr userData) =>
            {
                DeviceConnectionChanged?.Invoke(this, new CameraDeviceConnectionChangedEventArgs(ref device, status));
            };

            Native.SetDeviceConnectionChangedCallback(Handle, callback, IntPtr.Zero, out connectionCallbackId).
            ThrowIfFailed("Failed to set device connection changed callback");
        }
Exemple #4
0
        /// <summary>
        /// Disconnects the band by disposing all references. Band will stay paired though.
        /// </summary>
        /// <param name="triggerEvent">Should the <see cref="DeviceConnectionChanged"/> event be triggered?</param>
        public void DisconnectBand(bool triggerEvent = true)
        {
            if (triggerEvent)
            {
                DeviceConnectionChanged?.Invoke(DeviceIndex, false);
            }

            DeviceConnectionChanged = null;
            _heartRate.Dispose();
            _authentication.Dispose();
            if (_connectedBtDevice != null)
            {
                _connectedBtDevice.ConnectionStatusChanged -= ConnectionStatusChanged;
                _connectedBtDevice.Dispose();
                _connectedBtDevice = null;
            }

            // Needed to force an immediate update of the connection-status by deleting the removed references.
            GC.Collect();
        }