public override IObservable <CharacteristicGattResult> WhenNotificationReceived() { this.AssertNotify(); this.notificationOb = this.notificationOb ?? Observable.Create <CharacteristicGattResult>(ob => { //var trigger = new GattCharacteristicNotificationTrigger(this.native); var handler = new TypedEventHandler <Native, GattValueChangedEventArgs>((sender, args) => { if (sender.Equals(this.Native)) { var bytes = args.CharacteristicValue.ToArray(); var result = new CharacteristicGattResult(this, bytes); ob.OnNext(result); } }); this.Native.ValueChanged += handler; return(() => this.Native.ValueChanged -= handler); }) .Publish() .RefCount(); return(this.notificationOb); }
void OnValueChanged(Native sender, GattValueChangedEventArgs args) { if (sender.Equals(this.Native)) { var bytes = args.CharacteristicValue.ToArray(); var result = new CharacteristicGattResult(this, bytes); this.currentOb.OnNext(result); } }