public HeartRateMonitor (CBCentralManager manager, CBPeripheral peripheral) { if (manager == null) { throw new ArgumentNullException ("manager"); } else if (peripheral == null) { throw new ArgumentNullException ("peripheral"); } Location = HeartRateMonitorLocation.Unknown; Manager = manager; Peripheral = peripheral; Peripheral.Delegate = this; Peripheral.DiscoverServices (); }
public override void DiscoverCharacteristic (CBPeripheral peripheral, CBService service, NSError error) { if (disposed) { return; } foreach (var characteristic in service.Characteristics) { if (characteristic.UUID == HeartRateMeasurementCharacteristicUUID) { service.Peripheral.SetNotifyValue (true, characteristic); } else if (characteristic.UUID == BodySensorLocationCharacteristicUUID) { service.Peripheral.ReadValue (characteristic); } else if (characteristic.UUID == HeartRateControlPointCharacteristicUUID) { service.Peripheral.WriteValue (NSData.FromBytes ((IntPtr)1, 1), characteristic, CBCharacteristicWriteType.WithResponse); } } }
public override void UpdatedCharacterteristicValue (CBPeripheral peripheral, CBCharacteristic characteristic, NSError error) { if (disposed || error != null || characteristic.Value == null) { return; } if (characteristic.UUID == HeartRateMeasurementCharacteristicUUID) { UpdateHeartRate (characteristic.Value); } else if (characteristic.UUID == BodySensorLocationCharacteristicUUID) { UpdateBodySensorLocation (characteristic.Value); } }
public override void DiscoveredService (CBPeripheral peripheral, NSError error) { if (disposed) { return; } foreach (var service in peripheral.Services) { if (service.UUID == PeripheralUUID) { peripheral.DiscoverCharacteristics (service); } } }