public static IObservable <byte[]> WhenReadOrNotify(this IGattCharacteristic character, TimeSpan readInterval) { if (character.CanNotify()) { return(character.SubscribeToNotifications()); } if (character.CanRead()) { return(character.ReadInterval(readInterval)); } throw new ArgumentException($"Characteristic {character.Uuid} does not have read or notify permissions"); }
public static IObservable <CharacteristicResult> WhenReadOrNotify(this IGattCharacteristic character, TimeSpan readInterval) { if (character.CanNotify()) { return(character .EnableNotifications() .Where(x => x) .Select(x => character.WhenNotificationReceived()) .Switch()); } if (character.CanRead()) { return(character.ReadInterval(readInterval)); } throw new ArgumentException($"Characteristic {character.Uuid} does not have read or notify permissions"); }