npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-fitbit-heartrate

v0.0.2

Published

Module to simplify access to heart rate inside Fitbit OS applications

Downloads

6

Readme

Simple Fitbit Heartrate

npm

Introduction

The goal of this project is to simplify access to the heart rate measures inside Fitbit OS applications.

It was built to do all this work easier and reduce the need to update the UI and calculations. Less you have to calculate something or update the UI and more you will reduce the impact of your application on the battery consumption.

Features

This module includes many features to help developers :

  • Get heart rate values each second.
  • Get values as a single object HeartReatMeasure.
  • The HeartReatMeasure is deined only when the module have new values to share to the fitbit application.
  • Type definitions for TypScript or JavaScript (with comments to visualize the documentation when you are coding).

Data structure

Data returned by the module respect the HeartReatMeasure interface.

interface HeartReatMeasure {
    /**
     * Hear rate (bpm)
     */
    heartRate: number;
    /**
     * Current heart rate Zone (combine default and custom zones)
     */
    zone: DefaultZone | UserDefinedZone;
    /**
     * Resting heart rate
     */
    restingHeartRate: number | undefined;
}

Installation

1. Install the module

You could use a any package manager to install this module. it was tested with npm and pnpm.

npm install simple-fitbit-heartrate --save-dev

2. Request user's permissions

Your application should have access to :

  • access_heart_rate : requested to obtain heart rate of the user.
  • access_user_profile: requested for user custom zones.

Your package.json should be like this (you could request more permissions, it is not a problem) :

Exemple :

{
    "requestedPermissions": [
        "access_heart_rate",
        "access_user_profile"]
}

If permissions are not well set, you will not have exceptions :

  • The callback method will return undefined.

3. Initialize the device app

Inside the app folder the index.ts file have to :

  • Import the module.
  • Initialize the module with the method to call when UI should be updated with new values.

Exemple :

import * as simpleHeartrate from "simple-fitbit-heartrate";
// initialize
simpleHeartrate.initialize(updateHeartrate);

4. Use and get activities

The updateHeartrate could be like this:

Exemple :

// Update heart rate informations
function updateHeartrate(value: simpleHeartrate.HeartReatMeasure | undefined): void {
  if (value === undefined) return;
  // Zones
  imageHrm.href = value.zone === "out-of-range"
    ? "images/stat_hr_open_48px.png"
    : "images/stat_hr_solid_48px.png";

  text.text = value.heartRate.toString();
}

5. Refresh / update

This module has logic to periodic refresh (each second). It try to get measures only when display is on.

6. Bonus

This modul expose :

  • last expose the last measure (it use the HeartReatMeasure interface).
  • start() and stop() to use with AOD.

Contribute or report issues

You can report any issue via GitHub, if you found one, please report it! This code was open to be shared and improved. If you have an idea, tell it or send a pull request. Keep in mind that this module is built for small devices. It does not have the goal to be a Swiss knife with hundreds of functions. It is why it is simple as possible.

Compilation

This module was built with TypeScript. It uses Typescript to generate JavaScript files that are imported by the Fitbit SDK. It includes the following npm scripts to:

  • build (generate JavaScript files and copy all requested files to the ./distribution directory).
  • clean (remove generated files from the ./distribution directory).
  • lint (code quality).