Rust bindings for libdivecomputer, a cross-platform and open source library for communication with dive computers from various manufacturers.
This repository contains 2 crates:
| Name | Description | Links |
|---|---|---|
libdivecomputer |
Safe, idiomatic high-level Rust bindings | |
libdivecomputer-sys |
Unsafe auto-generated FFI bindings |
use libdivecomputer::{Context, Descriptor, LogLevel};
fn main() -> libdivecomputer::Result<()> {
let ctx = Context::builder()
.log_level(LogLevel::Warning)
.build()?;
// List all supported dive computers.
for desc in Descriptor::iter(&ctx)? {
println!("{desc} (family: {})", desc.family());
}
Ok(())
}See the libdivecomputer crate README for more examples, including scanning for devices, downloading dives, and parsing dive data.
Serial, USB, USB HID, IrDA, Bluetooth, BLE, and USB Storage.
BLE support requires the ble feature (enabled by default), which uses btleplug.
| Platform | Status | Transports |
|---|---|---|
| Linux | Fully supported | Serial, USB, USBHID, IrDA, Bluetooth, BLE |
| Android | Supported (requires NDK) | Serial, BLE |
| macOS | Supported | Serial, USB, USBHID, BLE |
| iOS | Supported | Serial, BLE |
| Windows | Supported (MSVC) | Serial, USB, USBHID, IrDA, BLE |
autoreconf(autotools) — Linux, macOS, iOSgccor compatible C compilergit(submodules)
sudo apt install autoconf automake libtool pkg-config \
libusb-1.0-0-dev libhidapi-dev libbluetooth-dev libdbus-1-dev libmtp-devbrew install automake autoconf libtool pkg-config libusb hidapi- Install Visual Studio Build Tools with "Desktop development with C++" and Windows SDK
- Install LLVM (for
libclangused bybindgen) - Download libusb and hidapi and extract them
- Set environment variables pointing to the extracted directories:
$env:LIBUSB_DIR = "C:\path\to\libusb"
$env:HIDAPI_DIR = "C:\path\to\hidapi"Build from a Developer Command Prompt (or run vcvarsall.bat x64 first):
git submodule update --init --recursive
cargo build --releasegit submodule update --init --recursive
cargo build --releaseWhen cross-compiling on an Intel Mac for aarch64-apple-darwin, the Homebrew-installed
libraries (libusb, hidapi) are x86_64 and cannot be used. You need to build arm64
versions from source:
# Install the Rust target
rustup target add aarch64-apple-darwin
# Build libusb for arm64
cd /tmp && git clone https://github.com/libusb/libusb && cd libusb
./autogen.sh
./configure --host=aarch64-apple-darwin --prefix=/tmp/libusb-arm64 \
CFLAGS="-arch arm64" LDFLAGS="-arch arm64" --disable-shared --enable-static
make && make install
# Build hidapi for arm64
cd /tmp && git clone https://github.com/libusb/hidapi && cd hidapi
cmake -B build -DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_INSTALL_PREFIX=/tmp/hidapi-arm64 -DBUILD_SHARED_LIBS=OFF
cmake --build build && cmake --install build
# Build with arm64 libraries
LIBUSB_DIR=/tmp/libusb-arm64 HIDAPI_DIR=/tmp/hidapi-arm64 \
cargo build --release --target aarch64-apple-darwinWithout LIBUSB_DIR/HIDAPI_DIR, the build will succeed but USB and USBHID
transports will be disabled for the cross-compiled target.
rustup target add x86_64-apple-darwin
cargo build --release --target x86_64-apple-darwinHomebrew libraries from /opt/homebrew/lib (arm64) will be skipped automatically.
Set LIBUSB_DIR/HIDAPI_DIR pointing to x86_64 builds for USB/USBHID support.
Requires full Xcode (not just Command Line Tools) for the iOS SDK:
# Install Xcode from the App Store, then:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
# Verify the iOS SDK is available
xcrun --show-sdk-path --sdk iphoneos
rustup target add aarch64-apple-ios
cargo build --release --target aarch64-apple-iosNote: USB/USBHID are not available on iOS. Serial and BLE are supported.
cargo run --example device_scanner # scan for dive computers
cargo run --example device_download -- -d "Shearwater Petrel 3" -t BLE # download dives
cargo run --example dive_parser -- -d "Suunto EON Steel" dives/*.bin # parse saved dives
# Low-level sys crate examples
cargo run -p libdivecomputer-sys --example list # list supported devices
cargo run -p libdivecomputer-sys --example version # print library versionLicensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Note that libdivecomputer has its own LGPL-2.1 license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.