From 04b2e35f81989d69fec59ae7f08af1565ee89bf2 Mon Sep 17 00:00:00 2001 From: Florian Heilmann Date: Mon, 19 Oct 2020 11:02:14 +0200 Subject: [PATCH] Add SteelSeries Apex M750 support Commits squashed and some minor code style changes by Adam Honse --- .../RGBController_SteelSeriesApex.cpp | 10 +- .../RGBController_SteelSeriesApex.h | 6 +- .../SteelSeriesApexBaseController.h | 40 +++++++ .../SteelSeriesApexController.cpp | 5 - .../SteelSeriesApexController.h | 10 +- .../SteelSeriesApexMController.cpp | 111 ++++++++++++++++++ .../SteelSeriesApexMController.h | 40 +++++++ .../SteelSeriesControllerDetect.cpp | 24 +++- .../SteelSeriesGeneric.h | 1 + OpenRGB.pro | 3 + 10 files changed, 224 insertions(+), 26 deletions(-) create mode 100644 Controllers/SteelSeriesController/SteelSeriesApexBaseController.h create mode 100644 Controllers/SteelSeriesController/SteelSeriesApexMController.cpp create mode 100644 Controllers/SteelSeriesController/SteelSeriesApexMController.h diff --git a/Controllers/SteelSeriesController/RGBController_SteelSeriesApex.cpp b/Controllers/SteelSeriesController/RGBController_SteelSeriesApex.cpp index daf3c6c3..1172923a 100644 --- a/Controllers/SteelSeriesController/RGBController_SteelSeriesApex.cpp +++ b/Controllers/SteelSeriesController/RGBController_SteelSeriesApex.cpp @@ -261,7 +261,7 @@ static const char *led_names_tkl[] = "Key: \\", }; -RGBController_SteelSeriesApex::RGBController_SteelSeriesApex(SteelSeriesApexController* steelseries_ptr) +RGBController_SteelSeriesApex::RGBController_SteelSeriesApex(SteelSeriesApexBaseController* steelseries_ptr) { steelseries = steelseries_ptr; @@ -309,7 +309,7 @@ void RGBController_SteelSeriesApex::SetupZones() new_zone.name = zone_names[zone_idx]; new_zone.type = zone_types[zone_idx]; - if(proto_type == APEX) + if((proto_type == APEX) || (proto_type == APEX_M)) { new_zone.leds_min = zone_sizes[zone_idx]; new_zone.leds_max = zone_sizes[zone_idx]; @@ -326,7 +326,7 @@ void RGBController_SteelSeriesApex::SetupZones() { new_zone.matrix_map = new matrix_map_type; new_zone.matrix_map->height = 6; - if(proto_type == APEX) + if((proto_type == APEX) || (proto_type == APEX_M)) { new_zone.matrix_map->width = 23; new_zone.matrix_map->map = (unsigned int *)&matrix_map; @@ -344,7 +344,7 @@ void RGBController_SteelSeriesApex::SetupZones() zones.push_back(new_zone); - if(proto_type == APEX) + if((proto_type == APEX) || (proto_type == APEX_M)) { total_led_count += zone_sizes[zone_idx]; } @@ -357,7 +357,7 @@ void RGBController_SteelSeriesApex::SetupZones() for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++) { led new_led; - if(proto_type == APEX) + if((proto_type == APEX) || (proto_type == APEX_M)) { new_led.name = led_names[led_idx]; } diff --git a/Controllers/SteelSeriesController/RGBController_SteelSeriesApex.h b/Controllers/SteelSeriesController/RGBController_SteelSeriesApex.h index 302aa3f8..5811f827 100644 --- a/Controllers/SteelSeriesController/RGBController_SteelSeriesApex.h +++ b/Controllers/SteelSeriesController/RGBController_SteelSeriesApex.h @@ -11,13 +11,13 @@ #include #include "RGBController.h" -#include "SteelSeriesApexController.h" +#include "SteelSeriesApexBaseController.h" #include "SteelSeriesGeneric.h" class RGBController_SteelSeriesApex : public RGBController { public: - RGBController_SteelSeriesApex(SteelSeriesApexController* steelseries_ptr); + RGBController_SteelSeriesApex(SteelSeriesApexBaseController* steelseries_ptr); ~RGBController_SteelSeriesApex(); void SetupZones(); @@ -32,7 +32,7 @@ public: void DeviceUpdateMode(); private: - SteelSeriesApexController* steelseries; + SteelSeriesApexBaseController* steelseries; steelseries_type proto_type; std::chrono::time_point last_update_time; diff --git a/Controllers/SteelSeriesController/SteelSeriesApexBaseController.h b/Controllers/SteelSeriesController/SteelSeriesApexBaseController.h new file mode 100644 index 00000000..785ab324 --- /dev/null +++ b/Controllers/SteelSeriesController/SteelSeriesApexBaseController.h @@ -0,0 +1,40 @@ +/*-----------------------------------------*\ +| SteelSeriesApexBaseController.h | +| | +| Base controller for SteelSeries Apex | +| Keyboard lighting controllers | +| | +| Florian Heilmann (FHeilmann) 19/10/2020 | +\*-----------------------------------------*/ + +#include "RGBController.h" +#include "SteelSeriesGeneric.h" + +#include + +#pragma once + +class SteelSeriesApexBaseController +{ +public: + + std::string GetDeviceLocation() + { + return(location); + }; + + steelseries_type proto_type; + + virtual void SetMode + ( + unsigned char mode, + std::vector colors + ) = 0; + + virtual void SetLEDsDirect(std::vector colors) = 0; + +protected: + std::string location; + hid_device* dev; + unsigned char active_mode; +}; diff --git a/Controllers/SteelSeriesController/SteelSeriesApexController.cpp b/Controllers/SteelSeriesController/SteelSeriesApexController.cpp index bb9ebcfc..13353108 100644 --- a/Controllers/SteelSeriesController/SteelSeriesApexController.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesApexController.cpp @@ -43,11 +43,6 @@ SteelSeriesApexController::~SteelSeriesApexController() } -std::string SteelSeriesApexController::GetDeviceLocation() -{ - return(location); -} - void SteelSeriesApexController::SetMode ( unsigned char mode, diff --git a/Controllers/SteelSeriesController/SteelSeriesApexController.h b/Controllers/SteelSeriesController/SteelSeriesApexController.h index b7ebf6f3..0f8bb606 100644 --- a/Controllers/SteelSeriesController/SteelSeriesApexController.h +++ b/Controllers/SteelSeriesController/SteelSeriesApexController.h @@ -9,6 +9,7 @@ #include "RGBController.h" #include "SteelSeriesGeneric.h" +#include "SteelSeriesApexBaseController.h" #include #include @@ -20,16 +21,12 @@ enum APEX_PACKET_ID_DIRECT = 0x3a, /* Direct mode */ }; -class SteelSeriesApexController +class SteelSeriesApexController : public SteelSeriesApexBaseController { public: SteelSeriesApexController(hid_device* dev_handle, steelseries_type type, const char* path); ~SteelSeriesApexController(); - std::string GetDeviceLocation(); - - steelseries_type proto_type; - void SetMode ( unsigned char mode, @@ -39,9 +36,6 @@ public: void SetLEDsDirect(std::vector colors); private: - hid_device* dev; - unsigned char active_mode; - std::string location; void SelectProfile ( diff --git a/Controllers/SteelSeriesController/SteelSeriesApexMController.cpp b/Controllers/SteelSeriesController/SteelSeriesApexMController.cpp new file mode 100644 index 00000000..ef7008a1 --- /dev/null +++ b/Controllers/SteelSeriesController/SteelSeriesApexMController.cpp @@ -0,0 +1,111 @@ +/*-----------------------------------------*\ +| SteelSeriesApexMController.cpp | +| | +| Definitions and types for SteelSeries | +| Apex M750 Keyboard lighting controller | +| | +| Florian Heilmann (FHeilmann) 12/10/2020 | +\*-----------------------------------------*/ + +#include "SteelSeriesApexMController.h" + +#include + +#define NA 0xFF +static unsigned int keys_m[] = { 96, 99, 98, NA, 40, NA, NA, NA, NA, 102, 103, 104, 100, NA, NA , 75, 76, 74, NA, 93, NA, 94, + 97, 25, 23, 2 , 21, 1 , 13, 12, 49, 50 , 51 , NA , 101, NA, NA , NA, 77, NA, 84, 85, 86, 83, + 52, 0 , 18, 3 , 5 , 6 , 7 , 9 , 10, 11 , 46 , 47 , NA , 36, NA , NA, NA, NA, 87, 88, 89, NA, + 39, 16, 22, 4 , 17, 19, 24, 20, 8 , 14 , 15 , 43 , 44 , NA, 105, 71, 72, 73, 90, 91, 92, 82, + 48, 26, 27, 28, 29, 30, 31, 32, 33, 34 , 35 , 41 , 42 , NA, 38 , 68, 69, 70, 78, 79, 80, 81, + 37, 53, 54, 55, 56, NA, 57, 58, 59, 60 , NA , 61 , 62 , 63, 64 , 65, 66, 67, NA, NA, NA, NA }; + +SteelSeriesApexMController::SteelSeriesApexMController(hid_device* dev_handle, steelseries_type type, const char* path) +{ + dev = dev_handle; + location = path; + proto_type = type; + EnableLEDControl(); +} + +SteelSeriesApexMController::~SteelSeriesApexMController() +{ + +} + +void SteelSeriesApexMController::EnableLEDControl() +{ + unsigned char buf[513] = { 0x00 }; + buf[0x00] = 0x00; + buf[0x01] = 0x00; + buf[0x02] = 0x00; + buf[0x03] = 0x00; + buf[0x04] = 0x01; + buf[0x05] = 0x00; + buf[0x06] = 0x85; + hid_send_feature_report(dev, buf, 513); + buf[0x00] = 0x00; + buf[0x01] = 0x00; + buf[0x02] = 0x00; + buf[0x03] = 0x00; + buf[0x04] = 0x03; + buf[0x05] = 0x01; + buf[0x06] = 0x00; + buf[0x07] = 0xff; + hid_send_feature_report(dev, buf, 513); + buf[0x00] = 0x00; + buf[0x01] = 0x00; + buf[0x02] = 0x00; + buf[0x03] = 0x00; + buf[0x04] = 0x01; + buf[0x05] = 0x00; + buf[0x06] = 0x85; + hid_send_feature_report(dev, buf, 513); +} + +void SteelSeriesApexMController::SetMode(unsigned char mode, std::vector colors) +{ +} + +void SteelSeriesApexMController::SetLEDsDirect(std::vector colors) +{ + unsigned char buf[513] = { 0x00 }; + int num_keys = sizeof(keys_m) / sizeof(*keys_m); + + /*-----------------------------------------------------*\ + | Set up Direct packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x00; + buf[0x01] = 0x00; + buf[0x02] = 0x00; + buf[0x03] = 0x01; + buf[0x04] = 0x8e; + buf[0x05] = 0x01; + buf[0x06] = 0x03; + buf[0x07] = 0x06; + buf[0x08] = 0x16; + + /*-----------------------------------------------------*\ + | Fill in color data | + \*-----------------------------------------------------*/ + for (int i = 0; i < num_keys; i++) + { + if (keys_m[i] == NA) + { + buf[i * 3 + 9] = 0xFF; + buf[i * 3 + 10] = 0x32; + buf[i * 3 + 11] = 0x00; + } + else + { + buf[(i * 3) + 9] = RGBGetRValue(colors[keys_m[i]]); + buf[(i * 3) + 10] = RGBGetGValue(colors[keys_m[i]]); + buf[(i * 3) + 11] = RGBGetBValue(colors[keys_m[i]]); + } + } + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 513); + +} diff --git a/Controllers/SteelSeriesController/SteelSeriesApexMController.h b/Controllers/SteelSeriesController/SteelSeriesApexMController.h new file mode 100644 index 00000000..77b3ea6b --- /dev/null +++ b/Controllers/SteelSeriesController/SteelSeriesApexMController.h @@ -0,0 +1,40 @@ +/*-----------------------------------------*\ +| SteelSeriesApexMController.h | +| | +| Definitions and types for SteelSeries | +| Apex M750 Keyboard lighting controller | +| | +| Florian Heilmann (FHeilmann) 12/10/2020 | +\*-----------------------------------------*/ + +#include "RGBController.h" +#include "SteelSeriesGeneric.h" +#include "SteelSeriesApexBaseController.h" + +#include +#include + +#pragma once + +class SteelSeriesApexMController : public SteelSeriesApexBaseController +{ +public: + SteelSeriesApexMController(hid_device* dev_handle, steelseries_type type, const char* path); + ~SteelSeriesApexMController(); + + void SetMode + ( + unsigned char mode, + std::vector colors + ); + + void SetLEDsDirect(std::vector colors); + +private: + + void EnableLEDControl(); + void SelectProfile + ( + unsigned char profile + ); +}; diff --git a/Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp b/Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp index c38bd254..f0df3f1d 100644 --- a/Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp @@ -2,6 +2,7 @@ #include "SteelSeriesRivalController.h" #include "SteelSeriesSiberiaController.h" #include "SteelSeriesApexController.h" +#include "SteelSeriesApexMController.h" #include "SteelSeriesGeneric.h" #include "RGBController.h" #include "RGBController_SteelSeriesRival.h" @@ -41,6 +42,7 @@ #define STEELSERIES_APEX_7_TKL_PID 0x1618 #define STEELSERIES_APEX_PRO_PID 0x1610 #define STEELSERIES_APEX_PRO_TKL_PID 0x1614 +#define STEELSERIES_APEX_M750_PID 0x0616 typedef struct { @@ -83,6 +85,7 @@ static const steelseries_device device_list[] = { STEELSERIES_VID, STEELSERIES_APEX_7_TKL_PID, 1, DEVICE_TYPE_KEYBOARD, APEX_TKL, "SteelSeries Apex 7 TKL" }, { STEELSERIES_VID, STEELSERIES_APEX_PRO_PID, 1, DEVICE_TYPE_KEYBOARD, APEX, "SteelSeries Apex Pro" }, { STEELSERIES_VID, STEELSERIES_APEX_PRO_TKL_PID, 1, DEVICE_TYPE_KEYBOARD, APEX_TKL, "SteelSeries Apex Pro TKL" }, + { STEELSERIES_VID, STEELSERIES_APEX_M750_PID, 2, DEVICE_TYPE_KEYBOARD, APEX_M, "SteelSeries Apex M750" }, }; /******************************************************************************************\ @@ -128,11 +131,22 @@ void DetectSteelSeriesControllers(std::vector& rgb_controllers) { case DEVICE_TYPE_KEYBOARD: { - SteelSeriesApexController* controller = new SteelSeriesApexController(dev, device_list[device_idx].proto_type, info->path); - - RGBController_SteelSeriesApex* rgb_controller = new RGBController_SteelSeriesApex(controller); - rgb_controller->name = device_list[device_idx].name; - rgb_controllers.push_back(rgb_controller); + if ((device_list[device_idx].proto_type == APEX) || (device_list[device_idx].proto_type == APEX_TKL)) { + SteelSeriesApexController* controller = new SteelSeriesApexController(dev, device_list[device_idx].proto_type, info->path); + + RGBController_SteelSeriesApex* rgb_controller = new RGBController_SteelSeriesApex(controller); + rgb_controller->name = device_list[device_idx].name; + rgb_controllers.push_back(rgb_controller); + } + else + { + SteelSeriesApexMController* controller = new SteelSeriesApexMController(dev, device_list[device_idx].proto_type, info->path); + + RGBController_SteelSeriesApex* rgb_controller = new RGBController_SteelSeriesApex(controller); + rgb_controller->name = device_list[device_idx].name; + rgb_controllers.push_back(rgb_controller); + } + } break; diff --git a/Controllers/SteelSeriesController/SteelSeriesGeneric.h b/Controllers/SteelSeriesController/SteelSeriesGeneric.h index 17765aef..a40b0f2e 100644 --- a/Controllers/SteelSeriesController/SteelSeriesGeneric.h +++ b/Controllers/SteelSeriesController/SteelSeriesGeneric.h @@ -22,5 +22,6 @@ typedef enum SIBERIA_350 = 0x03, APEX = 0x04, APEX_TKL = 0x05, + APEX_M = 0x06, } steelseries_type; diff --git a/OpenRGB.pro b/OpenRGB.pro index 99e7eb89..7534d1bf 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -246,7 +246,9 @@ HEADERS += Controllers/SinowealthController/RGBController_Sinowealth.h \ Controllers/SonyDS4Controller/SonyDS4Controller.h \ Controllers/SonyDS4Controller/RGBController_SonyDS4.h \ + Controllers/SteelSeriesController/SteelSeriesApexBaseController.h \ Controllers/SteelSeriesController/SteelSeriesApexController.h \ + Controllers/SteelSeriesController/SteelSeriesApexMController.h \ Controllers/SteelSeriesController/SteelSeriesRivalController.h \ Controllers/SteelSeriesController/SteelSeriesSiberiaController.h \ Controllers/SteelSeriesController/RGBController_SteelSeriesApex.h \ @@ -451,6 +453,7 @@ SOURCES += Controllers/SonyDS4Controller/SonyDS4ControllerDetect.cpp \ Controllers/SonyDS4Controller/RGBController_SonyDS4.cpp \ Controllers/SteelSeriesController/SteelSeriesApexController.cpp \ + Controllers/SteelSeriesController/SteelSeriesApexMController.cpp \ Controllers/SteelSeriesController/SteelSeriesRivalController.cpp \ Controllers/SteelSeriesController/SteelSeriesSiberiaController.cpp \ Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp \