void InitializeCoreBluetooth() { manager.UpdatedState += OnCentralManagerUpdatedState; //HACK: Modified this to just quit after finding the first heart rate monitor EventHandler <CBDiscoveredPeripheralEventArgs> discovered = null; discovered += (sender, e) => { if (monitor != null) { monitor.Dispose(); } monitor = new HeartRateMonitor(manager, e.Peripheral); monitor.HeartRateUpdated += OnHeartRateUpdated; monitor.HeartBeat += OnHeartBeat; heartRateMonitors.Add(monitor); //HACK: instead of adding to a list, just use this one statusLabel.Text = "Found " + monitor.Name + "."; manager.DiscoveredPeripheral -= discovered; }; manager.DiscoveredPeripheral += discovered; manager.ConnectedPeripheral += (sender, e) => e.Peripheral.DiscoverServices(); manager.DisconnectedPeripheral += (sender, e) => DisconnectMonitor(); HeartRateMonitor.ScanForHeartRateMonitors(manager); }
void InitializeCoreBluetooth() { manager.UpdatedState += OnCentralManagerUpdatedState; manager.DiscoveredPeripheral += (sender, e) => { LogPeripheral("Discovered", e.Peripheral); heartRateMonitors.Add(e.Peripheral); deviceTableView.ReloadData(); }; manager.FailedToConnectPeripheral += (sender, e) => { LogPeripheral($"Failed to connect ({e.Error})", e.Peripheral); DisconnectMonitor(); }; manager.ConnectedPeripheral += (sender, e) => { LogPeripheral("Connected", e.Peripheral); statusLabel.StringValue = "Discovering services..."; disconnectButton.Hidden = false; e.Peripheral.DiscoverServices(); }; manager.DisconnectedPeripheral += (sender, e) => { LogPeripheral("Disconneceted", e.Peripheral); heartRateMonitors.Remove(e.Peripheral); deviceTableView.ReloadData(); DisconnectMonitor(); }; HeartRateMonitor.ScanForHeartRateMonitors(manager); }
void OnCentralManagerUpdatedState(object sender, EventArgs e) { string message = null; switch (manager.State) { case CBCentralManagerState.PoweredOn: HeartRateMonitor.ScanForHeartRateMonitors(manager); //connectButton.Enabled = true; message = "Scanning..."; return; case CBCentralManagerState.Unsupported: message = "The platform or hardware does not support Bluetooth Low Energy."; break; case CBCentralManagerState.Unauthorized: message = "The application is not authorized to use Bluetooth Low Energy."; break; case CBCentralManagerState.PoweredOff: message = "Bluetooth is currently powered off."; break; default: message = "Unhandled state: " + manager.State; break; } if (message != null) { var alert = new UIAlertView("Alert", message, null, "OK", null); alert.Show(); } }
void OnCentralManagerUpdatedState(object sender, EventArgs e) { string message = null; switch (manager.State) { case CBCentralManagerState.PoweredOn: if (!connectButton.Enabled) { HeartRateMonitor.ScanForHeartRateMonitors(manager); connectButton.Enabled = true; } return; case CBCentralManagerState.Unsupported: message = "The platform or hardware does not support Bluetooth Low Energy."; break; case CBCentralManagerState.Unauthorized: message = "The application is not authorized to use Bluetooth Low Energy."; break; case CBCentralManagerState.PoweredOff: message = "Bluetooth is currently powered off."; break; default: break; } if (message != null) { new NSAlert { MessageText = "Heart Rate Monitor cannot be used at this time.", InformativeText = message }.RunSheetModal(Window); NSApplication.SharedApplication.Terminate(manager); } }
void InitializeCoreBluetooth() { manager.UpdatedState += OnCentralManagerUpdatedState; manager.DiscoveredPeripheral += (sender, e) => { if (monitor != null) { monitor.Dispose(); } monitor = new HeartRateMonitor(manager, e.Peripheral); monitor.HeartRateUpdated += OnHeartRateUpdated; monitor.HeartBeat += OnHeartBeat; heartRateMonitors.AddHeartRateMonitor(monitor); deviceTableView.ReloadData(); }; manager.ConnectedPeripheral += (sender, e) => e.Peripheral.DiscoverServices(); manager.DisconnectedPeripheral += (sender, e) => DisconnectMonitor(); HeartRateMonitor.ScanForHeartRateMonitors(manager); }