/***************************************************************************** * Module: DasKeyboard * Created On: Fri 07 May 2021 10:17:24 PM CEST * Last Modified: Sat 08 May 2021 10:14:52 PM CEST * * Driver for DasKeyboard keyboards light * Jali *****************************************************************************/ use hidapi::{DeviceInfo, HidApi, HidError, HidResult}; use std::ffi::{CStr, CString}; use Usb::UsbDevice; /** Driver for DasKeyboard RGB keyboards * lighting controller */ pub struct DasKeyboardController { _dev: UsbDevice, _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 {} /** Send a command to the HID controller in the traditional way, * sending 8 bytes per call. * * # Arguments * * * `api` - Reference to the HidApi object. * * `device_info` - Reference to the device to write to. */ fn send_data_traditional(usb_device: &UsbDevice, data: &[u8]) { // traditional send_data (split into chunks of 8 bytes) let mut usb_buf = [0u8; 9]; let err_cnt = 3; let chk_sum = 0; usb_device.open().and_then(|dev| { for idx in (1..data.len() + 1).step_by(7) { usb_buf[0] = 1; for fld_idx in (1..7) { let tmp_idx = idx + fld_idx -1; if tmp_idx < length { usb_buf[fld_idx] = data[tmp_idx]; chk_sum ^= data[tmp_idx]; } else if tmp_idx == data.len() { usb_buf[fld_idx] = chk_sum; } else { usb_buf[fld_idx] = 0 } } match dev.send_feature_report(usb_buf) { Ok(_) { () }, Err(_) { idx = 0; if err_cnt == 0 { return (); } err_cnt -= 1; () } } } }) } }