Skip to main content

Crate brainbit

Crate brainbit 

Source
Expand description

§brainbit

Rust library for BrainBit EEG headband devices via the NeuroSDK2 C library, loaded at runtime.

Supports BrainBit (original 4-channel), BrainBit 2, BrainBit Pro, BrainBit Flex 4/8, and related devices from BrainBit LLC.

§Cross-platform

Works on Windows, Linux, and macOS. The neurosdk2 shared library (neurosdk2.dll / libneurosdk2.so / libneurosdk2.dylib) is loaded at runtime via libloading — no build-time C dependencies.

Download the native library for your platform:

§Quick start

use brainbit::prelude::*;
use std::time::Duration;

// 1. Scan for devices
let scanner = Scanner::new(&[SensorFamily::LEBrainBit])?;
scanner.start()?;
std::thread::sleep(Duration::from_secs(5));
scanner.stop()?;

let devices = scanner.devices()?;
if devices.is_empty() {
    eprintln!("No BrainBit device found!");
    return Ok(());
}

// 2. Connect
let mut device = BrainBitDevice::connect(&scanner, &devices[0])?;
println!("Connected to: {}", device.name()?);
println!("Battery: {}%", device.battery_level()?);
println!("Firmware: {:?}", device.firmware_version()?);

// 3. Stream EEG for 4 seconds
let samples = device.capture_signal(BRAINBIT_SAMPLING_RATE as usize * 4)?;
for s in &samples[..5] {
    println!("#{}: O1={:.6}V O2={:.6}V T3={:.6}V T4={:.6}V",
        s.pack_num, s.channels[0], s.channels[1], s.channels[2], s.channels[3]);
}

§Module overview

ModulePurpose
preludeOne-line glob import of the most commonly needed types
ffiCross-platform FFI bindings for NeuroSDK2 (runtime-loaded)
typesC-compatible FFI types, enums, and structures
scannerBLE device scanner
deviceHigh-level device API: signal streaming, resistance, battery
errorError types

Modules§

device
High-level device abstraction for BrainBit sensors.
error
Error types for the BrainBit SDK wrapper.
ffi
Runtime-loaded FFI bindings to the NeuroSDK2 C library.
prelude
Convenience re-exports for downstream crates.
sandbox
Process-level network sandboxing for the NeuroSDK2 library.
scanner
BLE device scanner for discovering BrainBit devices.
types
FFI types matching cmn_type.h from the NeuroSDK2 C API.
verify
Runtime integrity verification for the NeuroSDK2 native library.