コード例 #1
0
 /// <summary>
 /// Connect and manage connection as well as hook into your required characterisitcs with all proper cleanups necessary
 /// </summary>
 /// <param name="peripheral"></param>
 /// <param name="serviceUuid"></param>
 /// <param name="characteristicUuid"></param>
 /// <param name="useIndicationIfAvailable"></param>
 /// <returns></returns>
 public static IObservable <GattCharacteristicResult> Notify(this IPeripheral peripheral, string serviceUuid, string characteristicUuid, bool useIndicationIfAvailable = false)
 => peripheral
 .GetKnownCharacteristic(serviceUuid, characteristicUuid, true)
 .Select(x => x.EnableNotifications(true, useIndicationIfAvailable).Select(_ => x))
 .Switch()
 .Select(x => x.WhenNotificationReceived())
 .Switch();
コード例 #2
0
 public static Task <IGattCharacteristic> GetKnownCharacteristicAsync(this IPeripheral peripheral, string serviceUuid, string characteristicUuid, CancellationToken?cancelToken = null)
 => peripheral
 .GetKnownCharacteristic(serviceUuid, characteristicUuid)
 .Take(1)
 .ToTask(cancelToken ?? CancellationToken.None);
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="peripheral"></param>
 /// <param name="serviceUuid"></param>
 /// <param name="characteristicUuid"></param>
 /// <returns></returns>
 public static IObservable <byte[]?> ReadCharacteristic(this IPeripheral peripheral, string serviceUuid, string characteristicUuid)
 => peripheral
 .GetKnownCharacteristic(serviceUuid, characteristicUuid, true)
 .Select(x => x.Read())
 .Switch()
 .Select(x => x.Data);
コード例 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="peripheral"></param>
 /// <param name="serviceUuid"></param>
 /// <param name="characteristicUuid"></param>
 /// <param name="data"></param>
 /// <param name="withResponse"></param>
 /// <returns></returns>
 public static IObservable <GattCharacteristicResult> WriteCharacteristic(this IPeripheral peripheral, string serviceUuid, string characteristicUuid, byte[] data, bool withResponse = true)
 => peripheral
 .GetKnownCharacteristic(serviceUuid, characteristicUuid, true)
 .Select(x => x.Write(data, withResponse))
 .Switch();