Created a controller for the keyboard
This commit is contained in:
58
src/controllers/DasKeyboard.rs
Normal file
58
src/controllers/DasKeyboard.rs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/controllers/mod.rs
Normal file
10
src/controllers/mod.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Definition of module controllers
|
||||
*
|
||||
* Created On: Fri 07 May 2021 09:19:14 PM CEST
|
||||
* Last Modified: Fri 07 May 2021 09:19:14 PM CEST
|
||||
*/
|
||||
|
||||
mod DasKeyboard;
|
||||
pub use DasKeyboard::DasKeyboardController;
|
||||
|
||||
Reference in New Issue
Block a user