Expand description
§mendi
Async Rust library for streaming fNIRS neurofeedback data from Mendi headbands over Bluetooth Low Energy.
§Hardware
The Mendi headband is a consumer fNIRS (functional near-infrared spectroscopy) device that measures blood oxygenation in the prefrontal cortex. It communicates over BLE using protobuf-encoded messages on six GATT characteristics:
| UUID | Characteristic | Data |
|---|---|---|
| 0xABB1 | Frame | IMU + temperature + 3 optical channels (IR/red/ambient) |
| 0xABB2 | Sensor | Optical sensor register read/write |
| 0xABB3 | IMU | IMU register read/write |
| 0xABB4 | ADC | Battery voltage, charging, USB status |
| 0xABB5 | Diagnostics | Self-test results at power-on |
| 0xABB6 | Calibration | LED current offsets, auto-cal, low-power mode |
§Quick start
use mendi::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = MendiClient::new(MendiClientConfig::default());
let (mut rx, handle) = client.connect().await?;
while let Some(event) = rx.recv().await {
match event {
MendiEvent::Frame(f) => {
println!("temp={:.1}°C IR: L={} R={} P={}",
f.temperature, f.ir_left, f.ir_right, f.ir_pulse);
}
MendiEvent::Battery(b) => {
println!("Battery: {:.2}V charging={}", b.voltage(), b.charging);
}
MendiEvent::Disconnected => break,
_ => {}
}
}
Ok(())
}§Module overview
| Module | Purpose |
|---|---|
mendi_client | BLE scanning, connecting, and the mendi_client::MendiHandle API |
types | All event and data types produced by the client |
protocol | GATT UUIDs and BLE constants |
parse | Protobuf decoders for BLE notification payloads |
wire | Generated protobuf types from device_v4.proto |
§Protobuf code generation
The wire module contains Rust types generated from proto/device_v4.proto
using prost. By default, pre-generated code is bundled in
src/wire_generated.rs so you do not need protoc installed.
To regenerate from the .proto file (e.g. after modifying it), enable the
regenerate-proto feature:
cargo build --features regenerate-protoThis requires the protoc compiler to be available on your PATH.
After regenerating, copy the output to src/wire_generated.rs to update
the bundled version:
cp target/debug/build/mendi-*/out/mendi.rs src/wire_generated.rs§Feature flags
| Feature | Description |
|---|---|
simulate | Simulated + mock devices for testing without hardware |
tui | Terminal UI with real-time charts (implies simulate) |
regenerate-proto | Rebuild protobuf types from .proto (requires protoc) |
Modules§
- mendi_
client - BLE client for the Mendi neurofeedback headband.
- parse
- Protobuf decoders for Mendi BLE notification payloads.
- prelude
- Convenience re-exports.
- protocol
- GATT UUIDs and constants for the Mendi headband BLE protocol (V4).
- types
- Data types for events emitted by the Mendi BLE client.
- wire
- Generated protobuf types from the Mendi V4 wire protocol.