Crates.io | cerebrust |
lib.rs | cerebrust |
version | 0.3.1 |
created_at | 2025-02-28 23:56:10.392572+00 |
updated_at | 2025-04-12 16:40:47.97079+00 |
description | Cerebrust is a simple, easy-to-use library for working with NeuroSky devices under Rust. |
homepage | |
repository | https://github.com/TeddyHuang-00/cerebrust |
max_upload_size | |
id | 1573341 |
size | 46,528 |
A library for interfacing with NeuroSky devices over Bluetooth, using Rust.
[!IMPORTANT] Due to limitations in the availability of
bluez
, this library is only compatible with Linux systems.
Add to your Cargo.toml
:
[dependencies]
cerebrust = "0.1.0"
Create a DeviceConfig
and connect to the device:
use cerebrust::device::DeviceConfig;
#[tokio::main]
async fn main() -> bluer::Result<()> {
let stream = DeviceConfig::default()
.with_adapter("hci0".to_string())
.with_name("MyndBand".to_string())
.with_channel(5)
.connect()
.await
.unwrap();
// Use the `stream` to read data
Ok(())
}
Read packets with DataReader
:
use cerebrust::comm::DataReader;
//...
#[tokio::main]
async fn main() {
// ...
let mut data_reader = DataReader::new(stream);
while let Ok(packet) = data_reader.poll_next().await {
if let Some(eeg_power) = packet.eeg_power {
println!("{eeg_power:?}");
}
}
}
Try to convert the packet into a specific type:
use cerebrust::comm::PacketVariant;
//...
#[tokio::main]
async fn main() {
// ...
match packet.try_into() {
Ok(PacketVariant::RawWave { .. }) => {}
Ok(PacketVariant::EegPower { .. }) => {}
Err(e) => {
eprintln!("Error parsing packet: {:?}", e);
}
}
}
See the examples for full usage (requires a NeuroSky device).
Licensed under the MIT license.