Beispiel #1
0
		public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState)
		{
			Console.WriteLine ("OnConnectionStateChange: ");
			base.OnConnectionStateChange (gatt, status, newState);

			//TODO: need to pull the cached RSSI in here, or read it (requires the callback)
			Device device = new Device (gatt.Device, gatt, this, 0);

			switch (newState) {
			// disconnected
			case ProfileState.Disconnected:
				Console.WriteLine ("disconnected");
					if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
				{
					Console.WriteLine("Changing connection priority to balanced");
					gatt.RequestConnectionPriority(BluetoothGatt.ConnectionPriorityBalanced);
				}
				this.DeviceDisconnected (this, new DeviceConnectionEventArgs () { Device = device });
				break;
				// connecting
			case ProfileState.Connecting:
				Console.WriteLine ("Connecting");
				break;
				// connected
			case ProfileState.Connected:
				Console.WriteLine ("Connected");
					if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
				{
					Console.WriteLine("Changing connection priority to high");
					gatt.RequestConnectionPriority(BluetoothGatt.ConnectionPriorityHigh);
				}
				this.DeviceConnected (this, new DeviceConnectionEventArgs () { Device = device });
				break;
				// disconnecting
			case ProfileState.Disconnecting:
				Console.WriteLine ("Disconnecting");
				break;
			}
		}