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

incyclist-ant-plus

v0.3.3

Published

Incyclist library for ANT+ - originally forked from longhorn/ant-plus

Downloads

561

Readme

incyclist-ant-plus

Module to interface ANT+ Sensors/Devices, developed and maintained for Incyclist Indoor Cycling App

Prerequisites

Libusb is included as a submodule. On Linux, you'll need libudev to build libusb. On Ubuntu/Debian: sudo apt-get install build-essential libudev-dev

Windows

Using the AntDevice binding

Use Zadig to install the WinUSB driver for your USB device. Otherwise you will get LIBUSB_ERROR_NOT_SUPPORTED when attempting to open devices.

Using the AntServerBinding binding

The antserver.exe needs to be deployed together with your app. You can find a pre-compiled version in the ./bin directory, or you can compile it yourself based on the sources provided in the ./antserver directory

Install

npm install incyclist-ant-plus

Usage

Create and connect to USB Device (stick)

const {AntDevice} = require('incyclist-ant-plus/lib/bindings')

const ant = new AntDevice({startupTimeout:2000})
const success = await ant.open()

The library will automatically detect the matching Stick type ( Garmin2 / Garmin3)

Reserve the next available channel

const channel = ant.getChannel();

Use channel to scan for Sensors

const {BicyclePowerSensor,FitnessEquipmentSensor,HeartRateSensor} = require('incyclist-ant-plus');

//channel.on('detect', (profile, id) => console.log('detected',profile,id))

//channel.on('data', (profile, id, data) => console.log('data',profile,id, data))

channel.attach(new BicyclePowerSensor())
channel.attach(new HeartRateSensor())
channel.attach(new FitnessEquipmentSensor())

const detected = await channel.startScanner({timeout:10000})
console.log(detected)

Stop ongoing scan

might be used when scan should be stopped as soon as first/specific device is detected

has to be called explicitly if scan is done without timeout

channel.stopScanner()

Use channel to connect to a specific Sensor

const {FitnessEquipmentSensor} = require('incyclist-ant-plus');

channel.on('data', (profile, id, data) => console.log('data',profile,id, data))

const sensor = new FitnessEquipmentSensor()
const success = await channel.startSensor(sensor)
console.log(detected)

if (success) {
	console.log( "set User Weight = 78kg, Bike Weight= 10kg" );
	await sensor.sendUserConfiguration(78,10);
	
	console.log( "set slope to 1.1%" );
	await sensor.sendTrackResistance(1.1);
}

Important notes

  • In order to avoid problems at next launch, always call ant.close() at the end of the program

Writing your customized Classes

The library was designed so that the implemention of the interfaces can be customized

As Incyclist is developed as React app running in Electron, it will require a special implementions of the IAntDevice interface

  • IpcAntDevice: to be used in the renderer process to communicate with the AntDevice class in the Electron main process
  • WinAntDevice: A special implementation using ANT.DLL, to remove the dependency to Zadig

Classes

AntDevice (IAntDevice)

Constructor

constructor( props?: {
	deviceNo?: number;
	startupTimeout?: number;
	detailedStartReport?:boolean
	debug?: boolean;
	logger?: { logEvent?: (event)=>void, log:(...args)=>void};
})

deviceNo: In case you have multiple sticks connected, identifies the stick number. (0=first,1=second,...). Adding/removing a stick will not be recognized during the session ( i.e. after first use of constructor)

startupTimeout: timeout (in ms) after which the startup attempt should be stopped. If no timeout is given, the open()call will be blocking.

detailedStartReport: if set to true, the open() method will provide more detailed result (AntOpenResult type), otherwise it will return a boolean

debug: enables debug mode ( message logging)

logger: logger to be use for debug logging

Methods

open

open():Promise<boolean|AntOpenResult>

Tries to open the stick. In case the property detailedStartReport has been set, it will return any of 'Success', 'NoStick', 'StartupError' Returns true on success and false on failure.

close

close():Promise<boolean>

Tries to close the stick and all opened channels. Returns true on success and false on failure.

getMaxChannels

getMaxChannels():number

returns the maximum number of channels that this stick supports; valid only after stick was opened successfully.

getDeviceNumber

getDeviceNumber():number

returns the current device(stick) number (0=first,1=second,...); valid only after stick was opened successfully.

getChannel

getChannel():IChannel

Tries to reserve the next available channel - up to the maximum number of channels as indicated by getMaxChannels()

Returns a Channel object on success and null on failure.

freeChannel

closeChannel(IChannel):void

removes the reservation for a channel. Note This should never be called directly. It will be called by the methods of stopScanner() and stopSensor()

write

write(data:Buffer):void

sends a message to the ANT+Device

Channel (IChannel)

TODO

Sensor

TODO

Available Sensors

TODO