private void SetUpdateValue(bool enable)
{
if (!_gatt.SetCharacteristicNotification(_nativeCharacteristic, enable))
throw new Exception("Unable to set the notification value on the characteristic");
// hackity-hack-hack
System.Threading.Thread.Sleep(100);
if (_nativeCharacteristic.Descriptors.Count > 0)
{
const string descriptorId = "00002902-0000-1000-8000-00805f9b34fb";
var value = enable ? BluetoothGattDescriptor.EnableNotificationValue : BluetoothGattDescriptor.DisableNotificationValue;
var descriptor = _nativeCharacteristic.Descriptors.FirstOrDefault(x => x.Uuid.ToString() == descriptorId);
if (descriptor != null && !descriptor.SetValue(value.ToArray()))
throw new Exception("Unable to set the notification value on the descriptor");
}
}
}