diff --git a/Controllers/OKSController/OKSKeyboardController.cpp b/Controllers/OKSController/OKSKeyboardController.cpp new file mode 100644 index 000000000..088dfea4f --- /dev/null +++ b/Controllers/OKSController/OKSKeyboardController.cpp @@ -0,0 +1,178 @@ +/*-----------------------------------------*\ +| OKSKeyboardController.cpp | +| | +| Driver for OKS RGB keyboardlighting | +| controller | +| | +| Merafour (OKS) 2/24/2023 | +\*-----------------------------------------*/ + +#include +#include "OKSKeyboardController.h" + +OKSKeyboardController::OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid) +{ + dev = dev_handle; + location = path; + usb_pid = pid; + + SendInitialize(); +} + +OKSKeyboardController::~OKSKeyboardController() +{ + hid_close(dev); +} + +std::string OKSKeyboardController::GetDeviceLocation() +{ + return("HID: " + location); +} + +std::string OKSKeyboardController::GetSerialString() +{ + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); + + if(ret != 0) + { + return(""); + } + + std::wstring return_wstring = serial_string; + std::string return_string(return_wstring.begin(), return_wstring.end()); + + return(return_string); +} + +unsigned short OKSKeyboardController::GetUSBPID() +{ + return(usb_pid); +} + +void OKSKeyboardController::SendColors(unsigned char* color_data, unsigned int color_data_size) +{ + char usb_buf[65]; + union kb2_port_t Pack; + uint8_t cnt; + uint8_t red,green,blue; + uint16_t color_idx; + uint32_t irgb[14]; + uint16_t pos=0; + for(color_idx=0; color_idx<(6*21); color_idx += 14) + { + for(cnt=0; cnt<14; cnt++) + { + pos = color_idx+cnt; + red = color_data[pos*3+0]; + green = color_data[pos*3+1]; + blue = color_data[pos*3+2]; + irgb[cnt] = blue&0xFF; + irgb[cnt] <<= 8; + irgb[cnt] |= green&0xFF; + irgb[cnt] <<= 8; + irgb[cnt] |= red&0xFF; + irgb[cnt] <<= 8; + irgb[cnt] |= pos&0xFF; + } + kb2M_wled(&Pack, irgb); + usb_buf[0] = 0x04; + for(uint8_t i=0; i<64; i++) usb_buf[i+1] = Pack.bin[i]; + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, (unsigned char *)usb_buf, 65); + } + std::this_thread::sleep_for(std::chrono::milliseconds(5)); +} + +void OKSKeyboardController::SendKeyboardModeEx(const mode &m, unsigned char red, unsigned char green, unsigned char blue) +{ + union kb2_port_t Pack; + kb2M_wrgb(&Pack, m.brightness, m.value, m.speed, m.direction); + Send(Pack.bin, Pack.length+KB2_HEAD_SIZE); +} + +void OKSKeyboardController::Send(const uint8_t bin[], const uint16_t len) +{ + char usb_buf[65]; + uint16_t Len; + uint16_t pos; + pos=0; + while(pos64) Len=64; + for(uint8_t i=0; ilength; + + checksum += Pack->head; + checksum += len; + checksum += Pack->cmd; + if((len>0) && (len<=KB2_DATA_SIZE)) checksum += Pack->data[len-1]; + return checksum; +} +int OKSKeyboardController::kb2_add_32b(union kb2_port_t* const Pack, const uint32_t value) +{ + union uint32_kb2 Value; + if((Pack->length+4)>KB2_DATA_SIZE) return -1; + Value.data = value; + Pack->data[Pack->length++] = Value.Byte0; + Pack->data[Pack->length++] = Value.Byte1; + Pack->data[Pack->length++] = Value.Byte2; + Pack->data[Pack->length++] = Value.Byte3; + return 4; +} +void OKSKeyboardController::kb2M_init(union kb2_port_t* const Pack, const enum kb2_cmd cmd) +{ + Pack->head = KB2_PACK_HEAD; + Pack->length = 0; + Pack->cmd = cmd; + Pack->checksum = 0; +} +void OKSKeyboardController::kb2M_wrgb(union kb2_port_t* const Pack, const uint8_t bright, const uint8_t mode, const uint8_t speed, const uint8_t dir) +{ + kb2M_init(Pack, KB2_CMD_WRGB); + kb2_add_32b(Pack, bright); + Pack->data[Pack->length++] = mode; + Pack->data[Pack->length++] = speed; + Pack->data[Pack->length++] = dir; + Pack->data[Pack->length++] = 0xFF; + Pack->data[Pack->length++] = 0xFF; + Pack->checksum = kb2_ComputeChecksum(Pack); +} +void OKSKeyboardController::kb2M_wled(union kb2_port_t* const Pack, const uint32_t irgb[14]) +{ + kb2M_init(Pack, KB2_CMD_WLED); + for(uint8_t i=0; i<14; i++) kb2_add_32b(Pack, irgb[i]); + Pack->data[Pack->length++] = 0xFF; + Pack->data[Pack->length++] = 0xFF; + Pack->checksum = kb2_ComputeChecksum(Pack); +} diff --git a/Controllers/OKSController/OKSKeyboardController.h b/Controllers/OKSController/OKSKeyboardController.h new file mode 100644 index 000000000..b701790b1 --- /dev/null +++ b/Controllers/OKSController/OKSKeyboardController.h @@ -0,0 +1,92 @@ +/*-----------------------------------------*\ +| OKSKeyboardController.h | +| | +| Definitions and types for OKS RGB | +| keyboard lighting controller | +| | +| Merafour (OKS) 2/24/2023 | +\*-----------------------------------------*/ + +#include "RGBController.h" + +#include +#include +#include + +#pragma once + +/*-----------------------------------------------------*\ +| OKS vendor ID | +\*-----------------------------------------------------*/ +#define OKS_VID 0x1C4F + +/*-----------------------------------------------------*\ +| Keyboard product IDs | +\*-----------------------------------------------------*/ +#define OKS_OPTICAL_RGB_PID 0xEE88 + +/*-----------------------------------------------------*\ +| communication protocol | +\*-----------------------------------------------------*/ +#define KB2_PACK_HEAD (0x5C&0xFF) +#define KB2_HEAD_SIZE 4 +#define KB2_PORT_SIZE (64*4) +#define KB2_DATA_SIZE (KB2_PORT_SIZE-KB2_HEAD_SIZE) +union kb2_port_t +{ + uint8_t bin[KB2_PORT_SIZE]; + struct + { + uint8_t head; + uint8_t length; + uint8_t cmd; + uint8_t checksum; + uint8_t data[KB2_DATA_SIZE]; + }; +}; +enum kb2_cmd +{ + KB2_CMD_RRGB = 0x14, + KB2_CMD_WRGB = 0x15, + KB2_CMD_RLED = 0x16, + KB2_CMD_WLED = 0x17, +}; +union uint32_kb2 +{ + uint32_t data; + struct + { + uint8_t Byte0; + uint8_t Byte1; + uint8_t Byte2; + uint8_t Byte3; + }; +}; + +class OKSKeyboardController +{ +public: + OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid); + ~OKSKeyboardController(); + + std::string GetDeviceLocation(); + std::string GetSerialString(); + unsigned short GetUSBPID(); + + void SendColors(unsigned char* color_data, unsigned int color_data_size); + void SendKeyboardModeEx(const mode &m, unsigned char red, unsigned char green, unsigned char blue); + + +private: + hid_device* dev; + std::string location; + unsigned short usb_pid; + + void Send(const uint8_t bin[64], const uint16_t len); + void SendInitialize(); + uint8_t kb2_ComputeChecksum(const union kb2_port_t* const Pack); + int kb2_add_32b(union kb2_port_t* const Pack, const uint32_t value); + void kb2M_init(union kb2_port_t* const Pack, const enum kb2_cmd cmd); + void kb2M_wrgb(union kb2_port_t* const Pack, const uint8_t bright, const uint8_t mode, const uint8_t speed, const uint8_t dir); + void kb2M_wled(union kb2_port_t* const Pack, const uint32_t irgb[14]); +}; diff --git a/Controllers/OKSController/OKSKeyboardControllerDetect.cpp b/Controllers/OKSController/OKSKeyboardControllerDetect.cpp new file mode 100644 index 000000000..c5870bfd1 --- /dev/null +++ b/Controllers/OKSController/OKSKeyboardControllerDetect.cpp @@ -0,0 +1,27 @@ +#include "Detector.h" +#include "OKSKeyboardController.h" +#include "RGBController.h" +#include "RGBController_OKSKeyboard.h" +#include +/******************************************************************************************\ +* * +* DetectOKSKeyboardControllers * +* Reference: DuckyKeyboardController * +* Tests the USB address to see if a OKS Optical Axis RGB Keyboard controller exists there.* +* Reference:DetectDuckyKeyboardControllers * +\******************************************************************************************/ + +void DetectOKSKeyboardControllers(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + OKSKeyboardController* controller = new OKSKeyboardController(dev, info->path, info->product_id); + RGBController_OKSKeyboard* rgb_controller = new RGBController_OKSKeyboard(controller); + rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +} /* DetectOKSKeyboardControllers() */ + +REGISTER_HID_DETECTOR_I("OKS Optical Axis RGB", DetectOKSKeyboardControllers, OKS_VID, OKS_OPTICAL_RGB_PID, 1); diff --git a/Controllers/OKSController/RGBController_OKSKeyboard.cpp b/Controllers/OKSController/RGBController_OKSKeyboard.cpp new file mode 100644 index 000000000..e1bc2cd91 --- /dev/null +++ b/Controllers/OKSController/RGBController_OKSKeyboard.cpp @@ -0,0 +1,303 @@ +/*-----------------------------------------*\ +| RGBController_OKSKeyboard.cpp | +| | +| Generic RGB Interface for OKS RGB | +| keyboard devices | +| | +| Merafour (OKS) 2/24/2023 | +\*-----------------------------------------*/ + +#include "RGBControllerKeyNames.h" +#include "RGBController_OKSKeyboard.h" + +//0xFFFFFFFF indicates an unused entry in matrix +#define NA 0xFFFFFFFF + +static unsigned int matrix_map_optical[6][21] = + { { 0, NA, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, NA, NA, NA, NA }, + { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41 }, + { 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62 }, + { 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, NA, 76, NA, NA, NA, 80, 81, 82, NA }, + { 84, NA, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, NA, 97, NA, 99, NA, 101, 102, 103, 104 }, + { 105, 106, 107, NA, NA, NA, 111, NA, NA, NA, 115, 116, 117, 118, 119, 120, 121, 122, NA, 124, NA } }; + +static unsigned int matrix_kb87_map[6][17] = +{ { 0, NA, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, + { 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33}, + { 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50}, + { 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, NA, 64, NA, NA, NA}, + { 68, NA, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, NA, 81, NA, 83, NA}, + { 85, 86, 87, NA, NA, NA, 91, NA, NA, NA, 95, 96, 97, 98, 99, 100, 101} }; + +static const char* zone_names[] = +{ + "Keyboard", +}; + +static zone_type zone_types[] = +{ + ZONE_TYPE_MATRIX, +}; + +static const unsigned int zone_sizes_optical[] = +{ + 126 +}; + +static const unsigned int zone_sizes_kb87[] = +{ + 102 +}; + +static const char *led_names[] = +{ + // R0--0 + KEY_EN_ESCAPE, KEY_EN_UNUSED, KEY_EN_F1, KEY_EN_F2, KEY_EN_F3, KEY_EN_F4, KEY_EN_F5, KEY_EN_F6, KEY_EN_F7, KEY_EN_F8, KEY_EN_F9, KEY_EN_F10, KEY_EN_F11, KEY_EN_F12, KEY_EN_PRINT_SCREEN, KEY_EN_SCROLL_LOCK, KEY_EN_PAUSE_BREAK, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_UNUSED, + // R1--21 + KEY_EN_BACK_TICK, KEY_EN_1, KEY_EN_2, KEY_EN_3, KEY_EN_4, KEY_EN_5, KEY_EN_6, KEY_EN_7, KEY_EN_8, KEY_EN_9, KEY_EN_0, KEY_EN_MINUS, KEY_EN_EQUALS, KEY_EN_BACKSPACE, KEY_EN_INSERT, KEY_EN_HOME, KEY_EN_PAGE_UP, KEY_EN_NUMPAD_LOCK, KEY_EN_NUMPAD_DIVIDE, KEY_EN_NUMPAD_TIMES, KEY_EN_NUMPAD_MINUS, + // R2--42 + KEY_EN_TAB, KEY_EN_Q, KEY_EN_W, KEY_EN_E, KEY_EN_R, KEY_EN_T, KEY_EN_Y, KEY_EN_U, KEY_EN_I, KEY_EN_O, KEY_EN_P, KEY_EN_LEFT_BRACKET, KEY_EN_RIGHT_BRACKET, KEY_EN_ANSI_BACK_SLASH, KEY_EN_DELETE, KEY_EN_END, KEY_EN_PAGE_DOWN, KEY_EN_NUMPAD_7, KEY_EN_NUMPAD_8, KEY_EN_NUMPAD_9, KEY_EN_NUMPAD_PLUS, + // R3--63 + KEY_EN_CAPS_LOCK, KEY_EN_A, KEY_EN_S, KEY_EN_D, KEY_EN_F, KEY_EN_G, KEY_EN_H, KEY_EN_J, KEY_EN_K, KEY_EN_L, KEY_EN_SEMICOLON, KEY_EN_QUOTE, KEY_EN_UNUSED, KEY_EN_ANSI_ENTER, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_NUMPAD_4, KEY_EN_NUMPAD_5, KEY_EN_NUMPAD_6, KEY_EN_UNUSED, + // R4--84 + KEY_EN_LEFT_SHIFT, KEY_EN_UNUSED, KEY_EN_Z, KEY_EN_X, KEY_EN_C, KEY_EN_V, KEY_EN_B, KEY_EN_N, KEY_EN_M, KEY_EN_COMMA, KEY_EN_PERIOD, KEY_EN_FORWARD_SLASH, KEY_EN_UNUSED, KEY_EN_RIGHT_SHIFT, KEY_EN_UNUSED, KEY_EN_UP_ARROW, KEY_EN_UNUSED, KEY_EN_NUMPAD_1, KEY_EN_NUMPAD_2, KEY_EN_NUMPAD_3, KEY_EN_NUMPAD_ENTER, + // R5--105 + KEY_EN_LEFT_CONTROL, KEY_EN_LEFT_WINDOWS, KEY_EN_LEFT_ALT, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_SPACE, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_RIGHT_ALT, KEY_EN_RIGHT_FUNCTION, KEY_EN_MENU, KEY_EN_RIGHT_CONTROL, KEY_EN_LEFT_ARROW, KEY_EN_DOWN_ARROW, KEY_EN_RIGHT_ARROW, KEY_EN_NUMPAD_0, KEY_EN_UNUSED, KEY_EN_NUMPAD_PERIOD, KEY_EN_UNUSED, + // "Key: Calculator", +}; + +static const char *led_kb87_names[] = +{ + // R0--0 + KEY_EN_ESCAPE, KEY_EN_UNUSED, KEY_EN_F1, KEY_EN_F2, KEY_EN_F3, KEY_EN_F4, KEY_EN_F5, KEY_EN_F6, KEY_EN_F7, KEY_EN_F8, KEY_EN_F9, KEY_EN_F10, KEY_EN_F11, KEY_EN_F12, KEY_EN_PRINT_SCREEN, KEY_EN_SCROLL_LOCK, KEY_EN_PAUSE_BREAK, + // R1--17 + KEY_EN_BACK_TICK, KEY_EN_1, KEY_EN_2, KEY_EN_3, KEY_EN_4, KEY_EN_5, KEY_EN_6, KEY_EN_7, KEY_EN_8, KEY_EN_9, KEY_EN_0, KEY_EN_MINUS, KEY_EN_EQUALS, KEY_EN_BACKSPACE, KEY_EN_INSERT, KEY_EN_HOME, KEY_EN_PAGE_UP, + // R2--34 + KEY_EN_TAB, KEY_EN_Q, KEY_EN_W, KEY_EN_E, KEY_EN_R, KEY_EN_T, KEY_EN_Y, KEY_EN_U, KEY_EN_I, KEY_EN_O, KEY_EN_P, KEY_EN_LEFT_BRACKET, KEY_EN_RIGHT_BRACKET, KEY_EN_ANSI_BACK_SLASH, KEY_EN_DELETE, KEY_EN_END, KEY_EN_PAGE_DOWN, + // R3--51 + KEY_EN_CAPS_LOCK, KEY_EN_A, KEY_EN_S, KEY_EN_D, KEY_EN_F, KEY_EN_G, KEY_EN_H, KEY_EN_J, KEY_EN_K, KEY_EN_L, KEY_EN_SEMICOLON, KEY_EN_QUOTE, KEY_EN_UNUSED, KEY_EN_ANSI_ENTER, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_UNUSED, + // R4--68 + KEY_EN_LEFT_SHIFT, KEY_EN_UNUSED, KEY_EN_Z, KEY_EN_X, KEY_EN_C, KEY_EN_V, KEY_EN_B, KEY_EN_N, KEY_EN_M, KEY_EN_COMMA, KEY_EN_PERIOD, KEY_EN_FORWARD_SLASH, KEY_EN_UNUSED, KEY_EN_RIGHT_SHIFT, KEY_EN_UNUSED, KEY_EN_UP_ARROW, KEY_EN_UNUSED, + // R5--85 + KEY_EN_LEFT_CONTROL, KEY_EN_LEFT_WINDOWS, KEY_EN_LEFT_ALT, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_SPACE, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_UNUSED, KEY_EN_RIGHT_ALT, KEY_EN_RIGHT_FUNCTION, KEY_EN_MENU, KEY_EN_RIGHT_CONTROL, KEY_EN_LEFT_ARROW, KEY_EN_DOWN_ARROW, KEY_EN_RIGHT_ARROW, KEY_EN_NUMPAD_0, + // "Key: Calculator", +}; +enum +{ + OKS_SPEED_SLOWEST = 0x00, // Slowest speed + OKS_SPEED_SLOWER = 0x01, // Slower speed + OKS_SPEED_SLOW = 0x02, // Slow speed + OKS_SPEED_SLOWISH = 0x02, // Slowish speed + OKS_SPEED_NORMAL = 0x02, // Normal speed + OKS_SPEED_FASTISH = 0x03, // Fastish speed + OKS_SPEED_FAST = 0x04, // Fast speed + OKS_SPEED_FASTER = 0x05, // Faster speed + OKS_SPEED_FASTEST = 0x06, // Fastest speed +}; +/**------------------------------------------------------------------*\ + @name OKS Keyboard | + @category Keyboard | + @type USB | + @save :x: | + @direct :white_check_mark: | + @effects :x: | + @detectors DetectOKSKeyboardControllers | + @comment | +\*-------------------------------------------------------------------*/ + +RGBController_OKSKeyboard::RGBController_OKSKeyboard(OKSKeyboardController* controller_ptr) +{ + controller = controller_ptr; + + + name = "OKS Keyboard Device"; + vendor = "OKS"; + type = DEVICE_TYPE_KEYBOARD; + description = "OKS Keyboard Device"; + location = controller->GetDeviceLocation(); + serial = controller->GetSerialString(); + + mode Direct; + Direct.name = "Direct"; + Direct.value = UP_RGB_MODES_DIRECT; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS ; + Direct.brightness_min = 0; + Direct.brightness_max = 5; + Direct.brightness = 2; + Direct.color_mode = MODE_COLORS_PER_LED; + Direct.speed_min = OKS_SPEED_FASTEST; + Direct.speed_max = OKS_SPEED_SLOWEST; + Direct.speed = OKS_SPEED_NORMAL; + Direct.direction = MODE_DIRECTION_RIGHT; + modes.push_back(Direct); + + mode udef = Direct; + udef.name = "User mode1"; + udef.value = UP_RGB_MODES_UDEF1; + udef.direction = MODE_DIRECTION_LEFT; + udef.speed = 0; + modes.push_back(udef); + udef.name = "User mode2"; + udef.value = UP_RGB_MODES_UDEF2; + modes.push_back(udef); + udef.name = "User mode3"; + udef.value = UP_RGB_MODES_UDEF3; + modes.push_back(udef); + udef.name = "User mode4"; + udef.value = UP_RGB_MODES_UDEF4; + modes.push_back(udef); + udef.name = "User mode5"; + udef.value = UP_RGB_MODES_UDEF5; + modes.push_back(udef); + /*---------------------------------------------------------*\ + | Delete the "Horse race lamp","Breathing"... mode | + \*---------------------------------------------------------*/ + SetupZones(); +} + +RGBController_OKSKeyboard::~RGBController_OKSKeyboard() +{ + /*---------------------------------------------------------*\ + | Delete the matrix map | + \*---------------------------------------------------------*/ + for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++) + { + if(zones[zone_index].matrix_map != NULL) + { + delete zones[zone_index].matrix_map; + } + } + + delete controller; +} + +void RGBController_OKSKeyboard::SetupZones() +{ + /*---------------------------------------------------------*\ + | Set up zones | + \*---------------------------------------------------------*/ + unsigned int total_led_count = 0; + for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++) + { + unsigned int zone_size = 0; + unsigned int matrix_width = 0; + unsigned int* matrix_map_ptr = NULL; + + switch(serial.c_str()[0]) + { + case 'B': + zone_size = zone_sizes_kb87[zone_idx]; + matrix_width = 17; + matrix_map_ptr = (unsigned int *)&matrix_kb87_map; + break; + default: + zone_size = zone_sizes_optical[zone_idx]; + matrix_width = 21; + matrix_map_ptr = (unsigned int *)&matrix_map_optical; + break; + } + + zone new_zone; + new_zone.name = zone_names[zone_idx]; + new_zone.type = zone_types[zone_idx]; + new_zone.leds_min = zone_size; + new_zone.leds_max = zone_size; + new_zone.leds_count = zone_size; + new_zone.matrix_map = new matrix_map_type; + new_zone.matrix_map->height = 6; + new_zone.matrix_map->width = matrix_width; + new_zone.matrix_map->map = matrix_map_ptr; + zones.push_back(new_zone); + + total_led_count += zone_size; + } + + for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++) + { + led new_led; + switch(serial.c_str()[0]) + { + case 'B': + new_led.name = led_kb87_names[led_idx]; + break; + + default: + new_led.name = led_names[led_idx]; + break; + } + leds.push_back(new_led); + } + + SetupColors(); +} + +void RGBController_OKSKeyboard::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_OKSKeyboard::DeviceUpdateLEDs() +{ + unsigned char colordata[155*3]; + unsigned int width; + unsigned int kb_idx; + unsigned int row_idx; + unsigned int col_idx; + + width = zones[0].matrix_map->width; + for(std::size_t color_idx = 0; color_idx < 155; color_idx++) + { + colordata[(color_idx*3)+0] = 0x00; + colordata[(color_idx*3)+1] = 0x00; + colordata[(color_idx*3)+2] = 0x00; + } + /*---------------------------------------------------------*\ + | send 6x21 matrix | + \*---------------------------------------------------------*/ + for(std::size_t color_idx = 0; color_idx < colors.size(); color_idx++) + { + row_idx = color_idx/width; + col_idx = color_idx%width; + kb_idx = row_idx*21+col_idx; + colordata[(kb_idx*3)+0] = RGBGetRValue(colors[color_idx]); + colordata[(kb_idx*3)+1] = RGBGetGValue(colors[color_idx]); + colordata[(kb_idx*3)+2] = RGBGetBValue(colors[color_idx]); + } + + controller->SendColors(colordata, colors.size()*3); +} + +void RGBController_OKSKeyboard::UpdateZoneLEDs(int zone) +{ + DeviceUpdateLEDs(); +} + +void RGBController_OKSKeyboard::UpdateSingleLED(int led) +{ + UpdateZoneLEDs(led); +} + +void RGBController_OKSKeyboard::SetCustomMode() +{ + active_mode = 0; +} + +void RGBController_OKSKeyboard::DeviceUpdateMode() +{ + mode m = modes[active_mode]; + unsigned char red = 0x00; + unsigned char grn = 0x00; + unsigned char blu = 0x00; + unsigned char random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM); + + if(modes[active_mode].colors.size() > 0) + { + red = RGBGetRValue(modes[active_mode].colors[0]); + grn = RGBGetGValue(modes[active_mode].colors[0]); + blu = RGBGetBValue(modes[active_mode].colors[0]); + } + + controller->SendKeyboardModeEx(m, red, grn, blu); +} diff --git a/Controllers/OKSController/RGBController_OKSKeyboard.h b/Controllers/OKSController/RGBController_OKSKeyboard.h new file mode 100644 index 000000000..71560c0a6 --- /dev/null +++ b/Controllers/OKSController/RGBController_OKSKeyboard.h @@ -0,0 +1,71 @@ +/*-----------------------------------------*\ +| RGBController_OKSKeyboard.h | +| | +| Generic RGB Interface for OKS RGB | +| keyboard devices | +| | +| Merafour (OKS) 2/24/2023 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "OKSKeyboardController.h" + +/*-----------------------------------------------------*\ +| mode | +\*-----------------------------------------------------*/ +enum user_param_view_mode_t +{ + UP_RGB_MODES_MASK = 0x7F, + UP_RGB_PAUSE__MASK = 0x80, + UP_RGB_PAUSE_ON = 0x80, + UP_RGB_PAUSE_OFF = 0x00, + /*------------------------------------------------------------*\ + | direct mode,eg:OpenRGB+Artemis | + \*------------------------------------------------------------*/ + UP_RGB_MODES_DIRECT = 0x00, + /*------------------------------------------------------------*\ + | user define mode | + \*------------------------------------------------------------*/ + UP_RGB_MODES_UDEF1 = 0x01, + UP_RGB_MODES_UDEF2 = 0x02, + UP_RGB_MODES_UDEF3 = 0x03, + UP_RGB_MODES_UDEF4 = 0x04, + UP_RGB_MODES_UDEF5 = 0x05, + UP_RGB_MODES_RECORD = 0x06, + /*------------------------------------------------------------*\ + | default mode | + \*------------------------------------------------------------*/ + UP_RGB_MODES_RACE = 0x07, + UP_RGB_MODES_BREAT = 0x08, + UP_RGB_MODES_RIPPLE = 0x09, + UP_RGB_MODES_DIFF = 0x0A, + UP_RGB_MODES_WAVE = 0x0B, + UP_RGB_MODES_CLICK = 0x0C, + UP_RGB_MODES_BRIGHT = 0x0D, + UP_RGB_MODES_LUMA_CYCLE = 0x0E, + UP_RGB_MODES_ROTATE = 0x0F, + UP_RGB_MODES_HID_MENU = 0x10, + UP_RGB_MODES_NONE = 0x12, +}; + +class RGBController_OKSKeyboard : public RGBController +{ +public: + RGBController_OKSKeyboard(OKSKeyboardController* controller_ptr); + ~RGBController_OKSKeyboard(); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); + +private: + OKSKeyboardController* controller; +}; diff --git a/OpenRGB.pro b/OpenRGB.pro index fdd63af2e..5f0b17f72 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -603,6 +603,8 @@ HEADERS += Controllers/NZXTKrakenController/NZXTKrakenController.h \ Controllers/NZXTKrakenController/RGBController_NZXTKraken.h \ Controllers/OpenRazerController/OpenRazerDevices.h \ + Controllers/OKSController/OKSKeyboardController.h \ + Controllers/OKSController/RGBController_OKSKeyboard.h \ Controllers/PalitGPUController/PalitGPUController.h \ Controllers/PalitGPUController/RGBController_PalitGPU.h \ Controllers/PatriotViperController/PatriotViperController.h \ @@ -1270,6 +1272,9 @@ SOURCES += Controllers/NZXTKrakenController/NZXTKrakenController.cpp \ Controllers/NZXTKrakenController/NZXTKrakenControllerDetect.cpp \ Controllers/NZXTKrakenController/RGBController_NZXTKraken.cpp \ + Controllers/OKSController/OKSKeyboardController.cpp \ + Controllers/OKSController/OKSKeyboardControllerDetect.cpp \ + Controllers/OKSController/RGBController_OKSKeyboard.cpp \ Controllers/PalitGPUController/PalitGPUController.cpp \ Controllers/PalitGPUController/PalitGPUControllerDetect.cpp \ Controllers/PalitGPUController/RGBController_PalitGPU.cpp \