@neurosdk2/websdk
v1.0.1
Published
To use this library, you will need:
Readme
NeuroSDK: Web
Getting started
Prerequisites
To use this library, you will need:
- a compatible device, turned on and either in pairing mode or already paired to your computer
- Headband
- BrainBit
- BrainBit Flex
- a browser with WebBluetooth capabilities
- any modern Chromium-based browser, e.g. Google Chrome
- to use WebBluetooth on Linux desktops you might need to turn on experimental Chromium flags
- a Bluetooth connection (adapter)
- a secure context
- localhost
- HTTPS-enabled webpage
Concepts
Device
The physical device that you have. Different devices come with different hardware and therefore can have different capabilities.
Sensor object
The JS object that you can use to interact with the device. It is obtained after making a successful connection to a device. You send commands to the device by calling methods on that object, and you receive data from the device by setting up callbacks on the sensor object.
Sample
A single set of values from the physical sensors (electrodes, gyroscope, infrared detectors), combining values from multiple channels.
Channel
A channel represents a single physical sensor.
Measurement
The period where your device sends data to the host. For example, you can start a signal measurement with startSignal() and end it with stopSignal(). During the time between those calls, a signalCallback will be called each time a new sample is available.
Filter
A post-processing function that can be applied to the samples. This package includes a 4Hz high pass, 30Hz low pass and two band stop filters. Filters can be combined sequentially to form a chain that acts as a single filter.
Example code
Starting a measurement and logging some signal samples:
import { requestSensor } from "@neurosdk2/websdk";
/* Helper function to pause the script */
function sleep(timeout): Promise<void> { return new Promise((resolve) => setTimeout(resolve, timeout)); }
/* `requestSensor` will return once the user has either dismissed the permission prompt (in which case, an error will be thrown) or selected a compatible device, as specified by the filter, and a connection has been established successfully */
const sensor = await requestSensor(["Headband", "BrainBit2"])
/* Callbacks are called once data is available. You can access battery level as a property at any time at `sensor.batteryLevel`. */
sensor.batteryLevelCallback = (level) => { console.log('Battery level', level); }
sensor.signalCallback = (signal) => { console.log('Samples', signal); }
/* This function starts the measurement. */
await sensor.startSignal()
/* For 5 seconds, signal samples will be logged about 250 times per second */
await sleep(5)
await sensor.stopSignal()Supported devices
Listed below are flat interfaces for supported devices. Most of the properties are the same for all of them and are inherited from the Sensor<T> type.
BrainBit2
BrainBitFlex
Headband
Sample types
export type XYZ = [number, number, number];