Introduction
kdri
is a library that lets you control Kettler devices via
bluetooth. This includes following models:
- TOUR
- RACER
- ERGO
- RECUMBENT
- UNIX
- SKYLON
- RUN
- TRACK
This library is tested on a RUN 7
. Because there are no platform independent
bluetooth libraries for Rust (yet), it only runs on BlueZ/Linux.
Example
extern crate kdri;
use std::io::Write;
use std::str::FromStr;
fn main() {
println!("Search for devices...");
let mut devices = kdri::scan_devices().expect("Scanning devices failed");
let device: kdri::KettlerDevice = devices.pop().expect("No devices found");
println!("Connect to \"{}\" (\"{}\")...", device.get_name(), device.get_addr().to_string());
let mut connection = device.connect().expect("Connecting to Kettler device failed");
println!("Connected!");
loop {
print!("> ");
std::io::stdout().flush().unwrap();
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
input = input.trim().to_string();
match input.as_str() {
"exit" => { break },
"pulse" => { println!("pulse: {:?}", connection.get_pulse());},
"speed" => { println!("speed: {:?}", connection.get_speed());},
"incline" => { println!("incline: {:?}", connection.get_incline());},
_ => {
let substring: Vec<_> = input.split('=').collect();
if substring.len() != 2 { println!("Input not recognized"); continue; }
let number: i32 = match FromStr::from_str(substring[1]) { Ok(n) => n, Err(_) => { println!("Expected number after '='"); continue; } };
match substring[0] {
"online" => connection.set_online(number != 0), "speed" => connection.set_speed(number as u16), "incline" => connection.set_incline(number as u16),
_ => println!("Unknown value '{}'", substring[0]),
}
}
}
}
connection.close();
}
Bindings for C
See kdri-c-wrapper.