From 2d7e996e4b80460c9d7c467c8e8e5e0191d47881 Mon Sep 17 00:00:00 2001 From: edbgon Date: Sun, 5 Jul 2020 21:50:35 +0200 Subject: [PATCH] Added initial support for SteelSeries Apex 7 Keyboard (Nordic model) --- .../SteelSeriesApexController.cpp | 117 ++++++++ .../SteelSeriesApexController.h | 44 +++ .../SteelSeriesControllerDetect.cpp | 20 +- .../SteelSeriesGeneric.h | 1 + OpenRGB.pro | 4 + .../RGBController_SteelSeriesApex.cpp | 255 ++++++++++++++++++ RGBController/RGBController_SteelSeriesApex.h | 37 +++ 7 files changed, 476 insertions(+), 2 deletions(-) create mode 100644 Controllers/SteelSeriesController/SteelSeriesApexController.cpp create mode 100644 Controllers/SteelSeriesController/SteelSeriesApexController.h create mode 100644 RGBController/RGBController_SteelSeriesApex.cpp create mode 100644 RGBController/RGBController_SteelSeriesApex.h diff --git a/Controllers/SteelSeriesController/SteelSeriesApexController.cpp b/Controllers/SteelSeriesController/SteelSeriesApexController.cpp new file mode 100644 index 000000000..e768bb88e --- /dev/null +++ b/Controllers/SteelSeriesController/SteelSeriesApexController.cpp @@ -0,0 +1,117 @@ +/*-----------------------------------------*\ +| SteelSeriesApexController.cpp | +| | +| Driver for SteelSeries Apex 7 RGB | +| Keyboard lighting controller | +| | +| Eric Samuelson (edbgon) 7/5/2020 | +\*-----------------------------------------*/ + +#include "SteelSeriesApexController.h" + +#include + +using namespace std::chrono_literals; + +static unsigned int keys[] = {0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, + 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, + 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, + 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xf0 }; + +SteelSeriesApexController::SteelSeriesApexController(hid_device* dev_handle) +{ + dev = dev_handle; +} + +SteelSeriesApexController::~SteelSeriesApexController() +{ + +} + +void SteelSeriesApexController::SetMode + ( + unsigned char mode, + std::vector colors + ) +{ + unsigned char color_mode; + unsigned char mode_colors[9]; + + active_mode = mode; + + memset(mode_colors, 0x00, sizeof(mode_colors)); + +} + +void SteelSeriesApexController::SetLEDsDirect(std::vector colors) +{ + unsigned char buf[642]; + int num_keys = sizeof(keys)/sizeof(*keys); + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Direct packet | + \*-----------------------------------------------------*/ + buf[0x00] = APEX7_PACKET_ID_DIRECT; + buf[0x01] = num_keys; + + /*-----------------------------------------------------*\ + | Fill in color data | + \*-----------------------------------------------------*/ + for(int i = 0; i < num_keys; i++) + { + buf[(i*4)+2] = keys[i]; + buf[(i*4)+3] = RGBGetRValue(colors[i]); + buf[(i*4)+4] = RGBGetGValue(colors[i]); + buf[(i*4)+5] = RGBGetBValue(colors[i]); + } + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 642); +} + +/*-------------------------------------------------------------------------------------------------*\ +| Private packet sending functions. | +\*-------------------------------------------------------------------------------------------------*/ + +void SteelSeriesApexController::SelectProfile + ( + unsigned char profile + ) +{ + unsigned char buf[64]; + + /*-----------------------------------------------------*\ + | Zero out buffer, set up first packet and send | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + buf[0x00] = 0x69; + hid_send_feature_report(dev, buf, 64); + + /*-----------------------------------------------------*\ + | Zero out buffer, set up second packet and send | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + buf[0x00] = 0x89; + buf[0x01] = profile; + hid_send_feature_report(dev, buf, 64); + + /*-----------------------------------------------------*\ + | Zero out buffer, set up third packet and send | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + buf[0x00] = 0x41; + hid_send_feature_report(dev, buf, 64); + +} diff --git a/Controllers/SteelSeriesController/SteelSeriesApexController.h b/Controllers/SteelSeriesController/SteelSeriesApexController.h new file mode 100644 index 000000000..7fee240d7 --- /dev/null +++ b/Controllers/SteelSeriesController/SteelSeriesApexController.h @@ -0,0 +1,44 @@ +/*-----------------------------------------*\ +| SteelSeriesApexController.h | +| | +| Definitions and types for SteelSeries | +| Apex 7 Keyboard lighting controller | +| | +| Eric Samuelson (edbgon) 7/5/2020 | +\*-----------------------------------------*/ + +#include "RGBController.h" + +#include +#include + +#pragma once + +enum +{ + APEX7_PACKET_ID_DIRECT = 0x3a, /* Direct mode */ +}; + +class SteelSeriesApexController +{ +public: + SteelSeriesApexController(hid_device* dev_handle); + ~SteelSeriesApexController(); + + void SetMode + ( + unsigned char mode, + std::vector colors + ); + + void SetLEDsDirect(std::vector colors); + +private: + hid_device* dev; + unsigned char active_mode; + + void SelectProfile + ( + unsigned char profile + ); +}; \ No newline at end of file diff --git a/Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp b/Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp index e7d3531c0..c574d95fe 100644 --- a/Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp @@ -1,9 +1,11 @@ #include "SteelSeriesRivalController.h" #include "SteelSeriesSiberiaController.h" +#include "SteelSeriesApexController.h" #include "SteelSeriesGeneric.h" #include "RGBController.h" #include "RGBController_SteelSeriesRival.h" #include "RGBController_SteelSeriesSiberia.h" +#include "RGBController_SteelSeriesApex.h" #include #include @@ -30,6 +32,10 @@ | Headset product IDs | \*-----------------------------------------------------*/ #define STEELSERIES_SIBERIA_350_PID 0x1229 +/*-----------------------------------------------------*\ +| Keyboard product IDs | +\*-----------------------------------------------------*/ +#define STEELSERIES_APEX_7_PID 0x1612 typedef struct { @@ -64,13 +70,17 @@ static const steelseries_device device_list[] = | Headsets | \*-----------------------------------------------------------------------------------------------------------------------------------------------------------------*/ { STEELSERIES_VID, STEELSERIES_SIBERIA_350_PID, 3, DEVICE_TYPE_HEADSET, SIBERIA_350, "SteelSeries Siberia 350" }, + /*-----------------------------------------------------------------------------------------------------------------------------------------------------------------*\ + | Keyboards | + \*-----------------------------------------------------------------------------------------------------------------------------------------------------------------*/ + { STEELSERIES_VID, STEELSERIES_APEX_7_PID, 1, DEVICE_TYPE_KEYBOARD, APEX_7, "SteelSeries Apex 7" }, }; /******************************************************************************************\ * * * DetectSteelSeriesControllers * * * -* Tests the USB address to find a SteelSeries Rival Mouse or Headset * +* Tests the USB address to find a SteelSeries Rival Mouse, Headset or Keyboard * * * \******************************************************************************************/ @@ -108,7 +118,13 @@ void DetectSteelSeriesControllers(std::vector& rgb_controllers) switch(device_list[device_idx].type) { case DEVICE_TYPE_KEYBOARD: - /* Not yet supported */ + { + SteelSeriesApexController* controller = new SteelSeriesApexController(dev); + + RGBController_SteelSeriesApex* rgb_controller = new RGBController_SteelSeriesApex(controller); + rgb_controller->name = device_list[device_idx].name; + rgb_controllers.push_back(rgb_controller); + } break; case DEVICE_TYPE_HEADSET: diff --git a/Controllers/SteelSeriesController/SteelSeriesGeneric.h b/Controllers/SteelSeriesController/SteelSeriesGeneric.h index 176d465a9..874681ba5 100644 --- a/Controllers/SteelSeriesController/SteelSeriesGeneric.h +++ b/Controllers/SteelSeriesController/SteelSeriesGeneric.h @@ -20,5 +20,6 @@ typedef enum RIVAL_100 = 0x00, RIVAL_300 = 0x01, SIBERIA_350 = 0x03, + APEX_7 = 0x04, } steelseries_type; diff --git a/OpenRGB.pro b/OpenRGB.pro index 0bb52f7f5..2cf18bd3e 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -145,6 +145,7 @@ HEADERS += \ Controllers/RedragonController/RedragonM711Controller.h \ Controllers/SteelSeriesController/SteelSeriesRivalController.h \ Controllers/SteelSeriesController/SteelSeriesSiberiaController.h \ + Controllers/SteelSeriesController/SteelSeriesApexController.h \ Controllers/ThermaltakeRiingController/ThermaltakeRiingController.h \ RGBController/RGBController.h \ RGBController/RGBController_AMDWraithPrism.h \ @@ -187,6 +188,7 @@ HEADERS += \ RGBController/RGBController_RGBFusionGPU.h \ RGBController/RGBController_SteelSeriesRival.h \ RGBController/RGBController_SteelSeriesSiberia.h \ + RGBController/RGBController_SteelSeriesApex.h \ RGBController/RGBController_ThermaltakeRiing.h \ SOURCES += \ @@ -285,6 +287,7 @@ SOURCES += \ Controllers/RedragonController/RedragonControllerDetect.cpp \ Controllers/SteelSeriesController/SteelSeriesRivalController.cpp \ Controllers/SteelSeriesController/SteelSeriesSiberiaController.cpp \ + Controllers/SteelSeriesController/SteelSeriesApexController.cpp \ Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp \ Controllers/ThermaltakeRiingController/ThermaltakeRiingController.cpp \ Controllers/ThermaltakeRiingController/ThermaltakeRiingControllerDetect.cpp \ @@ -330,6 +333,7 @@ SOURCES += \ RGBController/RGBController_RGBFusionGPU.cpp \ RGBController/RGBController_SteelSeriesRival.cpp \ RGBController/RGBController_SteelSeriesSiberia.cpp \ + RGBController/RGBController_SteelSeriesApex.cpp \ RGBController/RGBController_ThermaltakeRiing.cpp \ RESOURCES += \ diff --git a/RGBController/RGBController_SteelSeriesApex.cpp b/RGBController/RGBController_SteelSeriesApex.cpp new file mode 100644 index 000000000..923cc836d --- /dev/null +++ b/RGBController/RGBController_SteelSeriesApex.cpp @@ -0,0 +1,255 @@ +/*-----------------------------------------*\ +| RGBController_SteelSeriesApex.cpp | +| | +| Generic RGB Interface for SteelSeries | +| Apex 7 Keyboard | +| | +| Eric Samuelson (edbgon) 7/5/2020 | +\*-----------------------------------------*/ + +#include "RGBController_SteelSeriesApex.h" + +//Include thread libraries for Windows or Linux +#ifdef WIN32 +#include +#else +#include "pthread.h" +#include "unistd.h" +#endif + +using namespace std::chrono_literals; + +//0xFFFFFFFF indicates an unused entry in matrix +#define NA 0xFFFFFFFF + +static unsigned int matrix_map[6][23] = //TODO: Create proper matrix map + { { 0, NA, 16, 30, 44, 54, NA, 65, 75, 84, 95, NA, 8, 23 , 38, 6 , 22, 36, 49, NA, NA, NA, NA }, + { 1, 17, 31, 45, 55, 66, 76, 85, 96, 9, 24, NA, 39, 7 , 37, NA , 60, 70, 80, 52, 63, 73, 82 }, + { 2, NA, 18, 32, 46, 56, NA, 67, 77, 86, 97, 10, 25, 40 , 90, 101, 50, 61, 71, 51, 62, 72, 93 }, + { 3, NA, 19, 33, 47, 57, NA, 68, 78, 87, 98, 11, 26, 41 , 28, 14 , NA, NA, NA, 92, 103, 53, NA }, + { 4, 20, 34, 48, 58, 69, NA, 79, NA, 88, 99, 12, 27, 42 , 81, NA , NA, 102, NA, 64, 74, 83, 104 }, + { 5, 21, 35, NA, NA, NA, NA, 59, NA, NA, NA, NA, 89, 100, 13, 91 , 15, 29, 43, 94, NA, 105, NA } }; + +static const char* zone_names[] = +{ + "Keyboard" +}; + +static zone_type zone_types[] = +{ + ZONE_TYPE_MATRIX +}; + +static const unsigned int zone_sizes[] = +{ + 105, +}; + +static const char *led_names[] = +{ + "Key: A", + "Key: B", + "Key: C", + "Key: D", + "Key: E", + "Key: F", + "Key: G", + "Key: H", + "Key: I", + "Key: J", + "Key: K", + "Key: L", + "Key: M", + "Key: N", + "Key: O", + "Key: P", + "Key: Q", + "Key: R", + "Key: S", + "Key: T", + "Key: U", + "Key: V", + "Key: W", + "Key: X", + "Key: Y", + "Key: Z", + "Key: 1", + "Key: 2", + "Key: 3", + "Key: 4", + "Key: 5", + "Key: 6", + "Key: 7", + "Key: 8", + "Key: 9", + "Key: 0", + "Key: Enter", + "Key: Escape", + "Key: Backspace", + "Key: Tab", + "Key: Space", + "Key: +", // TODO: Find international name for this key + "Key: \\", // TODO: Find international name for this key + "Key: Å", // TODO: Find international name for this key + "Key: ¨", // TODO: Find international name for this key + "Key: '", // TODO: Find international name for this key + "Key: Ø", // TODO: Find international name for this key + "Key: Æ", // TODO: Find international name for this key + "Key: |", // TODO: Find international name for this key + "Key: ,", + "Key: .", + "Key: -", + "Key: Caps Lock", + "Key: F1", + "Key: F2", + "Key: F3", + "Key: F4", + "Key: F5", + "Key: F6", + "Key: F7", + "Key: F8", + "Key: F9", + "Key: F10", + "Key: F11", + "Key: F12", + "Key: Print Screen", + "Key: Scroll Lock", + "Key: Pause", + "Key: Insert", + "Key: Home", + "Key: Page Up", + "Key: Delete", + "Key: End", + "Key: Page Down", + "Key: Right Arrow", + "Key: Left Arrow", + "Key: Down Arrow", + "Key: Up Arrow", + "Key: Num Lock", + "Key: Number Pad /", + "Key: Number Pad *", + "Key: Number Pad -", + "Key: Number Pad +", + "Key: Number Pad Enter", + "Key: Number Pad 1", + "Key: Number Pad 2", + "Key: Number Pad 3", + "Key: Number Pad 4", + "Key: Number Pad 5", + "Key: Number Pad 6", + "Key: Number Pad 7", + "Key: Number Pad 8", + "Key: Number Pad 9", + "Key: Number Pad 0", + "Key: Number Pad .", + "Key: <", // TODO: Find international name for this + "Key: Left Control", + "Key: Left Shift", + "Key: Left Alt", + "Key: Left Super", + "Key: Right Control", + "Key: Right Shift", + "Key: Right Alt", + "Key: Right Super", + "Key: FN", +}; + +RGBController_SteelSeriesApex::RGBController_SteelSeriesApex(SteelSeriesApexController* steelseries_ptr) +{ + steelseries = steelseries_ptr; + + name = "SteelSeries Apex 7 RGB Keyboard"; + type = DEVICE_TYPE_KEYBOARD; + description = "SteelSeries Apex 7 RGB Device"; + + mode Direct; + Direct.name = "Direct"; + Direct.value = 0x00; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Direct); + + SetupZones(); + +} + +RGBController_SteelSeriesApex::~RGBController_SteelSeriesApex() +{ + +} + +void RGBController_SteelSeriesApex::SetupZones() +{ + /*---------------------------------------------------------*\ + | Set up zones | + \*---------------------------------------------------------*/ + unsigned int total_led_count = 0; + for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++) + { + zone new_zone; + new_zone.name = zone_names[zone_idx]; + new_zone.type = zone_types[zone_idx]; + new_zone.leds_min = zone_sizes[zone_idx]; + new_zone.leds_max = zone_sizes[zone_idx]; + new_zone.leds_count = zone_sizes[zone_idx]; + + if(zone_types[zone_idx] == ZONE_TYPE_MATRIX) + { + new_zone.matrix_map = new matrix_map_type; + new_zone.matrix_map->height = 6; + new_zone.matrix_map->width = 23; + new_zone.matrix_map->map = (unsigned int *)&matrix_map; + } + else + { + new_zone.matrix_map = NULL; + } + + zones.push_back(new_zone); + + total_led_count += zone_sizes[zone_idx]; + } + + for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++) + { + led new_led; + new_led.name = led_names[led_idx]; + leds.push_back(new_led); + } + + SetupColors(); +} + +void RGBController_SteelSeriesApex::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_SteelSeriesApex::DeviceUpdateLEDs() +{ + last_update_time = std::chrono::steady_clock::now(); + steelseries->SetLEDsDirect(colors); +} + +void RGBController_SteelSeriesApex::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_SteelSeriesApex::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_SteelSeriesApex::SetCustomMode() +{ + active_mode = 0; +} + +void RGBController_SteelSeriesApex::UpdateMode() +{ + std::vector temp_colors; + steelseries->SetMode(modes[active_mode].value, temp_colors); +} diff --git a/RGBController/RGBController_SteelSeriesApex.h b/RGBController/RGBController_SteelSeriesApex.h new file mode 100644 index 000000000..88567d74d --- /dev/null +++ b/RGBController/RGBController_SteelSeriesApex.h @@ -0,0 +1,37 @@ +/*-----------------------------------------*\ +| RGBController_SteelSeriesApex.cpp | +| | +| Generic RGB Interface for SteelSeries | +| Apex 7 Keyboard | +| | +| Eric Samuelson (edbgon) 7/5/2020 | +\*-----------------------------------------*/ + +#pragma once +#include + +#include "RGBController.h" +#include "SteelSeriesApexController.h" + +class RGBController_SteelSeriesApex : public RGBController +{ +public: + RGBController_SteelSeriesApex(SteelSeriesApexController* steelseries_ptr); + ~RGBController_SteelSeriesApex(); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void UpdateMode(); + +private: + SteelSeriesApexController* steelseries; + + std::chrono::time_point last_update_time; +};