From 02f142eeb45220080a94ca8197aca0cb8bed983b Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub <39207213+o-julfikar@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:42:44 +0600 Subject: [PATCH 01/10] Init Bloody B820R --- .../A4TechBloodyB820RController/A4TechBloodyB820RController.cpp | 0 .../A4TechBloodyB820RController/A4TechBloodyB820RController.h | 0 .../A4TechBloodyB820RControllerDetect.cpp | 0 .../RGBController_A4TechBloodyB820R.cpp | 0 .../A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp create mode 100644 Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h create mode 100644 Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp create mode 100644 Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp create mode 100644 Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h new file mode 100644 index 000000000..e69de29bb diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp b/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h b/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h new file mode 100644 index 000000000..e69de29bb From 3ec36b4184da71f3cf26a32af0133804e8a1a2a2 Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub <39207213+o-julfikar@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:23:07 +0600 Subject: [PATCH 02/10] Init Bloody B820R --- .../A4TechBloodyB820RController.cpp | 211 ++++++++++++++++++ .../A4TechBloodyB820RController.h | 107 +++++++++ .../A4TechBloodyB820RControllerDetect.cpp | 34 +++ 3 files changed, 352 insertions(+) diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp index e69de29bb..b237ef82d 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp @@ -0,0 +1,211 @@ +/*-----------------------------------------*\ +| A4TechBloodyB820RController.cpp | +| | +| Driver for A4Tech Bloody B820R | +| lightning controller | +| | +| Zulfikar (o-julfikar) 3/28/2024 | +\*-----------------------------------------*/ + +#include "A4TechBloodyB820RController.h" + +#include +#include +#include + +using namespace std::chrono_literals; + +A4TechBloodyB820RController::A4TechBloodyB820RController(hid_device* dev_handle, const char* path) +{ + dev = dev_handle; + location = path; +} + +A4TechBloodyB820RController::~A4TechBloodyB820RController() +{ + hid_close(dev); +} + +std::string A4TechBloodyB820RController::GetDeviceLocation() +{ + return("HID " + location); +} + +std::string A4TechBloodyB820RController::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); +} + +void A4TechBloodyB820RController::SetLightingConfig + ( + unsigned char mode, + unsigned char random, + unsigned char brightness, + unsigned char speed, + unsigned char direction, + RGBColor* color_data + ) +{ + SendStartPacket(); + std::this_thread::sleep_for(5ms); + + SendLightingConfigPacket(mode, random, brightness, speed, direction, color_data); + std::this_thread::sleep_for(5ms); + + SendEndPacket(); + std::this_thread::sleep_for(10ms); +} + +void A4TechBloodyB820RController::SetCustom + ( + RGBColor* color_data + ) +{ + SendStartPacket(); + std::this_thread::sleep_for(5ms); + + SendCustomPacket(color_data); + std::this_thread::sleep_for(5ms); + + SendEndPacket(); + std::this_thread::sleep_for(5ms); +} + +/*-------------------------------------------------------------------------------------------------*\ +| Private packet sending functions. | +\*-------------------------------------------------------------------------------------------------*/ + +void A4TechBloodyB820RController::SendStartPacket() +{ + unsigned char buf[64]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up start packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x09; + buf[0x01] = 0x21; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, buf, sizeof(buf)); +} + +void A4TechBloodyB820RController::SendEndPacket() +{ + unsigned char buf[64]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up end packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x09; + buf[0x01] = 0x22; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, buf, sizeof(buf)); +} + +void A4TechBloodyB820RController::SendCustomPacket + ( + RGBColor* color_data + ) +{ + unsigned char buf[361]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up custom lighting packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x20; + + /*-----------------------------------------------------*\ + | Copy in color data | + \*-----------------------------------------------------*/ + for(unsigned int color_idx = 0; color_idx < 120; color_idx++) + { + buf[color_idx + 1] = RGBGetRValue(color_data[color_idx]); + buf[color_idx + 121] = RGBGetGValue(color_data[color_idx]); + buf[color_idx + 241] = RGBGetBValue(color_data[color_idx]); + } + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, sizeof(buf)); +} + +void A4TechBloodyB820RController::SendLightingConfigPacket + ( + unsigned char mode, + unsigned char random, + unsigned char brightness, + unsigned char speed, + unsigned char direction, + RGBColor* color_data + ) +{ + unsigned char buf[117]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up lighting configuration packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x14; + buf[0x01] = 0x01; + + buf[0x06] = mode; + + buf[0x07 + (9 * mode) + 0] = RGBGetRValue(color_data[0]); + buf[0x07 + (9 * mode) + 1] = RGBGetGValue(color_data[0]); + buf[0x07 + (9 * mode) + 2] = RGBGetBValue(color_data[0]); + buf[0x07 + (9 * mode) + 3] = random; + buf[0x07 + (9 * mode) + 4] = direction; + buf[0x07 + (9 * mode) + 5] = speed; + buf[0x07 + (9 * mode) + 6] = brightness; + + unsigned short checksum = 0x4A9E; + + for(unsigned int buf_idx = 0; buf_idx < 115; buf_idx++) + { + checksum += buf[buf_idx]; + } + + buf[115] = checksum & 0xFF; + buf[116] = checksum >> 8; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 117); +} diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h index e69de29bb..e38e1226a 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h @@ -0,0 +1,107 @@ +/*-----------------------------------------*\ +| A4TechBloodyB820RController.h | +| | +| Definitions and types for AOC keyboard | +| lighting controller | +| | +| Zulfikar (o-julfikar) 3/28/2024 | +\*-----------------------------------------*/ + +#include "RGBController.h" +#include +#include + +#pragma once + +/*-----------------------------------------*\ +| A4Tech Bloody B820R Keyboard Modes | +\*-----------------------------------------*/ +enum +{ + A4TechBloodyB820R_MODE_STATIC = 0x00, /* Static mode */ + A4TechBloodyB820R_MODE_BREATHING = 0x01, /* Breathing mode */ + A4TechBloodyB820R_MODE_REACT = 0x02, /* React mode */ + A4TechBloodyB820R_MODE_RIPPLE = 0x04, /* Ripple mode */ + A4TechBloodyB820R_MODE_RADAR = 0x05, /* Radar mode */ + A4TechBloodyB820R_MODE_FIREWORKS = 0x06, /* Fireworks mode */ + A4TechBloodyB820R_MODE_BLINK = 0x07, /* Blink mode */ + A4TechBloodyB820R_MODE_WAVE = 0x08, /* Wave mode */ + A4TechBloodyB820R_MODE_CUSTOM = 0x09, /* Custom mode */ + A4TechBloodyB820R_MODE_CONCENTRIC_CIRCLES = 0x0A, /* Concentric Circles mode */ + A4TechBloodyB820R_MODE_W_WAVE = 0x0B, /* W Wave mode */ +}; + +enum +{ + A4TechBloodyB820R_SPEED_SLOW = 0x03, /* Slowest speed */ + A4TechBloodyB820R_SPEED_MEDIUM = 0x02, /* Medium speed */ + A4TechBloodyB820R_SPEED_FAST = 0x01, /* Fastest speed */ +}; + +enum +{ + A4TechBloodyB820R_BRIGHTNESS_OFF = 0x00, /* Lowest brightness (off) */ + A4TechBloodyB820R_BRIGHTNESS_LOW = 0x01, /* Low brightness */ + A4TechBloodyB820R_BRIGHTNESS_MEDIUM = 0x02, /* Medium brightness */ + A4TechBloodyB820R_BRIGHTNESS_HIGH = 0x03, /* Highest brightness */ +}; + +enum +{ + A4TechBloodyB820R_SINGLE_COLOR = 0x00, /* Single color mode */ + A4TechBloodyB820R_RANDOM = 0x01, /* Random color mode */ +}; + +enum +{ + A4TechBloodyB820R_DIRECTION_CLOCKWISE = 0x00, /* Clockwise direction */ + A4TechBloodyB820R_DIRECTION_COUNTERCLOCKWISE = 0x01, /* Counter-clockwise direction */ +}; + + +class A4TechBloodyB820RController +{ +public: + A4TechBloodyB820RController(hid_device* dev_handle, const char* path); + ~A4TechBloodyB820RController(); + + std::string GetDeviceLocation(); + std::string GetSerialString(); + + void SetLightingConfig + ( + unsigned char mode, + unsigned char random, + unsigned char brightness, + unsigned char speed, + unsigned char direction, + RGBColor* color_data + ); + + void SetCustom + ( + RGBColor* color_data + ); + +private: + hid_device* dev; + std::string location; + + void SendStartPacket(); + void SendEndPacket(); + + void SendCustomPacket + ( + RGBColor* color_data + ); + + void SendLightingConfigPacket + ( + unsigned char mode, + unsigned char random, + unsigned char brightness, + unsigned char speed, + unsigned char direction, + RGBColor* color_data + ); +}; diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp index e69de29bb..588fc30ac 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp @@ -0,0 +1,34 @@ +#include "Detector.h" +#include "A4TechBloodyB820RController.h" +#include "RGBController.h" +#include "RGBController_A4TechBloodyB820R.h" + +/*-----------------------------------------------------*\ +| AOC Mousemat IDs | +\*-----------------------------------------------------*/ +#define B820R_VID 0x09DA +#define B820R_PID 0xFA10 + +/******************************************************************************************\ +* * +* DetectA4TechBloodyB820RControllers * +* * +* Tests the USB address to see if an AOC Keyboard controller exists there. * +* * +\******************************************************************************************/ + +void DetectA4TechBloodyB820R(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + A4TechBloodyB820RController* controller = new A4TechBloodyB820RController(dev, info->path); + RGBController_A4TechBloodyB820R* rgb_controller = new RGBController_A4TechBloodyB820R(controller); + rgb_controller->name = name; + + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +} + +REGISTER_HID_DETECTOR_PU("A4Tech Bloody B820R", DetectA4TechBloodyB820R, B820R_VID, B820R_PID, 0xFF19, 0xFF19); From fe6b7037ba0db50d4fe1a0b2da985fa1240c1a3a Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub <39207213+o-julfikar@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:34:22 +0600 Subject: [PATCH 03/10] Updated files for Bloody B820R --- .../A4TechBloodyB820RController.cpp | 263 ++++++------------ .../A4TechBloodyB820RController.h | 108 ++----- .../A4TechBloodyB820RControllerDetect.cpp | 14 +- .../RGBController_A4TechBloodyB820R.cpp | 235 ++++++++++++++++ .../RGBController_A4TechBloodyB820R.h | 33 +++ 5 files changed, 383 insertions(+), 270 deletions(-) diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp index b237ef82d..e96b67d4c 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp @@ -1,211 +1,110 @@ -/*-----------------------------------------*\ -| A4TechBloodyB820RController.cpp | -| | -| Driver for A4Tech Bloody B820R | -| lightning controller | -| | -| Zulfikar (o-julfikar) 3/28/2024 | -\*-----------------------------------------*/ - +/*-------------------------------------------------------------------*\ +| DarkProjectKeyboardController.cpp | +| | +| Driver for DarkProjectKeyboard USB Controller | +| | +| Chris M (DrNo) 8 Apr 2022 | +| | +\*-------------------------------------------------------------------*/ + +#include "LogManager.h" #include "A4TechBloodyB820RController.h" -#include -#include -#include +static uint8_t packet_map[88] = + { +/*00 ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 */ + 5, 11, 17, 23, 29, 35, 41, 47, 53, 59, -using namespace std::chrono_literals; +/*10 F10 F11 F12 PRT SLK PBK ` 1 2 3 */ + 65, 71, 77, 83, 89, 95, 0, 6, 12, 18, -A4TechBloodyB820RController::A4TechBloodyB820RController(hid_device* dev_handle, const char* path) -{ - dev = dev_handle; - location = path; -} +/*20 4 5 6 7 8 9 0 - = BSP */ + 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, -A4TechBloodyB820RController::~A4TechBloodyB820RController() -{ - hid_close(dev); -} +/*30 INS HME PUP TAB Q W E R T Y */ + 84, 90, 96, 1, 7, 13, 19, 25, 31, 37, -std::string A4TechBloodyB820RController::GetDeviceLocation() -{ - return("HID " + location); -} +/*40 U I O P [ ] \ DEL END PDN */ + 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, -std::string A4TechBloodyB820RController::GetSerialString() -{ - wchar_t serial_string[128]; - int ret = hid_get_serial_number_string(dev, serial_string, 128); +/*50 CAP A S D F G H J K L */ + 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, - if(ret != 0) - { - return(""); - } +/*60 ; ' ENT LSH Z X C V B N */ + 62, 68, 80, 3, 15, 21, 27, 33, 39, 45, - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); +/*70 M , . / RSH UP LCTL LWIN LALT SPC */ + 51, 57, 63, 69, 81, 93, 4, 10, 16, 34, - return(return_string); -} +/*80 RALT RFNC MENU RCTL LFT DWN RGT */ + 52, 58, 64, 76, 88, 94, 100 -void A4TechBloodyB820RController::SetLightingConfig - ( - unsigned char mode, - unsigned char random, - unsigned char brightness, - unsigned char speed, - unsigned char direction, - RGBColor* color_data - ) -{ - SendStartPacket(); - std::this_thread::sleep_for(5ms); +/* Missing Indexes 9, 22, 28, 40, 46, 70, 74, 75, 82, 86, 87, 92, 98, 99, 101 */ + }; - SendLightingConfigPacket(mode, random, brightness, speed, direction, color_data); - std::this_thread::sleep_for(5ms); +A4TechBloodyB820RController::A4TechBloodyB820RController(hid_device* dev_handle, const char* path) +{ + dev = dev_handle; + location = path; +} - SendEndPacket(); - std::this_thread::sleep_for(10ms); +A4TechBloodyB820RController::~A4TechBloodyB820RController() +{ + hid_close(dev); } -void A4TechBloodyB820RController::SetCustom - ( - RGBColor* color_data - ) +std::string A4TechBloodyB820RController::GetDeviceName() { - SendStartPacket(); - std::this_thread::sleep_for(5ms); + const int szTemp = HID_MAX_STR; + wchar_t tmpName[szTemp]; - SendCustomPacket(color_data); - std::this_thread::sleep_for(5ms); + hid_get_manufacturer_string(dev, tmpName, szTemp); + std::wstring wName = std::wstring(tmpName); + std::string name = std::string(wName.begin(), wName.end()); - SendEndPacket(); - std::this_thread::sleep_for(5ms); + return name; } -/*-------------------------------------------------------------------------------------------------*\ -| Private packet sending functions. | -\*-------------------------------------------------------------------------------------------------*/ - -void A4TechBloodyB820RController::SendStartPacket() +std::string A4TechBloodyB820RController::GetSerial() { - unsigned char buf[64]; - - /*-----------------------------------------------------*\ - | Zero out buffer | - \*-----------------------------------------------------*/ - memset(buf, 0x00, sizeof(buf)); - - /*-----------------------------------------------------*\ - | Set up start packet | - \*-----------------------------------------------------*/ - buf[0x00] = 0x09; - buf[0x01] = 0x21; - - /*-----------------------------------------------------*\ - | Send packet | - \*-----------------------------------------------------*/ - hid_write(dev, buf, sizeof(buf)); -} + const int szTemp = HID_MAX_STR; + wchar_t tmpName[szTemp]; -void A4TechBloodyB820RController::SendEndPacket() -{ - unsigned char buf[64]; - - /*-----------------------------------------------------*\ - | Zero out buffer | - \*-----------------------------------------------------*/ - memset(buf, 0x00, sizeof(buf)); - - /*-----------------------------------------------------*\ - | Set up end packet | - \*-----------------------------------------------------*/ - buf[0x00] = 0x09; - buf[0x01] = 0x22; - - /*-----------------------------------------------------*\ - | Send packet | - \*-----------------------------------------------------*/ - hid_write(dev, buf, sizeof(buf)); + hid_get_serial_number_string(dev, tmpName, szTemp); + std::wstring wName = std::wstring(tmpName); + std::string serial = std::string(wName.begin(), wName.end()); + + return serial; } -void A4TechBloodyB820RController::SendCustomPacket - ( - RGBColor* color_data - ) +std::string A4TechBloodyB820RController::GetLocation() { - unsigned char buf[361]; - - /*-----------------------------------------------------*\ - | Zero out buffer | - \*-----------------------------------------------------*/ - memset(buf, 0x00, sizeof(buf)); - - /*-----------------------------------------------------*\ - | Set up custom lighting packet | - \*-----------------------------------------------------*/ - buf[0x00] = 0x20; - - /*-----------------------------------------------------*\ - | Copy in color data | - \*-----------------------------------------------------*/ - for(unsigned int color_idx = 0; color_idx < 120; color_idx++) - { - buf[color_idx + 1] = RGBGetRValue(color_data[color_idx]); - buf[color_idx + 121] = RGBGetGValue(color_data[color_idx]); - buf[color_idx + 241] = RGBGetBValue(color_data[color_idx]); - } - - /*-----------------------------------------------------*\ - | Send packet | - \*-----------------------------------------------------*/ - hid_send_feature_report(dev, buf, sizeof(buf)); + return("HID: " + location); } -void A4TechBloodyB820RController::SendLightingConfigPacket - ( - unsigned char mode, - unsigned char random, - unsigned char brightness, - unsigned char speed, - unsigned char direction, - RGBColor* color_data - ) +void A4TechBloodyB820RController::SetLedsDirect(std::vector colors) { - unsigned char buf[117]; - - /*-----------------------------------------------------*\ - | Zero out buffer | - \*-----------------------------------------------------*/ - memset(buf, 0x00, sizeof(buf)); - - /*-----------------------------------------------------*\ - | Set up lighting configuration packet | - \*-----------------------------------------------------*/ - buf[0x00] = 0x14; - buf[0x01] = 0x01; - - buf[0x06] = mode; - - buf[0x07 + (9 * mode) + 0] = RGBGetRValue(color_data[0]); - buf[0x07 + (9 * mode) + 1] = RGBGetGValue(color_data[0]); - buf[0x07 + (9 * mode) + 2] = RGBGetBValue(color_data[0]); - buf[0x07 + (9 * mode) + 3] = random; - buf[0x07 + (9 * mode) + 4] = direction; - buf[0x07 + (9 * mode) + 5] = speed; - buf[0x07 + (9 * mode) + 6] = brightness; - - unsigned short checksum = 0x4A9E; - - for(unsigned int buf_idx = 0; buf_idx < 115; buf_idx++) - { - checksum += buf[buf_idx]; - } - - buf[115] = checksum & 0xFF; - buf[116] = checksum >> 8; - - /*-----------------------------------------------------*\ - | Send packet | - \*-----------------------------------------------------*/ - hid_send_feature_report(dev, buf, 117); + uint8_t keyBuffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06 }; + + uint8_t RBuffer[BLOODY_B820R_PACKET_SIZE] = { }; + uint8_t GBuffer[BLOODY_B820R_PACKET_SIZE] = { }; + uint8_t BBuffer[BLOODY_B820R_PACKET_SIZE] = { }; + + /*-----------------------------------------------------------------*\ + | Set up Direct packet | + | packet_map is the index of the Key from full_matrix_map and | + | the value is the position in the direct packet buffer | + \*-----------------------------------------------------------------*/ +// for(size_t i = 0; i < colors.size(); i++) +// { +// RGBColor key = colors[i]; +// uint16_t offset = packet_map[i]; +// +// RGbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetRValue(key); +// RGbuffer[DARKPROJECTKEYBOARD_GREEN_BYTE + offset] = RGBGetGValue(key); +// BAbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetBValue(key); +// } + + hid_write(dev, keyBuffer, BLOODY_B820R_PACKET_SIZE); } + diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h index e38e1226a..8f8433f02 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h @@ -1,107 +1,49 @@ -/*-----------------------------------------*\ -| A4TechBloodyB820RController.h | -| | -| Definitions and types for AOC keyboard | -| lighting controller | -| | -| Zulfikar (o-julfikar) 3/28/2024 | -\*-----------------------------------------*/ +/*-------------------------------------------------------------------*\ +| A4TechBloodyB820RController.h | +| | +| Driver for DarkProjectKeyboard USB Controller | +| | +| Zulfikar (o-julfikar) 8 Apr 2022 | +| | +\*-------------------------------------------------------------------*/ -#include "RGBController.h" -#include #include +#include +#include "RGBController.h" #pragma once -/*-----------------------------------------*\ -| A4Tech Bloody B820R Keyboard Modes | -\*-----------------------------------------*/ -enum -{ - A4TechBloodyB820R_MODE_STATIC = 0x00, /* Static mode */ - A4TechBloodyB820R_MODE_BREATHING = 0x01, /* Breathing mode */ - A4TechBloodyB820R_MODE_REACT = 0x02, /* React mode */ - A4TechBloodyB820R_MODE_RIPPLE = 0x04, /* Ripple mode */ - A4TechBloodyB820R_MODE_RADAR = 0x05, /* Radar mode */ - A4TechBloodyB820R_MODE_FIREWORKS = 0x06, /* Fireworks mode */ - A4TechBloodyB820R_MODE_BLINK = 0x07, /* Blink mode */ - A4TechBloodyB820R_MODE_WAVE = 0x08, /* Wave mode */ - A4TechBloodyB820R_MODE_CUSTOM = 0x09, /* Custom mode */ - A4TechBloodyB820R_MODE_CONCENTRIC_CIRCLES = 0x0A, /* Concentric Circles mode */ - A4TechBloodyB820R_MODE_W_WAVE = 0x0B, /* W Wave mode */ -}; - -enum -{ - A4TechBloodyB820R_SPEED_SLOW = 0x03, /* Slowest speed */ - A4TechBloodyB820R_SPEED_MEDIUM = 0x02, /* Medium speed */ - A4TechBloodyB820R_SPEED_FAST = 0x01, /* Fastest speed */ -}; +#define NA 0xFFFFFFFF +#define HID_MAX_STR 255 -enum -{ - A4TechBloodyB820R_BRIGHTNESS_OFF = 0x00, /* Lowest brightness (off) */ - A4TechBloodyB820R_BRIGHTNESS_LOW = 0x01, /* Low brightness */ - A4TechBloodyB820R_BRIGHTNESS_MEDIUM = 0x02, /* Medium brightness */ - A4TechBloodyB820R_BRIGHTNESS_HIGH = 0x03, /* Highest brightness */ -}; +#define BLOODY_B820R_PACKET_SIZE 64 +#define BLOODY_B820R_TKL_KEYCOUNT 87 enum { - A4TechBloodyB820R_SINGLE_COLOR = 0x00, /* Single color mode */ - A4TechBloodyB820R_RANDOM = 0x01, /* Random color mode */ + BLOODY_B820R_MODE_DIRECT = 0x01, //Direct Led Control - Independently set LEDs in zone }; enum { - A4TechBloodyB820R_DIRECTION_CLOCKWISE = 0x00, /* Clockwise direction */ - A4TechBloodyB820R_DIRECTION_COUNTERCLOCKWISE = 0x01, /* Counter-clockwise direction */ + BLOODY_B820R_REPORT_BYTE = 1, + BLOODY_B820R_COMMAND_BYTE = 2, + BLOODY_B820R_RED_BLUE_BYTE = 5, + BLOODY_B820R_GREEN_BYTE = 107 }; - class A4TechBloodyB820RController { public: A4TechBloodyB820RController(hid_device* dev_handle, const char* path); ~A4TechBloodyB820RController(); - std::string GetDeviceLocation(); - std::string GetSerialString(); - - void SetLightingConfig - ( - unsigned char mode, - unsigned char random, - unsigned char brightness, - unsigned char speed, - unsigned char direction, - RGBColor* color_data - ); - - void SetCustom - ( - RGBColor* color_data - ); + std::string GetDeviceName(); + std::string GetSerial(); + std::string GetLocation(); + void SetLedsDirect(std::vector colors); private: - hid_device* dev; - std::string location; - - void SendStartPacket(); - void SendEndPacket(); - - void SendCustomPacket - ( - RGBColor* color_data - ); - - void SendLightingConfigPacket - ( - unsigned char mode, - unsigned char random, - unsigned char brightness, - unsigned char speed, - unsigned char direction, - RGBColor* color_data - ); + std::string location; + hid_device* dev; }; diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp index 588fc30ac..7a11d7fe1 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp @@ -3,10 +3,14 @@ #include "RGBController.h" #include "RGBController_A4TechBloodyB820R.h" -/*-----------------------------------------------------*\ -| AOC Mousemat IDs | -\*-----------------------------------------------------*/ -#define B820R_VID 0x09DA +/*---------------------------------------------------------*\ +| A4Tech vendor ID | +\*---------------------------------------------------------*/ +#define A4Tech_VID 0x09DA + +/*---------------------------------------------------------*\ +| Bloody B820R product ID | +\*---------------------------------------------------------*/ #define B820R_PID 0xFA10 /******************************************************************************************\ @@ -31,4 +35,4 @@ void DetectA4TechBloodyB820R(hid_device_info* info, const std::string& name) } } -REGISTER_HID_DETECTOR_PU("A4Tech Bloody B820R", DetectA4TechBloodyB820R, B820R_VID, B820R_PID, 0xFF19, 0xFF19); +REGISTER_HID_DETECTOR_PU("A4Tech Bloody B820R", DetectA4TechBloodyB820R, A4Tech_VID, B820R_PID, 0xFF19, 0xFF19); diff --git a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp b/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp index e69de29bb..d1a533969 100644 --- a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp +++ b/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp @@ -0,0 +1,235 @@ +/*-------------------------------------------------------------------*\ +| RGBController_DarkProjectKeyboard.cpp | +| | +| Driver for DarkProjectKeyboard USB Controller | +| | +| Zulfikar (o-julfikar) 28 Mar 2024 | +| | +\*-------------------------------------------------------------------*/ + +#include "RGBControllerKeyNames.h" +#include "RGBController_A4TechBloodyB820R.h" + +static unsigned int matrix_map[6][18] = + { + { 0, NA, 1, 2, 3, 4, 5, 6, 7, 8, NA, 9, 10, 11, 12, 13, 14, 15 }, + { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, NA, 30, 31, 32 }, + { 33, NA, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 }, + { 50, NA, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NA, 62, NA, NA, NA }, + { 63, NA, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, NA, 74, NA, NA, 75, NA }, + { 76, 77, 78, NA, NA, NA, 79, NA, NA, NA, 80, 81, NA, 82, 83, 84, 85, 86 } + }; + +static const char *led_names[] = + { + KEY_EN_ESCAPE, //00 + 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, //10 + KEY_EN_F11, + KEY_EN_F12, + KEY_EN_PRINT_SCREEN, + KEY_EN_SCROLL_LOCK, + KEY_EN_PAUSE_BREAK, + + KEY_EN_BACK_TICK, + KEY_EN_1, + KEY_EN_2, + KEY_EN_3, + KEY_EN_4, //20 + 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, //30 + KEY_EN_HOME, + KEY_EN_PAGE_UP, + + KEY_EN_TAB, + KEY_EN_Q, + KEY_EN_W, + KEY_EN_E, + KEY_EN_R, + KEY_EN_T, + KEY_EN_Y, + KEY_EN_U, //40 + 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_CAPS_LOCK, //50 + 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, //60 + KEY_EN_QUOTE, + KEY_EN_ANSI_ENTER, + + KEY_EN_LEFT_SHIFT, + KEY_EN_Z, + KEY_EN_X, + KEY_EN_C, + KEY_EN_V, + KEY_EN_B, + KEY_EN_N, + KEY_EN_M, //70 + KEY_EN_COMMA, + KEY_EN_PERIOD, + KEY_EN_FORWARD_SLASH, + KEY_EN_RIGHT_SHIFT, + KEY_EN_UP_ARROW, + + KEY_EN_LEFT_CONTROL, + KEY_EN_LEFT_WINDOWS, + KEY_EN_LEFT_ALT, + KEY_EN_SPACE, + KEY_EN_RIGHT_ALT, //80 + KEY_EN_RIGHT_FUNCTION, + KEY_EN_MENU, + KEY_EN_RIGHT_CONTROL, + KEY_EN_LEFT_ARROW, + KEY_EN_DOWN_ARROW, + KEY_EN_RIGHT_ARROW + }; + +/**------------------------------------------------------------------*\ + @name A4Tech Bloody B820R + @category Keyboard + @type USB + @save :x: + @direct :white_check_mark: + @effects :x: + @detectors A4TechBloodyB820RControllerDetect + @comment The A4Tech Bloody B820R keyboard controller currently + supports the full size KD3B Version 2 (ANSI layout). +\*-------------------------------------------------------------------*/ + +RGBController_A4TechBloodyB820R::RGBController_A4TechBloodyB820R(A4TechBloodyB820RController *controller_ptr) +{ + controller = controller_ptr; + + name = "A4 Tech Bloody B820R"; + vendor = "A4Tech"; + type = DEVICE_TYPE_KEYBOARD; + description = controller->GetDeviceName(); + serial = controller->GetSerial(); + location = controller->GetLocation(); + + mode Direct; + Direct.name = "Direct"; + Direct.value = BLOODY_B820R_MODE_DIRECT; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Direct); + + SetupZones(); +} + +RGBController_A4TechBloodyB820R::~RGBController_A4TechBloodyB820R() +{ + delete controller; +} + +void RGBController_A4TechBloodyB820R::SetupZones() +{ + /*-------------------------------------------------*\ + | Create the Keyboard zone and add the matrix map | + \*-------------------------------------------------*/ + zone KB_zone; + KB_zone.name = ZONE_EN_KEYBOARD; + KB_zone.type = ZONE_TYPE_MATRIX; + KB_zone.leds_min = BLOODY_B820R_TKL_KEYCOUNT; + KB_zone.leds_max = BLOODY_B820R_TKL_KEYCOUNT; + KB_zone.leds_count = BLOODY_B820R_TKL_KEYCOUNT; + + KB_zone.matrix_map = new matrix_map_type; + KB_zone.matrix_map->height = 6; + KB_zone.matrix_map->width = 18; + KB_zone.matrix_map->map = (unsigned int *)&matrix_map; + zones.push_back(KB_zone); + + /*-------------------------------------------------*\ + | Clear any existing color/LED configuration | + \*-------------------------------------------------*/ + leds.clear(); + colors.clear(); + + /*---------------------------------------------------------*\ + | Set up zones | + \*---------------------------------------------------------*/ + for(std::size_t zone_index = 0; zone_index < zones.size(); zone_index++) + { + for(unsigned int led_index = 0; led_index < zones[zone_index].leds_count; led_index++) + { + led new_led; + new_led.name = led_names[led_index]; + new_led.value = led_index; + leds.push_back(new_led); + } + } + + SetupColors(); +} + +void RGBController_A4TechBloodyB820R::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + + +void RGBController_A4TechBloodyB820R::DeviceUpdateLEDs() +{ + controller->SetLedsDirect(colors); +} + +void RGBController_A4TechBloodyB820R::UpdateZoneLEDs(int zone) +{ + std::vector colour; + for(size_t i = 0; i < zones[zone].leds_count; i++) + { + colour.push_back(zones[zone].colors[i]); + } + + controller->SetLedsDirect(colour); +} + +void RGBController_A4TechBloodyB820R::UpdateSingleLED(int led) +{ + std::vector colour; + colour.push_back(colors[led]); + + controller->SetLedsDirect(colour); +} + +void RGBController_A4TechBloodyB820R::DeviceUpdateMode() +{ + /*---------------------------------------------------------*\ + | This device only supports `Direct` mode | + \*---------------------------------------------------------*/ +} diff --git a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h b/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h index e69de29bb..0d245c65e 100644 --- a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h +++ b/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h @@ -0,0 +1,33 @@ +/*-------------------------------------------------------------------*\ +| RGBController_A4TechBloodyB820R.h | +| | +| Driver for A4TechBloodyB820R Keyboard Controller | +| | +| Zulfikar (o-julfikar) 28 Mar 2024 | +| | +\*-------------------------------------------------------------------*/ + +#pragma once +#include "LogManager.h" +#include "RGBController.h" +#include "A4TechBloodyB820RController.h" +#include + +class RGBController_A4TechBloodyB820R : public RGBController +{ +public: + RGBController_A4TechBloodyB820R(A4TechBloodyB820RController* controller_ptr); + ~RGBController_A4TechBloodyB820R(); + + void SetupZones(); + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void DeviceUpdateMode(); + +private: + A4TechBloodyB820RController* controller; +}; From 6558e196387eaa657fe249068e4bb0d5a9f5130f Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub <39207213+o-julfikar@users.noreply.github.com> Date: Fri, 29 Mar 2024 16:47:36 +0600 Subject: [PATCH 04/10] Added key map for Bloody B820R --- .../A4TechBloodyB820RController.cpp | 94 +++++++++++++------ 1 file changed, 64 insertions(+), 30 deletions(-) diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp index e96b67d4c..7366ae2cb 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp @@ -10,34 +10,53 @@ #include "LogManager.h" #include "A4TechBloodyB820RController.h" -static uint8_t packet_map[88] = +static uint8_t packet_map1[104] = { -/*00 ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 */ - 5, 11, 17, 23, 29, 35, 41, 47, 53, 59, +/*00 ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 */ + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, -/*10 F10 F11 F12 PRT SLK PBK ` 1 2 3 */ - 65, 71, 77, 83, 89, 95, 0, 6, 12, 18, +/*00 PS SL PB */ + 19, 20, 21, -/*20 4 5 6 7 8 9 0 - = BSP */ - 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, -/*30 INS HME PUP TAB Q W E R T Y */ - 84, 90, 96, 1, 7, 13, 19, 25, 31, 37, +/*10 ` 1 2 3 4 5 6 7 8 9 0 - = */ + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, -/*40 U I O P [ ] \ DEL END PDN */ - 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, +/*10 BCK INS HM PU NUM [N /] [N *] [N -] */ + 35, 36, 37, 38, 39, 40, 41, 42, -/*50 CAP A S D F G H J K L */ - 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, -/*60 ; ' ENT LSH Z X C V B N */ - 62, 68, 80, 3, 15, 21, 27, 33, 39, 45, -/*70 M , . / RSH UP LCTL LWIN LALT SPC */ - 51, 57, 63, 69, 81, 93, 4, 10, 16, 34, +/*20 TAB Q W E R T Y U I O P [ ] */ + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, -/*80 RALT RFNC MENU RCTL LFT DWN RGT */ - 52, 58, 64, 76, 88, 94, 100 +/*20 \ DEL END PD [N 7] [N 8] [N 9] [N +] */ + 56, 57, 58, 59, 60, 61, 62, 63 + } + +static uint16_t packet_map2[58] = + { + +/*30 LCAPS A S D F G H J K L ; ' BRK */ + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + +/*30 [N 4] [N 5] [N 6] */ + 19, 20, 21, + + + + +/*40 LSHIFT Z X C V B N M , . / RSHIFT */ + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + +/*40 UP [N 1] [N 2] [N 3] [N BRK] */ + 34, 35, 36, 37, 38, + + + + +/*50 LCTRL LWIN LALT SPC RALT RFN RCNTXT RCTRL LEFT DOWN RIGHT [N 0] [N .] */ + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, /* Missing Indexes 9, 22, 28, 40, 46, 70, 74, 75, 82, 86, 87, 92, 98, 99, 101 */ }; @@ -86,25 +105,40 @@ void A4TechBloodyB820RController::SetLedsDirect(std::vector colors) { uint8_t keyBuffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06 }; - uint8_t RBuffer[BLOODY_B820R_PACKET_SIZE] = { }; - uint8_t GBuffer[BLOODY_B820R_PACKET_SIZE] = { }; - uint8_t BBuffer[BLOODY_B820R_PACKET_SIZE] = { }; + uint8_t R1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x07, 0x00, 0x00 }; + uint8_t R2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x08, 0x00, 0x00 }; + uint8_t G1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x09, 0x00, 0x00 }; + uint8_t G2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0a, 0x00, 0x00 }; + uint8_t B1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0b, 0x00, 0x00 }; + uint8_t B2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0c, 0x00, 0x00 }; /*-----------------------------------------------------------------*\ | Set up Direct packet | | packet_map is the index of the Key from full_matrix_map and | | the value is the position in the direct packet buffer | \*-----------------------------------------------------------------*/ -// for(size_t i = 0; i < colors.size(); i++) -// { -// RGBColor key = colors[i]; -// uint16_t offset = packet_map[i]; -// + for(size_t i = 0; i < colors.size(); i++) + { + RGBColor key = colors[i]; + uint16_t offset = packet_map[i]; + + R1Buffer[offset] = RGBGetRValue(key); + R2Buffer[offset] = RGBGetRValue(key); + G1Buffer[offset] = RGBGetGValue(key); + G2Buffer[offset] = RGBGetGValue(key); + B1Buffer[offset] = RGBGetBValue(key); + B2Buffer[offset] = RGBGetBValue(key); + // RGbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetRValue(key); // RGbuffer[DARKPROJECTKEYBOARD_GREEN_BYTE + offset] = RGBGetGValue(key); // BAbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetBValue(key); -// } - - hid_write(dev, keyBuffer, BLOODY_B820R_PACKET_SIZE); + } + + hid_write(dev, R1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_write(dev, R2Buffer, BLOODY_B820R_PACKET_SIZE); + hid_write(dev, G1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_write(dev, G2Buffer, BLOODY_B820R_PACKET_SIZE); + hid_write(dev, B1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_write(dev, B2Buffer, BLOODY_B820R_PACKET_SIZE); } From 67d653050bbbdc56028b4a83730c83184e4ccda0 Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub Date: Sat, 30 Mar 2024 12:34:26 +0600 Subject: [PATCH 05/10] Added Functional Bloody B820R Detect --- .idea/.gitignore | 8 + .idea/OpenRGB.iml | 8 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .../A4TechBloodyB820RController.cpp | 365 +++++++++++++++--- .../A4TechBloodyB820RController.h | 8 +- .../A4TechBloodyB820RControllerDetect.cpp | 6 +- .../RGBController_A4TechBloodyB820R.cpp | 35 +- 8 files changed, 373 insertions(+), 71 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/OpenRGB.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/OpenRGB.iml b/.idea/OpenRGB.iml new file mode 100644 index 000000000..bc2cd8740 --- /dev/null +++ b/.idea/OpenRGB.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..16eb6d542 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp index 7366ae2cb..1d5ce0027 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp @@ -9,62 +9,193 @@ #include "LogManager.h" #include "A4TechBloodyB820RController.h" +#include +#include +#include +#include "fstream" + +static uint8_t map_layout1[58][2] = { + {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}, + {63} +}; + +static uint8_t map_layout2[58][2] = { + {6}, + {7}, + {8}, + {9}, + {10}, + {11}, + {12}, + {13}, + {14}, + {15}, + {16}, + {17}, + {18}, + {19}, + {20}, + {21}, + {22, 55}, + {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}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} +}; + +//static uint8_t packet_map1[104] = +// { +///*00 ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 */ +// 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, +// +///*00 PS SL PB */ +// 19, 20, 21, +// +// +///*10 ` 1 2 3 4 5 6 7 8 9 0 - = */ +// 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, +// +///*10 BCK INS HM PU NUM [N /] [N *] [N -] */ +// 35, 36, 37, 38, 39, 40, 41, 42, +// +// +// +///*20 TAB Q W E R T Y U I O P [ ] */ +// 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, +// +///*20 \ DEL END PD [N 7] [N 8] [N 9] [N +] */ +// 56, 57, 58, 59, 60, 61, 62, 63 +// }; +// +//static uint16_t packet_map2[58] = +// { +// +///*30 LCAPS A S D F G H J K L ; ' BRK */ +// 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, +// +///*30 [N 4] [N 5] [N 6] */ +// 19, 20, 21, +// +// +// +// +///*40 LSHIFT Z X C V B N M , . / RSHIFT */ +// 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, +// +///*40 UP [N 1] [N 2] [N 3] [N BRK] */ +// 34, 35, 36, 37, 38, +// +// +// +// +///*50 LCTRL LWIN LALT SPC RALT RFN RCNTXT RCTRL LEFT DOWN RIGHT [N 0] [N .] */ +// 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, +// +///* Missing Indexes 9, 22, 28, 40, 46, 70, 74, 75, 82, 86, 87, 92, 98, 99, 101 */ +// }; -static uint8_t packet_map1[104] = - { -/*00 ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 */ - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, -/*00 PS SL PB */ - 19, 20, 21, -/*10 ` 1 2 3 4 5 6 7 8 9 0 - = */ - 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - -/*10 BCK INS HM PU NUM [N /] [N *] [N -] */ - 35, 36, 37, 38, 39, 40, 41, 42, - - - -/*20 TAB Q W E R T Y U I O P [ ] */ - 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - -/*20 \ DEL END PD [N 7] [N 8] [N 9] [N +] */ - 56, 57, 58, 59, 60, 61, 62, 63 - } - -static uint16_t packet_map2[58] = - { - -/*30 LCAPS A S D F G H J K L ; ' BRK */ - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - -/*30 [N 4] [N 5] [N 6] */ - 19, 20, 21, - - - - -/*40 LSHIFT Z X C V B N M , . / RSHIFT */ - 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, - -/*40 UP [N 1] [N 2] [N 3] [N BRK] */ - 34, 35, 36, 37, 38, - - - - -/*50 LCTRL LWIN LALT SPC RALT RFN RCNTXT RCTRL LEFT DOWN RIGHT [N 0] [N .] */ - 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, - -/* Missing Indexes 9, 22, 28, 40, 46, 70, 74, 75, 82, 86, 87, 92, 98, 99, 101 */ - }; - A4TechBloodyB820RController::A4TechBloodyB820RController(hid_device* dev_handle, const char* path) { dev = dev_handle; location = path; + + InitDevice(); } A4TechBloodyB820RController::~A4TechBloodyB820RController() @@ -101,9 +232,31 @@ std::string A4TechBloodyB820RController::GetLocation() return("HID: " + location); } +std::string hexArrayToString(const uint8_t* arr, size_t size) { + std::stringstream ss; + ss << std::hex << std::setfill('0'); + for (size_t i = 0; i < size; ++i) { + ss << std::setw(2) << static_cast(arr[i]); +// ss << std::hex << static_cast(arr[i]); + } + return ss.str(); +} + +void A4TechBloodyB820RController::InitDevice() +{ + uint8_t buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00 }; + + hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); +// hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); + + buffer[BLOODY_B820R_MODE_BYTE] = 0; + buffer[BLOODY_B820R_DATA_BYTE] = 1; + + hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); +} + void A4TechBloodyB820RController::SetLedsDirect(std::vector colors) { - uint8_t keyBuffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06 }; uint8_t R1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x07, 0x00, 0x00 }; uint8_t R2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x08, 0x00, 0x00 }; @@ -117,28 +270,114 @@ void A4TechBloodyB820RController::SetLedsDirect(std::vector colors) | packet_map is the index of the Key from full_matrix_map and | | the value is the position in the direct packet buffer | \*-----------------------------------------------------------------*/ + + +// std::ofstream outputFile("example.txt"); +// if (outputFile.is_open()) { +// outputFile << colors.size(); +// outputFile.close(); +// } + for(size_t i = 0; i < colors.size(); i++) { RGBColor key = colors[i]; - uint16_t offset = packet_map[i]; - R1Buffer[offset] = RGBGetRValue(key); - R2Buffer[offset] = RGBGetRValue(key); - G1Buffer[offset] = RGBGetGValue(key); - G2Buffer[offset] = RGBGetGValue(key); - B1Buffer[offset] = RGBGetBValue(key); - B2Buffer[offset] = RGBGetBValue(key); + + size_t layout1_length = sizeof(map_layout1) / sizeof(map_layout1[0]); + + if (i < layout1_length) { + for(auto j : map_layout1[i]) { + if (j != 0) { + R1Buffer[j] = RGBGetRValue(key); + G1Buffer[j] = RGBGetGValue(key); + B1Buffer[j] = RGBGetBValue(key); + } + } + } else { + for(auto j : map_layout2[i - layout1_length]) { + if (j != 0) { + R2Buffer[j] = RGBGetRValue(key); + G2Buffer[j] = RGBGetGValue(key); + B2Buffer[j] = RGBGetBValue(key); + } + } + } +// uint16_t offset = packet_map1[i]; + +// uint8_t[2] offset1 = map_layout1[i]; + +// for(auto j : map_layout1[i]) { +// R1Buffer[j] = RGBGetRValue(key); +// G1Buffer[j] = RGBGetGValue(key); +// B1Buffer[j] = RGBGetBValue(key); +// } + +// uint8_t[2] offset2 = map_layout2[i]; + +// for(auto j : map_layout2[i]) { +// R2Buffer[j] = RGBGetRValue(key); +// G2Buffer[j] = RGBGetGValue(key); +// B2Buffer[j] = RGBGetBValue(key); +// } + + +// if (i < colors.size() / 2) { +// R1Buffer[offset] = RGBGetRValue(key); +// G1Buffer[offset] = RGBGetGValue(key); +// B1Buffer[offset] = RGBGetBValue(key); +// } else { +// R2Buffer[offset] = RGBGetRValue(key); +// G2Buffer[offset] = RGBGetGValue(key); +// B2Buffer[offset] = RGBGetBValue(key); +// } + +// R1Buffer[offset] = RGBGetRValue(key); +// R2Buffer[offset] = RGBGetRValue(key); +// G1Buffer[offset] = RGBGetGValue(key); +// G2Buffer[offset] = RGBGetGValue(key); +// B1Buffer[offset] = RGBGetBValue(key); +// B2Buffer[offset] = RGBGetBValue(key); // RGbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetRValue(key); // RGbuffer[DARKPROJECTKEYBOARD_GREEN_BYTE + offset] = RGBGetGValue(key); // BAbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetBValue(key); } - hid_write(dev, R1Buffer, BLOODY_B820R_PACKET_SIZE); - hid_write(dev, R2Buffer, BLOODY_B820R_PACKET_SIZE); - hid_write(dev, G1Buffer, BLOODY_B820R_PACKET_SIZE); - hid_write(dev, G2Buffer, BLOODY_B820R_PACKET_SIZE); - hid_write(dev, B1Buffer, BLOODY_B820R_PACKET_SIZE); - hid_write(dev, B2Buffer, BLOODY_B820R_PACKET_SIZE); -} + + std::ofstream outputFile("example.txt"); + if (outputFile.is_open()) { + outputFile << colors.size(); + outputFile << "\n"; + outputFile << hexArrayToString(R1Buffer, BLOODY_B820R_PACKET_SIZE); + outputFile << "\n"; + outputFile << hexArrayToString(R2Buffer, BLOODY_B820R_PACKET_SIZE); + outputFile << "\n"; + outputFile << hexArrayToString(G1Buffer, BLOODY_B820R_PACKET_SIZE); + outputFile << "\n"; + outputFile << hexArrayToString(G2Buffer, BLOODY_B820R_PACKET_SIZE); + outputFile << "\n"; + outputFile << hexArrayToString(B1Buffer, BLOODY_B820R_PACKET_SIZE); + outputFile << "\n"; + outputFile << hexArrayToString(B2Buffer, BLOODY_B820R_PACKET_SIZE); + outputFile << "\n"; + outputFile << "Hello world14"; + outputFile.close(); + } + + + hid_send_feature_report(dev, R1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, R2Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, G1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, G2Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, B1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, B2Buffer, BLOODY_B820R_PACKET_SIZE); + + +// hid_write(dev, R1Buffer, BLOODY_B820R_PACKET_SIZE); +// hid_write(dev, R2Buffer, BLOODY_B820R_PACKET_SIZE); +// hid_write(dev, G1Buffer, BLOODY_B820R_PACKET_SIZE); +// hid_write(dev, G2Buffer, BLOODY_B820R_PACKET_SIZE); +// hid_write(dev, B1Buffer, BLOODY_B820R_PACKET_SIZE); +// hid_write(dev, B2Buffer, BLOODY_B820R_PACKET_SIZE); +} \ No newline at end of file diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h index 8f8433f02..13ce58a70 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h @@ -16,8 +16,10 @@ #define NA 0xFFFFFFFF #define HID_MAX_STR 255 -#define BLOODY_B820R_PACKET_SIZE 64 -#define BLOODY_B820R_TKL_KEYCOUNT 87 +#define BLOODY_B820R_PACKET_SIZE 64 +#define BLOODY_B820R_KEYCOUNT 104 +#define BLOODY_B820R_MODE_BYTE 3 +#define BLOODY_B820R_DATA_BYTE 8 enum { @@ -46,4 +48,6 @@ class A4TechBloodyB820RController private: std::string location; hid_device* dev; + + void InitDevice(); }; diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp index 7a11d7fe1..216f8b2e7 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp +++ b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp @@ -1,4 +1,5 @@ #include "Detector.h" +#include #include "A4TechBloodyB820RController.h" #include "RGBController.h" #include "RGBController_A4TechBloodyB820R.h" @@ -17,7 +18,7 @@ * * * DetectA4TechBloodyB820RControllers * * * -* Tests the USB address to see if an AOC Keyboard controller exists there. * +* Tests the USB address to see if an A4Tech Bloody controller exists there. * * * \******************************************************************************************/ @@ -35,4 +36,5 @@ void DetectA4TechBloodyB820R(hid_device_info* info, const std::string& name) } } -REGISTER_HID_DETECTOR_PU("A4Tech Bloody B820R", DetectA4TechBloodyB820R, A4Tech_VID, B820R_PID, 0xFF19, 0xFF19); +//REGISTER_HID_DETECTOR_I("A4Tech Bloody B820R", DetectA4TechBloodyB820R, A4Tech_VID, B820R_PID, 2); +REGISTER_HID_DETECTOR_IPU("A4Tech Bloody B820R SE", DetectA4TechBloodyB820R, A4Tech_VID, B820R_PID, 2, 0xFF52, 0x0210); diff --git a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp b/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp index d1a533969..5a3de4b7b 100644 --- a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp +++ b/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp @@ -10,6 +10,15 @@ #include "RGBControllerKeyNames.h" #include "RGBController_A4TechBloodyB820R.h" + +//std::string hexArrayToString(const uint8_t* arr, size_t size) { +// std::stringstream ss; +// for (size_t i = 0; i < size; ++i) { +// ss << std::hex << static_cast(arr[i]); +// } +// return ss.str(); +//} + static unsigned int matrix_map[6][18] = { { 0, NA, 1, 2, 3, 4, 5, 6, 7, 8, NA, 9, 10, 11, 12, 13, 14, 15 }, @@ -113,7 +122,25 @@ static const char *led_names[] = KEY_EN_RIGHT_CONTROL, KEY_EN_LEFT_ARROW, KEY_EN_DOWN_ARROW, - KEY_EN_RIGHT_ARROW + KEY_EN_RIGHT_ARROW, + + KEY_EN_NUMPAD_LOCK, + KEY_EN_NUMPAD_DIVIDE, + KEY_EN_NUMPAD_TIMES, + KEY_EN_NUMPAD_MINUS, + KEY_EN_NUMPAD_PLUS, + KEY_EN_NUMPAD_PERIOD, + KEY_EN_NUMPAD_ENTER, + KEY_EN_NUMPAD_0, + KEY_EN_NUMPAD_1, + KEY_EN_NUMPAD_2, + KEY_EN_NUMPAD_3, + KEY_EN_NUMPAD_4, + KEY_EN_NUMPAD_5, + KEY_EN_NUMPAD_6, + KEY_EN_NUMPAD_7, + KEY_EN_NUMPAD_8, + KEY_EN_NUMPAD_9 }; /**------------------------------------------------------------------*\ @@ -162,9 +189,9 @@ void RGBController_A4TechBloodyB820R::SetupZones() zone KB_zone; KB_zone.name = ZONE_EN_KEYBOARD; KB_zone.type = ZONE_TYPE_MATRIX; - KB_zone.leds_min = BLOODY_B820R_TKL_KEYCOUNT; - KB_zone.leds_max = BLOODY_B820R_TKL_KEYCOUNT; - KB_zone.leds_count = BLOODY_B820R_TKL_KEYCOUNT; + KB_zone.leds_min = BLOODY_B820R_KEYCOUNT; + KB_zone.leds_max = BLOODY_B820R_KEYCOUNT; + KB_zone.leds_count = BLOODY_B820R_KEYCOUNT; KB_zone.matrix_map = new matrix_map_type; KB_zone.matrix_map->height = 6; From c2292cd3bd7987375bf7059962423755262269a0 Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub Date: Mon, 1 Apr 2024 01:42:19 +0600 Subject: [PATCH 06/10] Structured and cleaned B820R Controller withing A4TechController --- .../A4TechBloodyB820RController.cpp | 383 ------------------ .../A4TechBloodyB820RControllerDetect.cpp | 40 -- ...A4Tech_Detector.cpp => A4TechDetector.cpp} | 30 ++ .../BloodyB820RController.cpp | 239 +++++++++++ .../BloodyB820RController.h} | 27 +- .../RGBController_BloodyB820R.cpp} | 90 ++-- .../RGBController_BloodyB820R.h} | 16 +- 7 files changed, 329 insertions(+), 496 deletions(-) delete mode 100644 Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp delete mode 100644 Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp rename Controllers/A4TechController/{A4Tech_Detector.cpp => A4TechDetector.cpp} (55%) create mode 100644 Controllers/A4TechController/BloodyB820RController.cpp rename Controllers/{A4TechBloodyB820RController/A4TechBloodyB820RController.h => A4TechController/BloodyB820RController.h} (62%) rename Controllers/{A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp => A4TechController/RGBController_BloodyB820R.cpp} (77%) rename Controllers/{A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h => A4TechController/RGBController_BloodyB820R.h} (58%) diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp deleted file mode 100644 index 1d5ce0027..000000000 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/*-------------------------------------------------------------------*\ -| DarkProjectKeyboardController.cpp | -| | -| Driver for DarkProjectKeyboard USB Controller | -| | -| Chris M (DrNo) 8 Apr 2022 | -| | -\*-------------------------------------------------------------------*/ - -#include "LogManager.h" -#include "A4TechBloodyB820RController.h" -#include -#include -#include -#include "fstream" - -static uint8_t map_layout1[58][2] = { - {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}, - {63} -}; - -static uint8_t map_layout2[58][2] = { - {6}, - {7}, - {8}, - {9}, - {10}, - {11}, - {12}, - {13}, - {14}, - {15}, - {16}, - {17}, - {18}, - {19}, - {20}, - {21}, - {22, 55}, - {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}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {} -}; - -//static uint8_t packet_map1[104] = -// { -///*00 ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 */ -// 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, -// -///*00 PS SL PB */ -// 19, 20, 21, -// -// -///*10 ` 1 2 3 4 5 6 7 8 9 0 - = */ -// 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, -// -///*10 BCK INS HM PU NUM [N /] [N *] [N -] */ -// 35, 36, 37, 38, 39, 40, 41, 42, -// -// -// -///*20 TAB Q W E R T Y U I O P [ ] */ -// 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, -// -///*20 \ DEL END PD [N 7] [N 8] [N 9] [N +] */ -// 56, 57, 58, 59, 60, 61, 62, 63 -// }; -// -//static uint16_t packet_map2[58] = -// { -// -///*30 LCAPS A S D F G H J K L ; ' BRK */ -// 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, -// -///*30 [N 4] [N 5] [N 6] */ -// 19, 20, 21, -// -// -// -// -///*40 LSHIFT Z X C V B N M , . / RSHIFT */ -// 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, -// -///*40 UP [N 1] [N 2] [N 3] [N BRK] */ -// 34, 35, 36, 37, 38, -// -// -// -// -///*50 LCTRL LWIN LALT SPC RALT RFN RCNTXT RCTRL LEFT DOWN RIGHT [N 0] [N .] */ -// 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -// -///* Missing Indexes 9, 22, 28, 40, 46, 70, 74, 75, 82, 86, 87, 92, 98, 99, 101 */ -// }; - - - - -A4TechBloodyB820RController::A4TechBloodyB820RController(hid_device* dev_handle, const char* path) -{ - dev = dev_handle; - location = path; - - InitDevice(); -} - -A4TechBloodyB820RController::~A4TechBloodyB820RController() -{ - hid_close(dev); -} - -std::string A4TechBloodyB820RController::GetDeviceName() -{ - const int szTemp = HID_MAX_STR; - wchar_t tmpName[szTemp]; - - hid_get_manufacturer_string(dev, tmpName, szTemp); - std::wstring wName = std::wstring(tmpName); - std::string name = std::string(wName.begin(), wName.end()); - - return name; -} - -std::string A4TechBloodyB820RController::GetSerial() -{ - const int szTemp = HID_MAX_STR; - wchar_t tmpName[szTemp]; - - hid_get_serial_number_string(dev, tmpName, szTemp); - std::wstring wName = std::wstring(tmpName); - std::string serial = std::string(wName.begin(), wName.end()); - - return serial; -} - -std::string A4TechBloodyB820RController::GetLocation() -{ - return("HID: " + location); -} - -std::string hexArrayToString(const uint8_t* arr, size_t size) { - std::stringstream ss; - ss << std::hex << std::setfill('0'); - for (size_t i = 0; i < size; ++i) { - ss << std::setw(2) << static_cast(arr[i]); -// ss << std::hex << static_cast(arr[i]); - } - return ss.str(); -} - -void A4TechBloodyB820RController::InitDevice() -{ - uint8_t buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00 }; - - hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); -// hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); - - buffer[BLOODY_B820R_MODE_BYTE] = 0; - buffer[BLOODY_B820R_DATA_BYTE] = 1; - - hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); -} - -void A4TechBloodyB820RController::SetLedsDirect(std::vector colors) -{ - - uint8_t R1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x07, 0x00, 0x00 }; - uint8_t R2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x08, 0x00, 0x00 }; - uint8_t G1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x09, 0x00, 0x00 }; - uint8_t G2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0a, 0x00, 0x00 }; - uint8_t B1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0b, 0x00, 0x00 }; - uint8_t B2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0c, 0x00, 0x00 }; - - /*-----------------------------------------------------------------*\ - | Set up Direct packet | - | packet_map is the index of the Key from full_matrix_map and | - | the value is the position in the direct packet buffer | - \*-----------------------------------------------------------------*/ - - -// std::ofstream outputFile("example.txt"); -// if (outputFile.is_open()) { -// outputFile << colors.size(); -// outputFile.close(); -// } - - for(size_t i = 0; i < colors.size(); i++) - { - RGBColor key = colors[i]; - - - size_t layout1_length = sizeof(map_layout1) / sizeof(map_layout1[0]); - - if (i < layout1_length) { - for(auto j : map_layout1[i]) { - if (j != 0) { - R1Buffer[j] = RGBGetRValue(key); - G1Buffer[j] = RGBGetGValue(key); - B1Buffer[j] = RGBGetBValue(key); - } - } - } else { - for(auto j : map_layout2[i - layout1_length]) { - if (j != 0) { - R2Buffer[j] = RGBGetRValue(key); - G2Buffer[j] = RGBGetGValue(key); - B2Buffer[j] = RGBGetBValue(key); - } - } - } -// uint16_t offset = packet_map1[i]; - -// uint8_t[2] offset1 = map_layout1[i]; - -// for(auto j : map_layout1[i]) { -// R1Buffer[j] = RGBGetRValue(key); -// G1Buffer[j] = RGBGetGValue(key); -// B1Buffer[j] = RGBGetBValue(key); -// } - -// uint8_t[2] offset2 = map_layout2[i]; - -// for(auto j : map_layout2[i]) { -// R2Buffer[j] = RGBGetRValue(key); -// G2Buffer[j] = RGBGetGValue(key); -// B2Buffer[j] = RGBGetBValue(key); -// } - - -// if (i < colors.size() / 2) { -// R1Buffer[offset] = RGBGetRValue(key); -// G1Buffer[offset] = RGBGetGValue(key); -// B1Buffer[offset] = RGBGetBValue(key); -// } else { -// R2Buffer[offset] = RGBGetRValue(key); -// G2Buffer[offset] = RGBGetGValue(key); -// B2Buffer[offset] = RGBGetBValue(key); -// } - -// R1Buffer[offset] = RGBGetRValue(key); -// R2Buffer[offset] = RGBGetRValue(key); -// G1Buffer[offset] = RGBGetGValue(key); -// G2Buffer[offset] = RGBGetGValue(key); -// B1Buffer[offset] = RGBGetBValue(key); -// B2Buffer[offset] = RGBGetBValue(key); - -// RGbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetRValue(key); -// RGbuffer[DARKPROJECTKEYBOARD_GREEN_BYTE + offset] = RGBGetGValue(key); -// BAbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetBValue(key); - } - - - - std::ofstream outputFile("example.txt"); - if (outputFile.is_open()) { - outputFile << colors.size(); - outputFile << "\n"; - outputFile << hexArrayToString(R1Buffer, BLOODY_B820R_PACKET_SIZE); - outputFile << "\n"; - outputFile << hexArrayToString(R2Buffer, BLOODY_B820R_PACKET_SIZE); - outputFile << "\n"; - outputFile << hexArrayToString(G1Buffer, BLOODY_B820R_PACKET_SIZE); - outputFile << "\n"; - outputFile << hexArrayToString(G2Buffer, BLOODY_B820R_PACKET_SIZE); - outputFile << "\n"; - outputFile << hexArrayToString(B1Buffer, BLOODY_B820R_PACKET_SIZE); - outputFile << "\n"; - outputFile << hexArrayToString(B2Buffer, BLOODY_B820R_PACKET_SIZE); - outputFile << "\n"; - outputFile << "Hello world14"; - outputFile.close(); - } - - - hid_send_feature_report(dev, R1Buffer, BLOODY_B820R_PACKET_SIZE); - hid_send_feature_report(dev, R2Buffer, BLOODY_B820R_PACKET_SIZE); - hid_send_feature_report(dev, G1Buffer, BLOODY_B820R_PACKET_SIZE); - hid_send_feature_report(dev, G2Buffer, BLOODY_B820R_PACKET_SIZE); - hid_send_feature_report(dev, B1Buffer, BLOODY_B820R_PACKET_SIZE); - hid_send_feature_report(dev, B2Buffer, BLOODY_B820R_PACKET_SIZE); - - -// hid_write(dev, R1Buffer, BLOODY_B820R_PACKET_SIZE); -// hid_write(dev, R2Buffer, BLOODY_B820R_PACKET_SIZE); -// hid_write(dev, G1Buffer, BLOODY_B820R_PACKET_SIZE); -// hid_write(dev, G2Buffer, BLOODY_B820R_PACKET_SIZE); -// hid_write(dev, B1Buffer, BLOODY_B820R_PACKET_SIZE); -// hid_write(dev, B2Buffer, BLOODY_B820R_PACKET_SIZE); -} \ No newline at end of file diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp b/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp deleted file mode 100644 index 216f8b2e7..000000000 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RControllerDetect.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "Detector.h" -#include -#include "A4TechBloodyB820RController.h" -#include "RGBController.h" -#include "RGBController_A4TechBloodyB820R.h" - -/*---------------------------------------------------------*\ -| A4Tech vendor ID | -\*---------------------------------------------------------*/ -#define A4Tech_VID 0x09DA - -/*---------------------------------------------------------*\ -| Bloody B820R product ID | -\*---------------------------------------------------------*/ -#define B820R_PID 0xFA10 - -/******************************************************************************************\ -* * -* DetectA4TechBloodyB820RControllers * -* * -* Tests the USB address to see if an A4Tech Bloody controller exists there. * -* * -\******************************************************************************************/ - -void DetectA4TechBloodyB820R(hid_device_info* info, const std::string& name) -{ - hid_device* dev = hid_open_path(info->path); - - if(dev) - { - A4TechBloodyB820RController* controller = new A4TechBloodyB820RController(dev, info->path); - RGBController_A4TechBloodyB820R* rgb_controller = new RGBController_A4TechBloodyB820R(controller); - rgb_controller->name = name; - - ResourceManager::get()->RegisterRGBController(rgb_controller); - } -} - -//REGISTER_HID_DETECTOR_I("A4Tech Bloody B820R", DetectA4TechBloodyB820R, A4Tech_VID, B820R_PID, 2); -REGISTER_HID_DETECTOR_IPU("A4Tech Bloody B820R SE", DetectA4TechBloodyB820R, A4Tech_VID, B820R_PID, 2, 0xFF52, 0x0210); diff --git a/Controllers/A4TechController/A4Tech_Detector.cpp b/Controllers/A4TechController/A4TechDetector.cpp similarity index 55% rename from Controllers/A4TechController/A4Tech_Detector.cpp rename to Controllers/A4TechController/A4TechDetector.cpp index 5e576ff72..a537b2f55 100644 --- a/Controllers/A4TechController/A4Tech_Detector.cpp +++ b/Controllers/A4TechController/A4TechDetector.cpp @@ -1,3 +1,13 @@ +/*-------------------------------------------------------------------*\ +| A4TechDetector.cpp | +| | +| Driver for A4Tech Devices Detector | +| | +| Chris M (Dr_No) 30 Jun 2022 | +| Mohammed Julfikar Ali Mahbub (o-julfikar) 01 Apr 2024 | +| | +\*-------------------------------------------------------------------*/ + /*-----------------------------------------------------*\ | OpenRGB includes | \*-----------------------------------------------------*/ @@ -5,10 +15,13 @@ #include "Detector.h" #include "RGBController.h" + /*-----------------------------------------------------*\ | A4 Tech specific includes | \*-----------------------------------------------------*/ #include "RGBController_BloodyMouse.h" +#include "BloodyB820RController.h" +#include "RGBController_BloodyB820R.h" /*-----------------------------------------------------*\ | A4 Tech USB vendor ID | @@ -29,6 +42,23 @@ void DetectA4TechMouseControllers(hid_device_info* info, const std::string& name } } +void DetectBloodyB820R(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + BloodyB820RController* controller = new BloodyB820RController(dev, info->path); + RGBController_BloodyB820R* rgb_controller = new RGBController_BloodyB820R(controller); + rgb_controller->name = name; + + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +} + + REGISTER_HID_DETECTOR_IPU("Bloody W60 Pro", DetectA4TechMouseControllers, A4_TECH_VID, BLOODY_W60_PRO_PID, 2, 0xFF33, 0x0529); REGISTER_HID_DETECTOR_IPU("Bloody W90 Max", DetectA4TechMouseControllers, A4_TECH_VID, BLOODY_W90_MAX_PID, 2, 0xFF33, 0x053D); REGISTER_HID_DETECTOR_IPU("Bloody MP 50RS", DetectA4TechMouseControllers, A4_TECH_VID, BLOODY_MP_50RS_PID, 2, 0xFFF2, 0x6009); + +REGISTER_HID_DETECTOR_IPU("A4Tech Bloody B820R", DetectBloodyB820R, A4_TECH_VID, BLOODY_B820R_PID, 2, 0xFF52, 0x0210); diff --git a/Controllers/A4TechController/BloodyB820RController.cpp b/Controllers/A4TechController/BloodyB820RController.cpp new file mode 100644 index 000000000..1cd8fa71c --- /dev/null +++ b/Controllers/A4TechController/BloodyB820RController.cpp @@ -0,0 +1,239 @@ +/*-------------------------------------------------------------------*\ +| BloodyB820RController.cpp | +| | +| Driver for A4Tech Bloody B820R Keyboard Controller | +| | +| Mohammed Julfikar Ali Mahbub (o-julfikar) 01 Apr 2024 | +| | +\*-------------------------------------------------------------------*/ + +#include "LogManager.h" +#include "BloodyB820RController.h" + +static uint8_t map_layout1[58][2] = { + {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}, + {63} +}; + +static uint8_t map_layout2[58][2] = { + {6}, + {7}, + {8}, + {9}, + {10}, + {11}, + {12}, + {13}, + {14}, + {15}, + {16}, + {17}, + {18}, + {19}, + {20}, + {21}, + {22, 55}, + {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}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} +}; + + +BloodyB820RController::BloodyB820RController(hid_device* dev_handle, const char* path) +{ + dev = dev_handle; + location = path; + + InitDevice(); +} + +BloodyB820RController::~BloodyB820RController() +{ + hid_close(dev); +} + +std::string BloodyB820RController::GetDeviceName() +{ + const int szTemp = HID_MAX_STR; + wchar_t tmpName[szTemp]; + + hid_get_manufacturer_string(dev, tmpName, szTemp); + std::wstring wName = std::wstring(tmpName); + std::string name = std::string(wName.begin(), wName.end()); + + return name; +} + +std::string BloodyB820RController::GetSerial() +{ + const int szTemp = HID_MAX_STR; + wchar_t tmpName[szTemp]; + + hid_get_serial_number_string(dev, tmpName, szTemp); + std::wstring wName = std::wstring(tmpName); + std::string serial = std::string(wName.begin(), wName.end()); + + return serial; +} + +std::string BloodyB820RController::GetLocation() +{ + return("HID: " + location); +} + +void BloodyB820RController::InitDevice() +{ + uint8_t buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00 }; + + hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); + + buffer[BLOODY_B820R_MODE_BYTE] = 0; + buffer[BLOODY_B820R_DATA_BYTE] = 1; + + hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); +} + +void BloodyB820RController::SetLEDDirect(std::vector colors) +{ + + uint8_t R1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x07, 0x00, 0x00 }; + uint8_t R2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x08, 0x00, 0x00 }; + uint8_t G1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x09, 0x00, 0x00 }; + uint8_t G2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0a, 0x00, 0x00 }; + uint8_t B1Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0b, 0x00, 0x00 }; + uint8_t B2Buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x0c, 0x00, 0x00 }; + + /*-----------------------------------------------------------------*\ + | Set up Direct packet | + | packet_map is the index of the Key from full_matrix_map and | + | the value is the position in the direct packet buffer | + \*-----------------------------------------------------------------*/ + + + for(size_t i = 0; i < colors.size(); i++) + { + RGBColor key = colors[i]; + + + size_t layout1_length = sizeof(map_layout1) / sizeof(map_layout1[0]); + + if (i < layout1_length) { + for(auto j : map_layout1[i]) { + if (j != 0) { + R1Buffer[j] = RGBGetRValue(key); + G1Buffer[j] = RGBGetGValue(key); + B1Buffer[j] = RGBGetBValue(key); + } + } + } else { + for(auto j : map_layout2[i - layout1_length]) { + if (j != 0) { + R2Buffer[j] = RGBGetRValue(key); + G2Buffer[j] = RGBGetGValue(key); + B2Buffer[j] = RGBGetBValue(key); + } + } + } + } + + hid_send_feature_report(dev, R1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, R2Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, G1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, G2Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, B1Buffer, BLOODY_B820R_PACKET_SIZE); + hid_send_feature_report(dev, B2Buffer, BLOODY_B820R_PACKET_SIZE); +} \ No newline at end of file diff --git a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h b/Controllers/A4TechController/BloodyB820RController.h similarity index 62% rename from Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h rename to Controllers/A4TechController/BloodyB820RController.h index 13ce58a70..1a1933f7c 100644 --- a/Controllers/A4TechBloodyB820RController/A4TechBloodyB820RController.h +++ b/Controllers/A4TechController/BloodyB820RController.h @@ -1,9 +1,9 @@ /*-------------------------------------------------------------------*\ -| A4TechBloodyB820RController.h | +| BloodyB820RController.h | | | -| Driver for DarkProjectKeyboard USB Controller | +| Driver for A4Tech Bloody B820R Keyboard Controller | | | -| Zulfikar (o-julfikar) 8 Apr 2022 | +| Mohammed Julfikar Ali Mahbub (o-julfikar) 01 Apr 2024 | | | \*-------------------------------------------------------------------*/ @@ -21,30 +21,27 @@ #define BLOODY_B820R_MODE_BYTE 3 #define BLOODY_B820R_DATA_BYTE 8 -enum -{ - BLOODY_B820R_MODE_DIRECT = 0x01, //Direct Led Control - Independently set LEDs in zone -}; +/*---------------------------------------------------------*\ +| Bloody B820R product ID | +\*---------------------------------------------------------*/ +#define BLOODY_B820R_PID 0xFA10 enum { - BLOODY_B820R_REPORT_BYTE = 1, - BLOODY_B820R_COMMAND_BYTE = 2, - BLOODY_B820R_RED_BLUE_BYTE = 5, - BLOODY_B820R_GREEN_BYTE = 107 + BLOODY_B820R_MODE_DIRECT = 0x01, //Direct Led Control - Independently set LEDs in zone }; -class A4TechBloodyB820RController +class BloodyB820RController { public: - A4TechBloodyB820RController(hid_device* dev_handle, const char* path); - ~A4TechBloodyB820RController(); + BloodyB820RController(hid_device* dev_handle, const char* path); + ~BloodyB820RController(); std::string GetDeviceName(); std::string GetSerial(); std::string GetLocation(); - void SetLedsDirect(std::vector colors); + void SetLEDDirect(std::vector colors); private: std::string location; hid_device* dev; diff --git a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp b/Controllers/A4TechController/RGBController_BloodyB820R.cpp similarity index 77% rename from Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp rename to Controllers/A4TechController/RGBController_BloodyB820R.cpp index 5a3de4b7b..a10c0230a 100644 --- a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.cpp +++ b/Controllers/A4TechController/RGBController_BloodyB820R.cpp @@ -1,32 +1,23 @@ /*-------------------------------------------------------------------*\ -| RGBController_DarkProjectKeyboard.cpp | +| RGBController_BloodyB820R.cpp | | | -| Driver for DarkProjectKeyboard USB Controller | +| Driver for A4Tech Bloody B820R Keyboard Controller | | | -| Zulfikar (o-julfikar) 28 Mar 2024 | +| Mohammed Julfikar Ali Mahbub (o-julfikar) 01 Apr 2024 | | | \*-------------------------------------------------------------------*/ #include "RGBControllerKeyNames.h" -#include "RGBController_A4TechBloodyB820R.h" +#include "RGBController_BloodyB820R.h" - -//std::string hexArrayToString(const uint8_t* arr, size_t size) { -// std::stringstream ss; -// for (size_t i = 0; i < size; ++i) { -// ss << std::hex << static_cast(arr[i]); -// } -// return ss.str(); -//} - -static unsigned int matrix_map[6][18] = +static unsigned int matrix_map[6][21] = { - { 0, NA, 1, 2, 3, 4, 5, 6, 7, 8, NA, 9, 10, 11, 12, 13, 14, 15 }, - { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, NA, 30, 31, 32 }, - { 33, NA, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 }, - { 50, NA, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NA, 62, NA, NA, NA }, - { 63, NA, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, NA, 74, NA, NA, 75, NA }, - { 76, 77, 78, NA, NA, NA, 79, NA, NA, NA, 80, 81, NA, 82, 83, 84, 85, 86 } + {0, NA, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, NA, NA, NA, NA, 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, 63, 64, 65, 66, 67, 68, 69, 70, NA, NA, NA, NA, 71, 72, 73, NA}, + {74, NA, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, NA, NA, 86, NA, 87, 88, 89, 90}, + {91, 92, 93, 94, NA, NA, NA, NA, NA, NA, 95, 96, 97, 98, 99, 100, 101, 102, NA, 103, NA}, }; static const char *led_names[] = @@ -65,6 +56,10 @@ static const char *led_names[] = KEY_EN_INSERT, //30 KEY_EN_HOME, KEY_EN_PAGE_UP, + KEY_EN_NUMPAD_LOCK, + KEY_EN_NUMPAD_DIVIDE, + KEY_EN_NUMPAD_TIMES, + KEY_EN_NUMPAD_MINUS, KEY_EN_TAB, KEY_EN_Q, @@ -83,6 +78,10 @@ static const char *led_names[] = 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, KEY_EN_CAPS_LOCK, //50 KEY_EN_A, @@ -97,6 +96,9 @@ static const char *led_names[] = KEY_EN_SEMICOLON, //60 KEY_EN_QUOTE, KEY_EN_ANSI_ENTER, + KEY_EN_NUMPAD_4, + KEY_EN_NUMPAD_5, + KEY_EN_NUMPAD_6, KEY_EN_LEFT_SHIFT, KEY_EN_Z, @@ -111,6 +113,10 @@ static const char *led_names[] = KEY_EN_FORWARD_SLASH, KEY_EN_RIGHT_SHIFT, KEY_EN_UP_ARROW, + KEY_EN_NUMPAD_1, + KEY_EN_NUMPAD_2, + KEY_EN_NUMPAD_3, + KEY_EN_NUMPAD_ENTER, KEY_EN_LEFT_CONTROL, KEY_EN_LEFT_WINDOWS, @@ -123,24 +129,8 @@ static const char *led_names[] = KEY_EN_LEFT_ARROW, KEY_EN_DOWN_ARROW, KEY_EN_RIGHT_ARROW, - - KEY_EN_NUMPAD_LOCK, - KEY_EN_NUMPAD_DIVIDE, - KEY_EN_NUMPAD_TIMES, - KEY_EN_NUMPAD_MINUS, - KEY_EN_NUMPAD_PLUS, - KEY_EN_NUMPAD_PERIOD, - KEY_EN_NUMPAD_ENTER, KEY_EN_NUMPAD_0, - KEY_EN_NUMPAD_1, - KEY_EN_NUMPAD_2, - KEY_EN_NUMPAD_3, - KEY_EN_NUMPAD_4, - KEY_EN_NUMPAD_5, - KEY_EN_NUMPAD_6, - KEY_EN_NUMPAD_7, - KEY_EN_NUMPAD_8, - KEY_EN_NUMPAD_9 + KEY_EN_NUMPAD_PERIOD }; /**------------------------------------------------------------------*\ @@ -155,11 +145,11 @@ static const char *led_names[] = supports the full size KD3B Version 2 (ANSI layout). \*-------------------------------------------------------------------*/ -RGBController_A4TechBloodyB820R::RGBController_A4TechBloodyB820R(A4TechBloodyB820RController *controller_ptr) +RGBController_BloodyB820R::RGBController_BloodyB820R(BloodyB820RController *controller_ptr) { controller = controller_ptr; - name = "A4 Tech Bloody B820R"; + name = "Bloody B820R"; vendor = "A4Tech"; type = DEVICE_TYPE_KEYBOARD; description = controller->GetDeviceName(); @@ -176,12 +166,12 @@ RGBController_A4TechBloodyB820R::RGBController_A4TechBloodyB820R(A4TechBloodyB82 SetupZones(); } -RGBController_A4TechBloodyB820R::~RGBController_A4TechBloodyB820R() +RGBController_BloodyB820R::~RGBController_BloodyB820R() { delete controller; } -void RGBController_A4TechBloodyB820R::SetupZones() +void RGBController_BloodyB820R::SetupZones() { /*-------------------------------------------------*\ | Create the Keyboard zone and add the matrix map | @@ -195,7 +185,7 @@ void RGBController_A4TechBloodyB820R::SetupZones() KB_zone.matrix_map = new matrix_map_type; KB_zone.matrix_map->height = 6; - KB_zone.matrix_map->width = 18; + KB_zone.matrix_map->width = 21; KB_zone.matrix_map->map = (unsigned int *)&matrix_map; zones.push_back(KB_zone); @@ -222,7 +212,7 @@ void RGBController_A4TechBloodyB820R::SetupZones() SetupColors(); } -void RGBController_A4TechBloodyB820R::ResizeZone(int /*zone*/, int /*new_size*/) +void RGBController_BloodyB820R::ResizeZone(int /*zone*/, int /*new_size*/) { /*---------------------------------------------------------*\ | This device does not support resizing zones | @@ -230,12 +220,12 @@ void RGBController_A4TechBloodyB820R::ResizeZone(int /*zone*/, int /*new_size*/) } -void RGBController_A4TechBloodyB820R::DeviceUpdateLEDs() +void RGBController_BloodyB820R::DeviceUpdateLEDs() { - controller->SetLedsDirect(colors); + controller->SetLEDDirect(colors); } -void RGBController_A4TechBloodyB820R::UpdateZoneLEDs(int zone) +void RGBController_BloodyB820R::UpdateZoneLEDs(int zone) { std::vector colour; for(size_t i = 0; i < zones[zone].leds_count; i++) @@ -243,18 +233,18 @@ void RGBController_A4TechBloodyB820R::UpdateZoneLEDs(int zone) colour.push_back(zones[zone].colors[i]); } - controller->SetLedsDirect(colour); + controller->SetLEDDirect(colour); } -void RGBController_A4TechBloodyB820R::UpdateSingleLED(int led) +void RGBController_BloodyB820R::UpdateSingleLED(int led) { std::vector colour; colour.push_back(colors[led]); - controller->SetLedsDirect(colour); + controller->SetLEDDirect(colour); } -void RGBController_A4TechBloodyB820R::DeviceUpdateMode() +void RGBController_BloodyB820R::DeviceUpdateMode() { /*---------------------------------------------------------*\ | This device only supports `Direct` mode | diff --git a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h b/Controllers/A4TechController/RGBController_BloodyB820R.h similarity index 58% rename from Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h rename to Controllers/A4TechController/RGBController_BloodyB820R.h index 0d245c65e..2e50110f4 100644 --- a/Controllers/A4TechBloodyB820RController/RGBController_A4TechBloodyB820R.h +++ b/Controllers/A4TechController/RGBController_BloodyB820R.h @@ -1,23 +1,23 @@ /*-------------------------------------------------------------------*\ -| RGBController_A4TechBloodyB820R.h | +| RGBController_BloodyB820R.h | | | -| Driver for A4TechBloodyB820R Keyboard Controller | +| Driver for A4Tech Bloody B820R Keyboard Controller | | | -| Zulfikar (o-julfikar) 28 Mar 2024 | +| Mohammed Julfikar Ali Mahbub (o-julfikar) 01 Apr 2024 | | | \*-------------------------------------------------------------------*/ #pragma once #include "LogManager.h" #include "RGBController.h" -#include "A4TechBloodyB820RController.h" +#include "BloodyB820RController.h" #include -class RGBController_A4TechBloodyB820R : public RGBController +class RGBController_BloodyB820R : public RGBController { public: - RGBController_A4TechBloodyB820R(A4TechBloodyB820RController* controller_ptr); - ~RGBController_A4TechBloodyB820R(); + RGBController_BloodyB820R(BloodyB820RController* controller_ptr); + ~RGBController_BloodyB820R(); void SetupZones(); void ResizeZone(int zone, int new_size); @@ -29,5 +29,5 @@ class RGBController_A4TechBloodyB820R : public RGBController void DeviceUpdateMode(); private: - A4TechBloodyB820RController* controller; + BloodyB820RController* controller; }; From 725e70ff5c020bbcdaaf6d383233996a4382f7a8 Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub Date: Mon, 1 Apr 2024 02:13:19 +0600 Subject: [PATCH 07/10] Added ReleaseDevice function for Bloody B820R to enable keyboard control. --- .../A4TechController/BloodyB820RController.cpp | 12 ++++++++++++ Controllers/A4TechController/BloodyB820RController.h | 1 + 2 files changed, 13 insertions(+) diff --git a/Controllers/A4TechController/BloodyB820RController.cpp b/Controllers/A4TechController/BloodyB820RController.cpp index 1cd8fa71c..3f90d176e 100644 --- a/Controllers/A4TechController/BloodyB820RController.cpp +++ b/Controllers/A4TechController/BloodyB820RController.cpp @@ -144,6 +144,7 @@ BloodyB820RController::BloodyB820RController(hid_device* dev_handle, const char* BloodyB820RController::~BloodyB820RController() { hid_close(dev); + ReleaseDevice(); } std::string BloodyB820RController::GetDeviceName() @@ -187,6 +188,17 @@ void BloodyB820RController::InitDevice() hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); } +void BloodyB820RController::ReleaseDevice() +{ + uint8_t buffer[BLOODY_B820R_PACKET_SIZE] = { 0x07, 0x03, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00 }; + + hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); + + buffer[BLOODY_B820R_MODE_BYTE] = 0; + + hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); +} + void BloodyB820RController::SetLEDDirect(std::vector colors) { diff --git a/Controllers/A4TechController/BloodyB820RController.h b/Controllers/A4TechController/BloodyB820RController.h index 1a1933f7c..0cac767e4 100644 --- a/Controllers/A4TechController/BloodyB820RController.h +++ b/Controllers/A4TechController/BloodyB820RController.h @@ -47,4 +47,5 @@ class BloodyB820RController hid_device* dev; void InitDevice(); + void ReleaseDevice(); }; From 9406b915ee9879eaad441a6c3129e6552cded9e3 Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub Date: Mon, 1 Apr 2024 02:13:40 +0600 Subject: [PATCH 08/10] Added ReleaseDevice function for Bloody B820R to enable keyboard control. --- Controllers/A4TechController/BloodyB820RController.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Controllers/A4TechController/BloodyB820RController.cpp b/Controllers/A4TechController/BloodyB820RController.cpp index 3f90d176e..f6946370e 100644 --- a/Controllers/A4TechController/BloodyB820RController.cpp +++ b/Controllers/A4TechController/BloodyB820RController.cpp @@ -144,7 +144,6 @@ BloodyB820RController::BloodyB820RController(hid_device* dev_handle, const char* BloodyB820RController::~BloodyB820RController() { hid_close(dev); - ReleaseDevice(); } std::string BloodyB820RController::GetDeviceName() From 3e0aa8c8752c65db6c77f8b326edeedad5b28a88 Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub Date: Mon, 1 Apr 2024 02:21:26 +0600 Subject: [PATCH 09/10] Updated B820R description. --- Controllers/A4TechController/RGBController_BloodyB820R.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Controllers/A4TechController/RGBController_BloodyB820R.cpp b/Controllers/A4TechController/RGBController_BloodyB820R.cpp index a10c0230a..fe5fbfc7a 100644 --- a/Controllers/A4TechController/RGBController_BloodyB820R.cpp +++ b/Controllers/A4TechController/RGBController_BloodyB820R.cpp @@ -140,9 +140,9 @@ static const char *led_names[] = @save :x: @direct :white_check_mark: @effects :x: - @detectors A4TechBloodyB820RControllerDetect + @detectors A4TechDetector @comment The A4Tech Bloody B820R keyboard controller currently - supports the full size KD3B Version 2 (ANSI layout). + supports the full size (ANSI layout). \*-------------------------------------------------------------------*/ RGBController_BloodyB820R::RGBController_BloodyB820R(BloodyB820RController *controller_ptr) @@ -152,7 +152,7 @@ RGBController_BloodyB820R::RGBController_BloodyB820R(BloodyB820RController *cont name = "Bloody B820R"; vendor = "A4Tech"; type = DEVICE_TYPE_KEYBOARD; - description = controller->GetDeviceName(); + description = "Contributed by Mohammed Julfikar Ali Mahbub (github.com/o-julfikar)"; serial = controller->GetSerial(); location = controller->GetLocation(); From 9ef46d33821409a111c49d68f35ca00bdfbd5959 Mon Sep 17 00:00:00 2001 From: Mohammed Julfikar Ali Mahbub Date: Tue, 2 Apr 2024 01:50:44 +0600 Subject: [PATCH 10/10] Added Release Control mode that gives back RGB control to the keyboard. --- .../BloodyB820RController.cpp | 24 +++++++++++++ .../A4TechController/BloodyB820RController.h | 6 +++- .../RGBController_BloodyB820R.cpp | 35 +++++++++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/Controllers/A4TechController/BloodyB820RController.cpp b/Controllers/A4TechController/BloodyB820RController.cpp index f6946370e..f8d3b070b 100644 --- a/Controllers/A4TechController/BloodyB820RController.cpp +++ b/Controllers/A4TechController/BloodyB820RController.cpp @@ -198,6 +198,30 @@ void BloodyB820RController::ReleaseDevice() hid_send_feature_report(dev, buffer, BLOODY_B820R_PACKET_SIZE); } +void BloodyB820RController::SetMode( + int mode, + int speed, + unsigned char brightness, + unsigned char dir, + unsigned char red, + unsigned char green, + unsigned char blue) { + + + switch (mode) { + case BLOODY_B820R_MODE_DIRECT: + case BLOODY_B820R_MODE_INIT: + InitDevice(); + break; + case BLOODY_B820R_MODE_RELEASE: + ReleaseDevice(); + break; + default: + break; + } + +} + void BloodyB820RController::SetLEDDirect(std::vector colors) { diff --git a/Controllers/A4TechController/BloodyB820RController.h b/Controllers/A4TechController/BloodyB820RController.h index 0cac767e4..b3730c459 100644 --- a/Controllers/A4TechController/BloodyB820RController.h +++ b/Controllers/A4TechController/BloodyB820RController.h @@ -28,7 +28,10 @@ enum { - BLOODY_B820R_MODE_DIRECT = 0x01, //Direct Led Control - Independently set LEDs in zone + BLOODY_B820R_MODE_DIRECT = 0x01, // Direct LED control - Independently set LEDs in zone + BLOODY_B820R_MODE_RELEASE = 0x02, // Release the OpenRGB control from the keyboard + BLOODY_B820R_MODE_INIT = 0x03, // Regain the OpenRGB control of the keyboard + BLOODY_B820R_MODE_BREATHING = 0x04, // Set breathing RGB effect }; class BloodyB820RController @@ -42,6 +45,7 @@ class BloodyB820RController std::string GetLocation(); void SetLEDDirect(std::vector colors); + void SetMode(int mode, int speed, unsigned char brightness, unsigned char dir, unsigned char red, unsigned char green, unsigned char blue); private: std::string location; hid_device* dev; diff --git a/Controllers/A4TechController/RGBController_BloodyB820R.cpp b/Controllers/A4TechController/RGBController_BloodyB820R.cpp index fe5fbfc7a..8b3c3646e 100644 --- a/Controllers/A4TechController/RGBController_BloodyB820R.cpp +++ b/Controllers/A4TechController/RGBController_BloodyB820R.cpp @@ -163,6 +163,20 @@ RGBController_BloodyB820R::RGBController_BloodyB820R(BloodyB820RController *cont Direct.color_mode = MODE_COLORS_PER_LED; modes.push_back(Direct); + mode Init; + Init.name = "Init"; + Init.value = BLOODY_B820R_MODE_INIT; + Init.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Init.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Init); + + mode Release; + Release.name = "Release Control"; + Release.value = BLOODY_B820R_MODE_RELEASE; + Release.flags = 0; + Release.color_mode = MODE_COLORS_NONE; + modes.push_back(Release); + SetupZones(); } @@ -246,7 +260,22 @@ void RGBController_BloodyB820R::UpdateSingleLED(int led) void RGBController_BloodyB820R::DeviceUpdateMode() { - /*---------------------------------------------------------*\ - | This device only supports `Direct` mode | - \*---------------------------------------------------------*/ + unsigned char red = 0; + unsigned char grn = 0; + unsigned char blu = 0; + unsigned char dir = 0; + + if(modes[active_mode].color_mode & MODE_COLORS_MODE_SPECIFIC) + { + red = RGBGetRValue(modes[active_mode].colors[0]); + grn = RGBGetGValue(modes[active_mode].colors[0]); + blu = RGBGetBValue(modes[active_mode].colors[0]); + } + + if(modes[active_mode].flags & MODE_FLAG_HAS_DIRECTION_LR) + { + dir = (unsigned char)modes[active_mode].direction; + } + + controller->SetMode(modes[active_mode].value, modes[active_mode].speed, modes[active_mode].brightness, dir, red, grn, blu); }