gtec 0.0.1

Rust library and TUI for g.tec Unicorn Hybrid Black 8-channel EEG headset via the Unicorn C API (runtime-loaded)
Documentation

gtec

A Rust library and terminal UI for the g.tec Unicorn Hybrid Black 8-channel EEG headset via the Unicorn C API.

Rust FFI wrapper with 100% API parity — all 16 functions from unicorn.h bound, all types mapped to #[repr(C)] Rust equivalents, SHA-256 verification, and OS-level network sandboxing.

Installation

cargo add gtec

Supported hardware

Device Channels Sampling Rate Connection
Unicorn Hybrid Black 8 EEG + 3 accel + 3 gyro + battery + counter + validation (17 total) 250 Hz Bluetooth

Cross-platform

Works on Windows and Linux (x86_64). The Unicorn library is loaded at runtime via libloading — no build-time C dependencies.

Note: No macOS native library is provided by g.tec.

Native library sources

Platform Repository File
Windows Unicorn-Hybrid-Black-Windows-APIs Unicorn.dll
Linux Unicorn-Suite-Hybrid-Black libunicorn.so

Quick start

use gtec::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let serials = UnicornDevice::scan(true)?;
    let mut device = UnicornDevice::open(&serials[0])?;

    println!("Info: {:?}", device.device_info()?);

    let scans = device.capture(UNICORN_SAMPLING_RATE * 4)?;
    for s in &scans[..5] {
        println!("EEG: {:?}", s.eeg());
    }

    device.close()?;
    Ok(())
}

Project layout

gtec-rs/
├── Cargo.toml
├── README.md
├── CHANGELOG.md
├── LICENSE
└── src/
    ├── lib.rs            # Crate root + prelude
    ├── main.rs           # CLI binary
    ├── bin/tui.rs        # ratatui TUI (8-channel EEG charts)
    ├── ffi.rs            # Runtime-loaded Unicorn C API (16 functions)
    ├── types.rs          # #[repr(C)] types matching unicorn.h
    ├── device.rs         # High-level device API
    ├── error.rs          # Error types
    ├── verify.rs         # SHA-256 integrity verification
    └── sandbox.rs        # OS-level network sandboxing
├── sdk/
│   ├── download.sh       # Download + verify native libraries
│   └── checksums.sha256  # Pinned SHA-256 hashes
├── examples/
│   ├── scan.rs           # Device discovery
│   ├── stream.rs         # Signal streaming
│   └── read_eeg.rs       # 4-second EEG capture
└── tests/
    └── types_tests.rs    # FFI type layout + constant tests

Dependencies

Crate Purpose
libloading Runtime DLL/so loading
thiserror Error type derivation
log Logging facade
env_logger Log output
libc seccomp syscalls (Linux)
ratatui Terminal UI (optional)
crossterm Terminal backend (optional)

Running tests

cargo test

License

MIT