|
| 1 | +/*---------------------------------------------------------------*\ |
| 2 | +| GaiZhongGaiKeyboardController.cpp | |
| 3 | +| | |
| 4 | +| https://oshwlab.com/yangdsada/GaiZhongGai-Keyboard-68-4PRO | |
| 5 | +| | |
| 6 | +| An Yang 2022/6/12 | |
| 7 | +\*---------------------------------------------------------------*/ |
| 8 | + |
| 9 | +#include <cstring> |
| 10 | +#include "GaiZhongGaiKeyboardController.h" |
| 11 | + |
| 12 | +GaiZhongGaiKeyboardController::GaiZhongGaiKeyboardController(hid_device* dev_handle, hid_device_info* info) |
| 13 | +{ |
| 14 | + dev = dev_handle; |
| 15 | + location = info->path; |
| 16 | + usb_pid = info->product_id; |
| 17 | + /*-----------------------------------------------------*\ |
| 18 | + | Obtaining the Firmware Version | |
| 19 | + \*-----------------------------------------------------*/ |
| 20 | + char str[10]; |
| 21 | + sprintf(str, "Ver%04X", info->release_number); |
| 22 | + version = str; |
| 23 | +} |
| 24 | + |
| 25 | +GaiZhongGaiKeyboardController::~GaiZhongGaiKeyboardController() |
| 26 | +{ |
| 27 | + /*-----------------------------------------------------*\ |
| 28 | + | Restore built-in light effect | |
| 29 | + \*-----------------------------------------------------*/ |
| 30 | + unsigned char usb_buf[65]; |
| 31 | + memset(usb_buf, 0x00, sizeof(usb_buf)); |
| 32 | + usb_buf[1] = 0xFF; |
| 33 | + hid_write(dev, usb_buf, 65); |
| 34 | + std::this_thread::sleep_for(std::chrono::milliseconds(2)); |
| 35 | + |
| 36 | + hid_close(dev); |
| 37 | +} |
| 38 | + |
| 39 | +std::string GaiZhongGaiKeyboardController::GetDeviceLocation() |
| 40 | +{ |
| 41 | + return("HID: " + location); |
| 42 | +} |
| 43 | + |
| 44 | +std::string GaiZhongGaiKeyboardController::GetSerialString() |
| 45 | +{ |
| 46 | + wchar_t serial_string[128]; |
| 47 | + int ret = hid_get_serial_number_string(dev, serial_string, 128); |
| 48 | + |
| 49 | + if(ret != 0) |
| 50 | + { |
| 51 | + return(""); |
| 52 | + } |
| 53 | + |
| 54 | + std::wstring return_wstring = serial_string; |
| 55 | + std::string return_string(return_wstring.begin(), return_wstring.end()); |
| 56 | + |
| 57 | + return(return_string); |
| 58 | +} |
| 59 | + |
| 60 | +std::string GaiZhongGaiKeyboardController::GetVersion() |
| 61 | +{ |
| 62 | + return(version); |
| 63 | +} |
| 64 | + |
| 65 | +unsigned short GaiZhongGaiKeyboardController::GetUSBPID() |
| 66 | +{ |
| 67 | + return(usb_pid); |
| 68 | +} |
| 69 | + |
| 70 | +void GaiZhongGaiKeyboardController::SendColors |
| 71 | + ( |
| 72 | + unsigned char* color_data, |
| 73 | + unsigned int color_data_size |
| 74 | + ) |
| 75 | +{ |
| 76 | + unsigned char usb_buf[65]; |
| 77 | + |
| 78 | + memset(usb_buf, 0x00, sizeof(usb_buf)); |
| 79 | + |
| 80 | + switch(usb_pid) |
| 81 | + { |
| 82 | + case GAIZHONGGAI_17_TOUCH_PRO_PID: //17PAD+Touch |
| 83 | + case GAIZHONGGAI_20_PRO_PID: //20PAD |
| 84 | + usb_buf[1] = 0x10; |
| 85 | + memcpy(usb_buf + 2, color_data + 68 * 3, 60); |
| 86 | + hid_write(dev, usb_buf, 65); |
| 87 | + break; |
| 88 | + |
| 89 | + case GAIZHONGGAI_17_PRO_PID: //17PAD |
| 90 | + usb_buf[1] = 0x10; |
| 91 | + memcpy(usb_buf + 2, color_data + 68 * 3, 51); |
| 92 | + hid_write(dev, usb_buf, 65); |
| 93 | + break; |
| 94 | + |
| 95 | + case GAIZHONGGAI_68_PRO_PID: //68% |
| 96 | + usb_buf[1] = 0x10; |
| 97 | + memcpy(usb_buf + 2, color_data + 0 * 3, 63); |
| 98 | + hid_write(dev, usb_buf, 65); |
| 99 | + std::this_thread::sleep_for(std::chrono::milliseconds(2)); |
| 100 | + |
| 101 | + usb_buf[1] = 0x11; |
| 102 | + memcpy(usb_buf + 2, color_data + 21 * 3, 63); |
| 103 | + hid_write(dev, usb_buf, 65); |
| 104 | + std::this_thread::sleep_for(std::chrono::milliseconds(2)); |
| 105 | + |
| 106 | + usb_buf[1] = 0x12; |
| 107 | + memcpy(usb_buf + 2, color_data + 42 * 3, 63); |
| 108 | + hid_write(dev, usb_buf, 65); |
| 109 | + std::this_thread::sleep_for(std::chrono::milliseconds(2)); |
| 110 | + |
| 111 | + memset(usb_buf, 0x00, sizeof(usb_buf)); |
| 112 | + usb_buf[1] = 0x13; |
| 113 | + memcpy(usb_buf + 2, color_data + 63 * 3, 15); |
| 114 | + hid_write(dev, usb_buf, 65); |
| 115 | + break; |
| 116 | + } |
| 117 | +} |
0 commit comments