Esempio n. 1
0
        public void Initialize(BluetoothLeDevice device, DeviceInformation deviceInfo)
        {
            // Check for valid input
            if (device == null)
            {
                throw new ArgumentNullException(@"In BEDeviceVM, BluetoothLeDevice cannot be null.");
            }
            if (deviceInfo == null)
            {
                throw new ArgumentNullException("In BEDeviceVM, DeviceInformation cannot be null.");
            }

            // Initialize variables
            _device     = device;
            _deviceInfo = deviceInfo;
            if (_device.ConnectionStatus == BluetoothLeDevice.BluetoothConnectionStatus.Connected)
            {
                Connected = true;
            }

            foreach (var service in _device.GattServices)
            {
                var serviceM = new BeServiceModel();
                serviceM.Initialize(service, this);
                ServiceModels.Add(serviceM);
            }

            // Register event handlers
            _device.ConnectionStatusChanged += OnConnectionStatusChanged;
            _device.NameChanged             += OnNameChanged;
            _device.GattServicesChanged     += OnGattervicesChanged;

            // Register for notifications from the device, on a separate thread
            //
            // NOTE:
            // This has the effect of telling the OS that we're interested in
            // these devices, and for it to automatically connect to them when
            // they are advertising.
            Utilities.RunFuncAsTask(RegisterNotificationsAsync);
        }
Esempio n. 2
0
        /// <summary>
        /// Performs the bare minimum initialization of this class.
        /// </summary>
        /// <param name="serviceM"></param>
        /// <param name="characteristic"></param>
        public void Initialize(BeServiceModel serviceM, GattCharacteristic characteristic)
        {
            if (serviceM == null)
            {
                throw new ArgumentNullException("In BECharacteristicVM, BEServiceModel cannot be null.");
            }

            ServiceM = serviceM;

            if (characteristic == null)
            {
                throw new ArgumentNullException("In BECharacteristicVM, GattCharacteristic cannot be null.");
            }

            _characteristic     = characteristic;
            CharacteristicValue = CHARACTERISTIC_VALUE_DEFAULT_STRING;
            GetDictionaryAndUpdateProperties();

            Writable |= ((_characteristic.CharacteristicProperties & GattCharacteristicProperties.WriteWithoutResponse) != 0);
            Writable |= ((_characteristic.CharacteristicProperties & GattCharacteristicProperties.Write) != 0);

            ToastInit();
        }