Created a controller for the keyboard

This commit is contained in:
2021-05-07 23:28:37 +02:00
parent abec6ac0ba
commit d2d324485e
3 changed files with 86 additions and 70 deletions

View File

@@ -0,0 +1,58 @@
/*****************************************************************************
* 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
}
}
}
}