59 lines
1.8 KiB
Rust
59 lines
1.8 KiB
Rust
/*****************************************************************************
|
|
* Module: DasKeyboard
|
|
* Created On: Fri 07 May 2021 10:17:24 PM CEST
|
|
* Last Modified: Fri 07 May 2021 11:28:01 PM CEST
|
|
*
|
|
* Driver for DasKeyboard keyboards light
|
|
* Jali <jali@orca-central.de>
|
|
*****************************************************************************/
|
|
|
|
use std::ffi::{CStr, CString};
|
|
use hidapi::{DeviceInfo, HidApi, HidError, HidResult};
|
|
|
|
/** Driver for DasKeyboard RGB keyboards
|
|
* lighting controller
|
|
*/
|
|
pub struct DasKeyboardController {
|
|
dev: DeviceInfo,
|
|
location: CString,
|
|
use_traditional_send_data: bool,
|
|
version: String,
|
|
}
|
|
|
|
/** Implementation of the controller. */
|
|
impl DasKeyboardController {
|
|
/**
|
|
* Creates a new instance of ```DasKeyboardController```, which is
|
|
* bound to a currently connected device.
|
|
*
|
|
* # Arguments
|
|
*
|
|
* * `vendor_id` - The unique vendor/manufactorer id of the device
|
|
* * `product_id` - The unique product id of the device.
|
|
*/
|
|
pub fn new(vendor_id: u16, product_id: u16) -> HidResult<DasKeyboardController> {
|
|
match HidApi::new() {
|
|
Ok(api) => {
|
|
let device = api.device_list()
|
|
.find(d => d.vendor_id() == vendor_id && d.product_id() == product_id);
|
|
|
|
match device {
|
|
Some(d) => {
|
|
let c = DasKeyboardController {
|
|
dev = d,
|
|
location = d.path()
|
|
};
|
|
Ok(c)
|
|
},
|
|
None => {
|
|
Err(HidApiError("Could not open device"))
|
|
}
|
|
}
|
|
},
|
|
Err(e) => {
|
|
e
|
|
}
|
|
}
|
|
}
|
|
}
|