# @vernier/godirect

> A JavaScript library to easily interact with [Vernier Go Direct® Sensors](https://www.vernier.com/products/sensors/go-direct-sensors).

Latest version **1.8.3** (published 2023-06-27) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @vernier/godirect
pnpm add @vernier/godirect
yarn add @vernier/godirect
bun add @vernier/godirect
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.8.3 |
| Published | 2023-06-27 |
| First published | 2018-10-26 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 334.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Vernier Software & Technology |
| Maintainers | jaustin, jminor, nrobinson1, tthef |
| Keywords | vernier, godirect, gdx, bluetooth, usb, sensor, webbluetooth, webusb, webhid |

## Links

- npm: https://www.npmjs.com/package/@vernier/godirect
- Repository: https://github.com/VernierST/godirect-js
- Issues: https://github.com/VernierST/godirect-js/issues
- npm.io page: https://npm.io/package/@vernier/godirect

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.8.3 (latest) — 2023-06-27
- 1.8.2 — 2022-11-08
- 1.7.1 — 2021-01-07
- 1.8.0 — 2020-12-28
- 1.7.0 — 2020-06-04
- 1.6.0 — 2020-03-08
- 1.5.4 — 2019-08-21
- 1.5.2 — 2019-08-21
- 1.5.1 — 2019-08-08
- 1.5.0 — 2019-03-15
- 1.4.3 — 2019-02-01
- 1.4.2 — 2019-01-29
- 1.4.1 — 2019-01-23
- 1.4.0 — 2019-01-14
- 1.3.0 — 2019-01-09
- … 7 more at https://npm.io/package/@vernier/godirect/versions

## README

# GODIRECT JS - Vernier Go Direct® Sensor Library

[![Build Status](https://travis-ci.org/VernierST/godirect-js.svg?branch=main)](https://travis-ci.org/VernierST/godirect-js) [![Dependabot](https://flat.badgen.net/dependabot/vernierst/godirect-js/?icon=dependabot)](https://flat.badgen.net/dependabot/vernierst/godirect-js/?icon=dependabot)

A JavaScript library to easily interact with [Vernier Go Direct® Sensors](https://www.vernier.com/products/sensors/go-direct-sensors).

## Requirements

This library is currently only implemented using [WebBluetooth](https://webbluetoothcg.github.io/web-bluetooth/) and [WebHID](https://wicg.github.io/webhid/) both of which have limited browser support

Partial WebHID functionality is available in Chrome 78 behind a flag on desktop OSes. You will need to enable the "Experimental Web Platform Features" flag (chrome://flags/#enable-experimental-web-platform-features) and restart Chrome.

## Installation

Use the unpkg module version of library in your HTML document:
```html
<script src="https://unpkg.com/@vernier/godirect/dist/godirect.min.umd.js"></script>
```

Use the library as a JavaScript module:

1. Install the module via npm:

```
$ npm i @vernier/godirect
```

2. Import the module into your JavaScript file:
```javascript
import godirect from './node_modules/@vernier/godirect/dist/godirect.min.esm.js';
```

## Example Usage

### HTML
A user action is required to open the BLE device list in the browser (e.g. a user click event from a button). Create a button to initiate the request.
```html
<button id="select_device">Select Go Direct Device</button>
```

### JavaScript
Listen for the button click event.
```javascript
const selectDeviceBtn = document.querySelector('#select_device');

selectDeviceBtn.addEventListener('click', async () => {
  // All following code will go here.
});

```

 Open the browsers device list chooser. This call returns your selected device back. We'll assign the selected device to a constant called `device`;

**`NOTE:` you cannot invoke `godirect.selectDevice()` outside of a user interaction, like a click event. This is part of the browser security model.**
```javascript
// opens the browser list of ble devices matching to GDX
const device = await godirect.selectDevice();

// Get a filtered array of only the enabled sensor(s).
const enabledSensors = device.sensors.filter(s => s.enabled);

// Loop through the array of `enabledSensors` and log the value changes.
enabledSensors.forEach(sensor => {
  sensor.on('value-changed', (sensor) => {
    // log the sensor name, new value, and units.
    console.log(`Sensor: ${sensor.name} value: ${sensor.value} units: ${sensor.unit}`);
  });
});
```

See this example and others (including our Python versions) at our examples repository: [https://github.com/VernierST/godirect-examples](https://github.com/VernierST/godirect-examples) or visit the [live demos](https://vernierst.github.io/godirect-examples/javascript/)


## License

BSD 3-Clause License.

Vernier products are designed for educational use. Our products are not designed nor are they recommended for any industrial, medical, or commercial process such as life support, patient diagnosis, control of a manufacturing process, or industrial testing of any kind.

---
_Source: https://npm.io/package/@vernier/godirect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
