private void OnPageHeartRate(HeartRateData page, uint a) { var hr = page.HeartRate; Console.WriteLine("HRM : " + hr); AntManagerState.Instance.CyclistHeartRate = hr; AntManagerState.WriteToMemory(); }
private void HeartRate_ReadingChanged(object sender, Microsoft.Band.Portable.Sensors.BandSensorReadingEventArgs <Microsoft.Band.Portable.Sensors.BandHeartRateReading> e) { //Device.BeginInvokeOnMainThread(() => //{ // point = point == "." ? "" : "."; // HeartLabel.Text = "Heart Rate: + e.SensorReading.HeartRate.ToString() + point; System.Diagnostics.Debug.WriteLine("Heart rate: " + e.SensorReading.HeartRate.ToString()); //}); currentData = new HeartRateData { Timestamp = DateTime.Now, Value = e.SensorReading.HeartRate }; }
private async void CharacteristicHR_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs args) { // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.battery_level.xml try { int heartValue; var bytes = args.Characteristic.Value; heartValue = bytes[1]; if (_currentValue == null) { _currentValue = new HeartRateData(); } _currentValue.Value = bytes[1]; _currentValue.Timestamp = DateTime.Now; if (_characteristicBatteryLevel != null) { if (_currentValue.TimestampBatteryLevel == null || (DateTime.Now - _currentValue.TimestampBatteryLevel).Value.Minutes > 1) { _currentValue.BatteryLevel = null; var batteryLevelByte = await _characteristicBatteryLevel?.ReadAsync(); _currentValue.TimestampBatteryLevel = DateTime.Now; _currentValue.BatteryLevel = batteryLevelByte[0]; } } _log("CharacteristicHR_ValueUpdated", $"Device {_currentValue.Value}"); } catch (Exception e) { _log("CharacteristicHR_ValueUpdated", e.Message); } }
public void Stop() { lock (this) { try { if (bandClient != null) { bandClient.SensorManager.HeartRate.StopReadingsAsync(); bandClient.SensorManager.HeartRate.ReadingChanged -= HeartRate_ReadingChanged; bandClient.SensorManager.Pedometer.StopReadingsAsync(); bandClient.SensorManager.Pedometer.ReadingChanged -= Pedometer_ReadingChanged; bandClient = null; currentData = null; } } catch { } } }
private async Task _disconnect() { try { _characteristicHR.ValueUpdated -= CharacteristicHR_ValueUpdated; _characteristicHR.StopUpdates(); await _adapter.DisconnectDeviceAsync(_device); _connectionRetry = 0; _device = null; _serviceHR = null; _serviceBattery = null; _characteristicHR = null; _characteristicBatteryLevel = null; _currentValue = null; _log("_disconnect", "disconnected"); } catch (Exception e) { _log("_disconnect", e.Message); } }
private static void HeartRateDisplay_HeartRateDataReceived(HeartRateData arg3, uint arg4) { ANT.HeartRate = arg3.HeartRate.ToString(); }
public static bool Prefix(HeartRateData __instance) { var ghost = __instance.transform.GetComponentsInChildren <Text>(); var image = __instance.transform.GetComponentsInChildren <Image>(); if (ghost != null) { foreach (var test in ghost) { foreach (var images in image) { if (test.rectTransform.name.Contains("P1HRValueText") && (images.rectTransform.name.Contains("P1HeartImage"))) { if (p1Sanity > 75) { test.color = new Color(1, 1, 1, 1); images.color = new Color(0, 1, 0, 0.1f); } else if (p1Sanity < 75 && p1Sanity > 25) { test.color = new Color(1, 1, 1, 1); images.color = new Color(1, 0.92f, 0.016f, 0.1f); } else if (p1Sanity < 25) { test.color = new Color(1, 1, 1, 1); images.color = new Color(1, 0, 0, 0.1f); } GetPlayer1Insanity(test.text.Replace("%", "")); } if (test.rectTransform.name.Contains("P2HRValueText") && (images.rectTransform.name.Contains("P2HeartImage"))) { if (p2Sanity > 75) { test.color = new Color(1, 1, 1, 1); images.color = new Color(0, 1, 0, 0.10f); } else if (p2Sanity < 75 && p2Sanity > 25) { test.color = new Color(1, 1, 1, 1); images.color = new Color(1, 0.92f, 0.016f, 0.10f); } else if (p2Sanity < 25) { test.color = new Color(1, 1, 1, 1); images.color = new Color(1, 0, 0, 0.10f); } GetPlayer2Insanity(test.text.Replace("%", "")); } if (test.rectTransform.name.Contains("P3HRValueText") && (images.rectTransform.name.Contains("P3HeartImage"))) { if (p3Sanity > 75) { test.color = new Color(1, 1, 1, 1); images.color = new Color(0, 1, 0, 0.10f); } else if (p3Sanity < 75 && p3Sanity > 25) { test.color = new Color(1, 1, 1, 1); images.color = new Color(1, 0.92f, 0.016f, 0.10f); } else if (p3Sanity < 25) { test.color = new Color(1, 1, 1, 1); images.color = new Color(1, 0, 0, 0.10f); } GetPlayer3Insanity(test.text.Replace("%", "")); } if (test.rectTransform.name.Contains("P4HRValueText") && (images.rectTransform.name.Contains("P4HeartImage"))) { if (p4Sanity > 75) { test.color = new Color(1, 1, 1, 1); images.color = new Color(0, 1, 0, 0.10f); } else if (p4Sanity < 75 && p4Sanity > 25) { test.color = new Color(1, 1, 1, 1); images.color = new Color(1, 0.92f, 0.016f, 0.10f); } else if (p4Sanity < 25) { test.color = new Color(1, 1, 1, 1); images.color = new Color(1, 0, 0, 0.10f); } GetPlayer4Insanity(test.text.Replace("%", "")); } if (test.rectTransform.name.Contains("TitleText")) { averageSanity = p1Sanity + p2Sanity + p3Sanity + p4Sanity; test.color = new Color(1, 1, 1, 1); test.fontSize = 10; if (playerCount != 0) { test.text = $"Team Sanity\n Avg. {averageSanity / playerCount }%\n"; } } } } } return(true); }