tomasslavicek

Get heart rate Garmin Connect IQ

Feb 5th, 2018
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. function getHeartRate(am) {
  2.     var heartRate = Activity.getActivityInfo().currentHeartRate;
  3.     if (heartRate == null) {
  4.         if (am has :getHeartRateHistory) {
  5.             var HRH = am.getHeartRateHistory(1, true);
  6.             var HRS = HRH.next();          
  7.             if (HRS != null && HRS.heartRate != ActivityMonitor.INVALID_HR_SAMPLE) {
  8.                 heartRate = HRS.heartRate;
  9.             }
  10.         }
  11.     }
  12.     if (heartRate != null) {
  13.         return heartRate;
  14.     } else {
  15.         return "--";
  16.     }
  17. }
  18.  
  19. function getMaxHr() {
  20.     try {
  21.         var currentSport = UserProfile.getCurrentSport();
  22.         if (currentSport != null) {
  23.             var zones = UserProfile.getHeartRateZones(currentSport);
  24.             if (zones instanceof Toybox.Lang.Array) {
  25.                 return zones[5];
  26.             }
  27.         }
  28.     }
  29.     catch (e) { }
  30.     return 185;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment