示例#1
0
		public Characteristic (BluetoothGattCharacteristic nativeCharacteristic, BluetoothGatt gatt, GattCallback gattCallback)
		{
			this._nativeCharacteristic = nativeCharacteristic;
			this._gatt = gatt;
			this._gattCallback = gattCallback;

			if (this._gattCallback != null) {
				// wire up the characteristic value updating on the gattcallback
				this._gattCallback.CharacteristicValueUpdated += (object sender, CharacteristicReadEventArgs e) => {
					// it may be other characteristics, so we need to test
					if(e.Characteristic.ID == this.ID) {
						// update our underlying characteristic (this one will have a value)
						//TODO: is this necessary? probably the underlying reference is the same.
						//this._nativeCharacteristic = e.Characteristic;

						this.ValueUpdated (this, e);
					}
				};
			}
		}
示例#2
0
		public Device (BluetoothDevice nativeDevice, BluetoothGatt gatt, 
			GattCallback gattCallback, int rssi) : base ()
		{
			this._nativeDevice = nativeDevice;
			this._gatt = gatt;
			this._gattCallback = gattCallback;
			this._rssi = rssi;

			// when the services are discovered on the gatt callback, cache them here
			if (this._gattCallback != null) {
				this._gattCallback.ServicesDiscovered += (s, e) => {
					var services = this._gatt.Services;
					this._services = new List<IService> ();
					foreach (var item in services) {
						this._services.Add (new Service (item, this._gatt, this._gattCallback));
					}
					this.ServicesDiscovered (this, e);
				};
			}
		}
示例#3
0
		public Adapter ()
		{
			var appContext = Android.App.Application.Context;
			// get a reference to the bluetooth system service
			this._manager = (BluetoothManager) appContext.GetSystemService("bluetooth");
			this._adapter = this._manager.Adapter;

			this._gattCallback = new GattCallback (this);

			this._gattCallback.DeviceConnected += (object sender, DeviceConnectionEventArgs e) => {
				this._connectedDevices.Add ( e.Device);
				this.DeviceConnected (this, e);
			};

			this._gattCallback.DeviceDisconnected += (object sender, DeviceConnectionEventArgs e) => {
				// TODO: remove the disconnected device from the _connectedDevices list
				// i don't think this will actually work, because i'm created a new underlying device here.
				//if(this._connectedDevices.Contains(
				this.DeviceDisconnected (this, e);
			};
		}
示例#4
0
        public Characteristic(BluetoothGattCharacteristic nativeCharacteristic, BluetoothGatt gatt, GattCallback gattCallback)
        {
            this._nativeCharacteristic = nativeCharacteristic;
            this._gatt         = gatt;
            this._gattCallback = gattCallback;

            if (this._gattCallback != null)
            {
                // wire up the characteristic value updating on the gattcallback
                this._gattCallback.CharacteristicValueUpdated += (object sender, CharacteristicReadEventArgs e) => {
                    // it may be other characteristics, so we need to test
                    if (e.Characteristic.ID == this.ID)
                    {
                        // update our underlying characteristic (this one will have a value)
                        //TODO: is this necessary? probably the underlying reference is the same.
                        //this._nativeCharacteristic = e.Characteristic;

                        this.ValueUpdated(this, e);
                    }
                };
            }
        }
示例#5
0
        public Adapter()
        {
            var appContext = Android.App.Application.Context;

            // get a reference to the bluetooth system service
            this._manager = (BluetoothManager)appContext.GetSystemService("bluetooth");
            this._adapter = this._manager.Adapter;

            this._gattCallback = new GattCallback(this);

            this._gattCallback.DeviceConnected += (object sender, DeviceConnectionEventArgs e) => {
                this._connectedDevices.Add(e.Device);
                this.DeviceConnected(this, e);
            };

            this._gattCallback.DeviceDisconnected += (object sender, DeviceConnectionEventArgs e) => {
                // TODO: remove the disconnected device from the _connectedDevices list
                // i don't think this will actually work, because i'm created a new underlying device here.
                //if(this._connectedDevices.Contains(
                this.DeviceDisconnected(this, e);
            };
        }
示例#6
0
        public Device(BluetoothDevice nativeDevice, BluetoothGatt gatt,
                      GattCallback gattCallback, int rssi) : base()
        {
            this._nativeDevice = nativeDevice;
            this._gatt         = gatt;
            this._gattCallback = gattCallback;
            this._rssi         = rssi;

            // when the services are discovered on the gatt callback, cache them here
            if (this._gattCallback != null)
            {
                this._gattCallback.ServicesDiscovered += (s, e) => {
                    var services = this._gatt.Services;
                    this._services = new List <IService> ();
                    foreach (var item in services)
                    {
                        this._services.Add(new Service(item, this._gatt, this._gattCallback));
                    }
                    this.ServicesDiscovered(this, e);
                };
            }
        }
示例#7
0
 public Service(BluetoothGattService nativeService, BluetoothGatt gatt, GattCallback _gattCallback)
 {
     this._nativeService = nativeService;
     this._gatt          = gatt;
     this._gattCallback  = _gattCallback;
 }
示例#8
0
		public Service (BluetoothGattService nativeService, BluetoothGatt gatt, GattCallback _gattCallback)
		{
			this._nativeService = nativeService;
			this._gatt = gatt;
			this._gattCallback = _gattCallback;
		}