Skip to content

Commit df1c0a0

Browse files
MrApplejuiceCalcProgrammer1
authored andcommitted
Initial commit for SteelSeriesApex3TKLController to resolve #1902
1 parent 8813615 commit df1c0a0

6 files changed

Lines changed: 460 additions & 0 deletions
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*-----------------------------------------*\
2+
| RGBController_SteelSeriesApex3TKL.cpp |
3+
| |
4+
| Paul K. Gerke - 27.10.2022 |
5+
| Dr_no (Chris M) |
6+
\*-----------------------------------------*/
7+
8+
#include "RGBController_SteelSeriesApex3TKL.h"
9+
10+
/**------------------------------------------------------------------*\
11+
@name Steel Series Apex 3 TKL Keyboard
12+
@category Keyboard
13+
@type USB
14+
@save :x:
15+
@direct :white_check_mark:
16+
@effects :white_check_mark:
17+
@detectors DetectSteelSeriesApex3TKL
18+
@comment
19+
\*-------------------------------------------------------------------*/
20+
21+
RGBController_SteelSeriesApex3TKL::RGBController_SteelSeriesApex3TKL(SteelSeriesApex3TKLController* controller_ptr)
22+
{
23+
controller = controller_ptr;
24+
25+
name = "Apex 3 TKL";
26+
vendor = "SteelSeries";
27+
type = DEVICE_TYPE_KEYBOARD;
28+
description = "SteelSeries Apex 3 TKL device";
29+
location = controller->GetDeviceLocation();
30+
serial = controller->GetSerialString();
31+
current_brightness = controller->GetBrightness();
32+
33+
mode direct;
34+
direct.name = "Direct";
35+
direct.value = static_cast<int>(APEX3_TKL_MODES::DIRECT);
36+
direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
37+
direct.color_mode = MODE_COLORS_PER_LED;
38+
direct.brightness_min = STEELSERIES_APEX3TKL_BRIGHTNESS_MIN;
39+
direct.brightness_max = STEELSERIES_APEX3TKL_BRIGHTNESS_MAX;
40+
direct.brightness = current_brightness;
41+
modes.push_back(direct);
42+
43+
mode rainbow;
44+
rainbow.name = "Rainbow Wave";
45+
rainbow.value = static_cast<int>(APEX3_TKL_MODES::RAINBOW);
46+
rainbow.flags = MODE_FLAG_HAS_BRIGHTNESS;
47+
rainbow.color_mode = MODE_COLORS_NONE;
48+
rainbow.brightness_min = STEELSERIES_APEX3TKL_BRIGHTNESS_MIN;
49+
rainbow.brightness_max = STEELSERIES_APEX3TKL_BRIGHTNESS_MAX;
50+
rainbow.brightness = current_brightness;
51+
modes.push_back(rainbow);
52+
53+
SetupZones();
54+
}
55+
56+
RGBController_SteelSeriesApex3TKL::~RGBController_SteelSeriesApex3TKL()
57+
{
58+
delete controller;
59+
}
60+
61+
62+
void RGBController_SteelSeriesApex3TKL::SetupZones()
63+
{
64+
zone curr_zone;
65+
curr_zone.name = "Keyboard";
66+
curr_zone.type = ZONE_TYPE_LINEAR;
67+
curr_zone.leds_min = 8;
68+
curr_zone.leds_max = 8;
69+
curr_zone.leds_count = 8;
70+
curr_zone.matrix_map = NULL;
71+
zones.push_back(curr_zone);
72+
73+
for(unsigned int i = 0; i < curr_zone.leds_count; i++)
74+
{
75+
led zone_led;
76+
zone_led.name = "LED " + std::to_string(i);
77+
leds.push_back(zone_led);
78+
}
79+
80+
SetupColors();
81+
}
82+
83+
void RGBController_SteelSeriesApex3TKL::ResizeZone(int /*zone*/, int /*new_size*/)
84+
{
85+
/*---------------------------------------------------------*\
86+
| This device does not support resizing zones |
87+
\*---------------------------------------------------------*/
88+
}
89+
90+
void RGBController_SteelSeriesApex3TKL::DeviceUpdateLEDs()
91+
{
92+
controller->SetColor(colors);
93+
UpdateBrightness();
94+
}
95+
96+
void RGBController_SteelSeriesApex3TKL::UpdateZoneLEDs(int /*zone*/)
97+
{
98+
DeviceUpdateLEDs();
99+
}
100+
101+
void RGBController_SteelSeriesApex3TKL::UpdateSingleLED(int /*led*/)
102+
{
103+
DeviceUpdateLEDs();
104+
}
105+
106+
void RGBController_SteelSeriesApex3TKL::DeviceUpdateMode()
107+
{
108+
switch (static_cast<APEX3_TKL_MODES>(active_mode)) {
109+
case APEX3_TKL_MODES::DIRECT:
110+
DeviceUpdateLEDs();
111+
break;
112+
case APEX3_TKL_MODES::RAINBOW:
113+
controller->SetRainbowMode();
114+
break;
115+
}
116+
UpdateBrightness();
117+
}
118+
119+
void RGBController_SteelSeriesApex3TKL::UpdateBrightness()
120+
{
121+
// Taken from Aerox3 Controller to prevent OpenRGB from automatically
122+
// overriding user-set brightness values via Mod+F11/F12
123+
if (current_brightness != modes[active_mode].brightness) {
124+
controller->SetBrightness(modes[active_mode].brightness);
125+
current_brightness = modes[active_mode].brightness;
126+
}
127+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*-----------------------------------------*\
2+
| RGBController_SteelSeriesApex3TKL.h |
3+
| |
4+
| Paul K. Gerke - 27.10.2022 |
5+
| Dr_no (Chris M) |
6+
\*-----------------------------------------*/
7+
8+
#pragma once
9+
10+
#include "RGBController.h"
11+
#include "SteelSeriesApex3TKLController.h"
12+
13+
enum class APEX3_TKL_MODES
14+
{
15+
DIRECT = 0,
16+
RAINBOW = 1
17+
};
18+
19+
class RGBController_SteelSeriesApex3TKL : public RGBController
20+
{
21+
public:
22+
RGBController_SteelSeriesApex3TKL(SteelSeriesApex3TKLController* apex_tzone_ptr);
23+
~RGBController_SteelSeriesApex3TKL();
24+
25+
void SetupZones();
26+
void ResizeZone(int zone, int new_size);
27+
28+
void DeviceUpdateLEDs();
29+
void UpdateZoneLEDs(int zone);
30+
void UpdateSingleLED(int led);
31+
32+
void DeviceUpdateMode();
33+
private:
34+
SteelSeriesApex3TKLController* controller;
35+
unsigned int current_brightness;
36+
37+
void UpdateBrightness();
38+
};
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*-----------------------------------------*\
2+
| SteelSeriesApex3TKLController.cpp |
3+
| |
4+
| Paul K. Gerke - 27.10.2022 |
5+
| Dr_no (Chris M) |
6+
\*-----------------------------------------*/
7+
8+
#include "SteelSeriesApex3TKLController.h"
9+
#include <cstring>
10+
#include <LogManager.h>
11+
12+
SteelSeriesApex3TKLController::SteelSeriesApex3TKLController
13+
(
14+
hid_device* dev_handle,
15+
steelseries_type proto_type,
16+
const char* path,
17+
const char* device_name
18+
)
19+
{
20+
dev = dev_handle;
21+
location = path;
22+
proto = proto_type;
23+
strcpy(this->device_name, device_name);
24+
}
25+
26+
SteelSeriesApex3TKLController::~SteelSeriesApex3TKLController()
27+
{
28+
hid_close(dev);
29+
}
30+
31+
std::string SteelSeriesApex3TKLController::GetDeviceLocation()
32+
{
33+
return("HID: " + location);
34+
}
35+
36+
char* SteelSeriesApex3TKLController::GetDeviceName()
37+
{
38+
return device_name;
39+
}
40+
41+
std::string SteelSeriesApex3TKLController::GetSerialString()
42+
{
43+
wchar_t serial_string[128];
44+
int ret = hid_get_serial_number_string(dev, serial_string, 128);
45+
46+
if (ret != 0)
47+
{
48+
return("");
49+
}
50+
51+
std::wstring return_wstring = serial_string;
52+
std::string return_string(return_wstring.begin(), return_wstring.end());
53+
54+
return(return_string);
55+
}
56+
57+
steelseries_type SteelSeriesApex3TKLController::GetKeyboardType()
58+
{
59+
return proto;
60+
}
61+
62+
void SteelSeriesApex3TKLController::SetBrightness(unsigned char brightness)
63+
{
64+
unsigned char buf[STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE];
65+
memset(buf, 0x00, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE);
66+
67+
buf[0x01] = 0x23;
68+
buf[0x02] = brightness;
69+
hid_write(dev, buf, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE);
70+
}
71+
72+
unsigned char SteelSeriesApex3TKLController::GetBrightness()
73+
{
74+
unsigned char buf[STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE];
75+
memset(buf, 0x00, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE);
76+
77+
buf[0x01] = 0xA3;
78+
hid_write(dev, buf, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE);
79+
80+
int read_back = hid_read_timeout(dev, buf, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE, 100);
81+
if (read_back >= 2 && buf[0x00] == 0xA3)
82+
{
83+
return(buf[0x01]);
84+
}
85+
LOG_ERROR("[%s] Failed load brightness; defaulting to max", device_name);
86+
return(STEELSERIES_APEX3TKL_BRIGHTNESS_MAX);
87+
}
88+
89+
void SteelSeriesApex3TKLController::SetRainbowMode()
90+
{
91+
unsigned char buf[STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE];
92+
93+
/*-----------------------------------------------------*\
94+
| Zero out buffer, set up packet and send |
95+
\*-----------------------------------------------------*/
96+
memset(buf, 0x00, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE);
97+
buf[0] = 0x00;
98+
buf[1] = 0x22;
99+
buf[2] = 0xFF;
100+
buf[3] = 0x00;
101+
buf[4] = 0x00;
102+
hid_write(dev, buf, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE);
103+
}
104+
105+
void SteelSeriesApex3TKLController::SetColor(std::vector<RGBColor> colors)
106+
{
107+
unsigned char buf[STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE];
108+
memset(buf, 0x00, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE);
109+
110+
buf[0x01] = 0x21;
111+
buf[0x02] = 0xFF;
112+
113+
for(unsigned int i = 0; i < colors.size(); i++)
114+
{
115+
uint8_t index = i * 3;
116+
117+
buf[index + 3] = RGBGetRValue(colors[i]);;
118+
buf[index + 4] = RGBGetGValue(colors[i]);;
119+
buf[index + 5] = RGBGetBValue(colors[i]);;
120+
}
121+
122+
hid_write(dev, buf, STEELSERIES_APEX3TKL_WRITE_PACKET_SIZE);
123+
}

0 commit comments

Comments
 (0)