|
| 1 | +/*-------------------------------------------------------------------*\ |
| 2 | +| DarkProjectKeyboardController.cpp | |
| 3 | +| | |
| 4 | +| Driver for DarkProjectKeyboard USB Controller | |
| 5 | +| | |
| 6 | +| Chris M (DrNo) 8 Apr 2022 | |
| 7 | +| | |
| 8 | +\*-------------------------------------------------------------------*/ |
| 9 | + |
| 10 | +#include "LogManager.h" |
| 11 | +#include "DarkProjectKeyboardController.h" |
| 12 | + |
| 13 | +static uint8_t packet_map[88] = |
| 14 | +{ |
| 15 | +/*00 ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 */ |
| 16 | + 5, 11, 17, 23, 29, 35, 41, 47, 53, 59, |
| 17 | + |
| 18 | +/*10 F10 F11 F12 PRT SLK PBK ` 1 2 3 */ |
| 19 | + 65, 71, 77, 83, 89, 95, 0, 6, 12, 18, |
| 20 | + |
| 21 | +/*20 4 5 6 7 8 9 0 - = BSP */ |
| 22 | + 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, |
| 23 | + |
| 24 | +/*30 INS HME PUP TAB Q W E R T Y */ |
| 25 | + 84, 90, 96, 1, 7, 13, 19, 25, 31, 37, |
| 26 | + |
| 27 | +/*40 U I O P [ ] \ DEL END PDN */ |
| 28 | + 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, |
| 29 | + |
| 30 | +/*50 CAP A S D F G H J K L */ |
| 31 | + 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, |
| 32 | + |
| 33 | +/*60 ; ' ENT LSH Z X C V B N */ |
| 34 | + 62, 68, 80, 3, 15, 21, 27, 33, 39, 45, |
| 35 | + |
| 36 | +/*70 M , . / RSH UP LCTL LWIN LALT SPC */ |
| 37 | + 51, 57, 63, 69, 81, 93, 4, 10, 16, 34, |
| 38 | + |
| 39 | +/*80 RALT RFNC MENU RCTL LFT DWN RGT */ |
| 40 | + 52, 58, 64, 76, 88, 94, 100 |
| 41 | + |
| 42 | +/* Missing Indexes 9, 22, 28, 40, 46, 70, 74, 75, 82, 86, 87, 92, 98, 99, 101 */ |
| 43 | +}; |
| 44 | + |
| 45 | +DarkProjectKeyboardController::DarkProjectKeyboardController(hid_device* dev_handle, const char* path) |
| 46 | +{ |
| 47 | + dev = dev_handle; |
| 48 | + location = path; |
| 49 | +} |
| 50 | + |
| 51 | +DarkProjectKeyboardController::~DarkProjectKeyboardController() |
| 52 | +{ |
| 53 | + hid_close(dev); |
| 54 | +} |
| 55 | + |
| 56 | +std::string DarkProjectKeyboardController::GetDeviceName() |
| 57 | +{ |
| 58 | + const int szTemp = HID_MAX_STR; |
| 59 | + wchar_t tmpName[szTemp]; |
| 60 | + |
| 61 | + hid_get_manufacturer_string(dev, tmpName, szTemp); |
| 62 | + std::wstring wName = std::wstring(tmpName); |
| 63 | + std::string name = std::string(wName.begin(), wName.end()); |
| 64 | + |
| 65 | + return name; |
| 66 | +} |
| 67 | + |
| 68 | +std::string DarkProjectKeyboardController::GetSerial() |
| 69 | +{ |
| 70 | + const int szTemp = HID_MAX_STR; |
| 71 | + wchar_t tmpName[szTemp]; |
| 72 | + |
| 73 | + hid_get_serial_number_string(dev, tmpName, szTemp); |
| 74 | + std::wstring wName = std::wstring(tmpName); |
| 75 | + std::string serial = std::string(wName.begin(), wName.end()); |
| 76 | + |
| 77 | + return serial; |
| 78 | +} |
| 79 | + |
| 80 | +std::string DarkProjectKeyboardController::GetLocation() |
| 81 | +{ |
| 82 | + return("HID: " + location); |
| 83 | +} |
| 84 | + |
| 85 | +void DarkProjectKeyboardController::SetLedsDirect(std::vector<RGBColor> colors) |
| 86 | +{ |
| 87 | + uint8_t RGbuffer[DARKPROJECTKEYBOARD_PACKET_SIZE] = { 0x08, 0x07, 0x00, 0x00, 0x00 }; |
| 88 | + uint8_t BAbuffer[DARKPROJECTKEYBOARD_PACKET_SIZE] = { 0x08, 0x07, 0x00, 0x01, 0x00 }; |
| 89 | + |
| 90 | + /*-----------------------------------------------------------------*\ |
| 91 | + | Set up Direct packet | |
| 92 | + | packet_map is the index of the Key from full_matrix_map and | |
| 93 | + | the value is the position in the direct packet buffer | |
| 94 | + \*-----------------------------------------------------------------*/ |
| 95 | + for(size_t i = 0; i < colors.size(); i++) |
| 96 | + { |
| 97 | + RGBColor key = colors[i]; |
| 98 | + uint16_t offset = packet_map[i]; |
| 99 | + |
| 100 | + RGbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetRValue(key); |
| 101 | + RGbuffer[DARKPROJECTKEYBOARD_GREEN_BYTE + offset] = RGBGetGValue(key); |
| 102 | + BAbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetBValue(key); |
| 103 | + } |
| 104 | + |
| 105 | + hid_write(dev, RGbuffer, DARKPROJECTKEYBOARD_PACKET_SIZE); |
| 106 | + hid_write(dev, BAbuffer, DARKPROJECTKEYBOARD_PACKET_SIZE); |
| 107 | +} |
| 108 | + |
0 commit comments