public BleGattCharacteristicViewModel(Guid service, Guid characteristic, IBleGattServer device, IUserDialogs dialogs) { m_device = device; m_dialogs = dialogs; m_service = service; m_characteristic = characteristic; RefreshValueCommand = new Command(async() => { await ReadValue(); }); EnableNotificationsCommand = new Command(EnableNotifications); DisableNotificationsCommand = new Command(DisableNotifications); ToggleNotificationsCommand = new Command(ToggleNotifications); WriteBytesCommand = new Command(async() => { await WriteCurrentBytes(); }); ValueAsHex = String.Empty; ValueAsString = String.Empty; m_device.ReadCharacteristicProperties(m_service, m_characteristic).ContinueWith( x => { Device.BeginInvokeOnMainThread( () => { //Log.Trace( "Reading properties for characteristic. id={0}", m_characteristic ); m_props = x.Result; RaisePropertyChanged(nameof(CanNotify)); RaisePropertyChanged(nameof(CanRead)); RaisePropertyChanged(nameof(CanWrite)); }); }); }
public BleGattCharacteristicViewModel(Guid serviceGuid, Guid characteristicGuid, IBleGattServerConnection gattServer, IUserDialogs dialogManager) { m_gattServer = gattServer; m_dialogManager = dialogManager; m_serviceGuid = serviceGuid; m_characteristicGuid = characteristicGuid; RefreshValueCommand = new Command(async() => { await ReadCharacteristicValue(); }); EnableNotificationsCommand = new Command(EnableNotifications); DisableNotificationsCommand = new Command(DisableNotifications); ToggleNotificationsCommand = new Command(() => { NotifyEnabled = !NotifyEnabled; }); WriteBytesCommand = new Command(async() => { await WriteCurrentBytes(); }); WriteCurrentBytesGUIDCommand = new Command(async() => { await WriteCurrentBytesGUID(); }); ValueAsHex = String.Empty; ValueAsString = String.Empty; ValueAsHexBytes = new Byte[] {}; m_gattServer.ReadCharacteristicProperties(m_serviceGuid, m_characteristicGuid).ContinueWith( x => { Device.BeginInvokeOnMainThread( () => { if (x.IsFaulted) { m_dialogManager.Toast(x.Exception.GetBaseException().Message); } else { Log.Trace("Reading properties for characteristic. id={0}", m_characteristicGuid); m_props = x.Result; RaisePropertyChanged(nameof(CanNotify)); RaisePropertyChanged(nameof(CanRead)); RaisePropertyChanged(nameof(CanWrite)); RaisePropertyChanged(nameof(CanIndicate)); } }); }); }
/// <summary> /// Return true if <see cref="CharacteristicProperty.Indicate" /> is set on this characteristic /// </summary> public static Boolean CanIndicate(this CharacteristicProperty properties) { return((properties & CharacteristicProperty.Indicate) != 0); }
/// <summary> /// Return true if <see cref="CharacteristicProperty.Write" /> or <see cref="CharacteristicProperty.WriteNoResponse" /> are /// set on this characteristic /// </summary> public static Boolean CanWrite(this CharacteristicProperty properties) { return((properties & (CharacteristicProperty.Write | CharacteristicProperty.WriteNoResponse)) != 0); }
/// <summary> /// Return true if <see cref="CharacteristicProperty.Read" /> is set on this characteristic /// </summary> public static Boolean CanRead(this CharacteristicProperty properties) { return((properties & CharacteristicProperty.Read) != 0); }
/// <summary> /// Return true if <see cref="CharacteristicProperty.Notify" /> is set on this characteristic /// </summary> public static Boolean CanNotify(this CharacteristicProperty properties) { return((properties & CharacteristicProperty.Notify) != 0); }