Publish LumaOps source
This commit is contained in:
+463
@@ -0,0 +1,463 @@
|
||||
/*------------------------------------------*\
|
||||
| RGBController_SinowealthKeyboard16.cpp |
|
||||
| |
|
||||
| Definitions and types for Sinowealth |
|
||||
| Keyboard with PID:0016, |
|
||||
| Hopefully generic for this PID, |
|
||||
| this was made spefically for ZUOYA X51 |
|
||||
| |
|
||||
| Zagorodnikov Aleksey (glooom) 26.07.2021 |
|
||||
| based on initial implementation from |
|
||||
| Dmitri Kalinichenko (Dima-Kal) 23/06/2021 |
|
||||
\*-----------------------------------------=*/
|
||||
|
||||
#include "RGBControllerKeyNames.h"
|
||||
#include "RGBController_SinowealthKeyboard16.h"
|
||||
#include <algorithm>
|
||||
|
||||
#define NA 0xFFFFFFFF
|
||||
|
||||
using namespace kbd16;
|
||||
|
||||
static unsigned int matrix_map[6][22] =
|
||||
{ { 0, NA, 2, 3, 4, 5, NA, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, NA, NA, NA, NA },
|
||||
{ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, NA, 36, 37, 38, 39, 40, 41, 42, 43 },
|
||||
{ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, NA, 59, 60, 61, 62, 63, 64, 65 },
|
||||
{ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, NA, 79, NA, NA, NA, NA, 84, 85, 86, 87 },
|
||||
{ 88, NA, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, NA, NA, 102, NA, 104, NA, 106, 107, 108, 109 },
|
||||
{ 110, 111, 112, NA, NA, 115, NA, NA, 118, 119, 120, NA, 122, NA, NA, 125, 126, 127, 128, 129, 130, 131 }
|
||||
};
|
||||
|
||||
static const char *led_names_tkl[] =
|
||||
{
|
||||
KEY_EN_ESCAPE,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_F1,
|
||||
KEY_EN_F2,
|
||||
KEY_EN_F3,
|
||||
KEY_EN_F4,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_F5,
|
||||
KEY_EN_F6,
|
||||
KEY_EN_F7,
|
||||
KEY_EN_F8,
|
||||
KEY_EN_F9,
|
||||
KEY_EN_F10,
|
||||
KEY_EN_F11,
|
||||
KEY_EN_F12,
|
||||
KEY_EN_PRINT_SCREEN,
|
||||
KEY_EN_SCROLL_LOCK,
|
||||
KEY_EN_PAUSE_BREAK,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
|
||||
KEY_EN_BACK_TICK,
|
||||
KEY_EN_1,
|
||||
KEY_EN_2,
|
||||
KEY_EN_3,
|
||||
KEY_EN_4,
|
||||
KEY_EN_5,
|
||||
KEY_EN_6,
|
||||
KEY_EN_7,
|
||||
KEY_EN_8,
|
||||
KEY_EN_9,
|
||||
KEY_EN_0,
|
||||
KEY_EN_MINUS,
|
||||
KEY_EN_EQUALS,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_BACKSPACE,
|
||||
KEY_EN_INSERT,
|
||||
KEY_EN_HOME,
|
||||
KEY_EN_PAGE_UP,
|
||||
KEY_EN_NUMPAD_LOCK,
|
||||
KEY_EN_NUMPAD_DIVIDE,
|
||||
KEY_EN_NUMPAD_TIMES,
|
||||
KEY_EN_NUMPAD_MINUS,
|
||||
|
||||
KEY_EN_TAB,
|
||||
KEY_EN_Q,
|
||||
KEY_EN_W,
|
||||
KEY_EN_E,
|
||||
KEY_EN_R,
|
||||
KEY_EN_T,
|
||||
KEY_EN_Y,
|
||||
KEY_EN_U,
|
||||
KEY_EN_I,
|
||||
KEY_EN_O,
|
||||
KEY_EN_P,
|
||||
KEY_EN_LEFT_BRACKET,
|
||||
KEY_EN_RIGHT_BRACKET,
|
||||
KEY_EN_ANSI_BACK_SLASH,
|
||||
KEY_EN_UNUSED,
|
||||
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,
|
||||
KEY_EN_A,
|
||||
KEY_EN_S,
|
||||
KEY_EN_D,
|
||||
KEY_EN_F,
|
||||
KEY_EN_G,
|
||||
KEY_EN_H,
|
||||
KEY_EN_J,
|
||||
KEY_EN_K,
|
||||
KEY_EN_L,
|
||||
KEY_EN_SEMICOLON,
|
||||
KEY_EN_QUOTE,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_ANSI_ENTER,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_NUMPAD_4,
|
||||
KEY_EN_NUMPAD_5,
|
||||
KEY_EN_NUMPAD_6,
|
||||
KEY_EN_NUMPAD_PLUS,
|
||||
|
||||
KEY_EN_LEFT_SHIFT,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_Z,
|
||||
KEY_EN_X,
|
||||
KEY_EN_C,
|
||||
KEY_EN_V,
|
||||
KEY_EN_B,
|
||||
KEY_EN_N,
|
||||
KEY_EN_M,
|
||||
KEY_EN_COMMA,
|
||||
KEY_EN_PERIOD,
|
||||
KEY_EN_FORWARD_SLASH,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_RIGHT_SHIFT,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UP_ARROW,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_NUMPAD_1,
|
||||
KEY_EN_NUMPAD_2,
|
||||
KEY_EN_NUMPAD_3,
|
||||
KEY_EN_NUMPAD_ENTER,
|
||||
|
||||
KEY_EN_LEFT_CONTROL,
|
||||
KEY_EN_LEFT_WINDOWS,
|
||||
KEY_EN_LEFT_ALT,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_SPACE,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_RIGHT_ALT,
|
||||
KEY_EN_RIGHT_FUNCTION,
|
||||
KEY_EN_RIGHT_WINDOWS,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_RIGHT_CONTROL,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_UNUSED,
|
||||
KEY_EN_LEFT_ARROW,
|
||||
KEY_EN_DOWN_ARROW,
|
||||
KEY_EN_RIGHT_ARROW,
|
||||
KEY_EN_NUMPAD_0,
|
||||
KEY_EN_NUMPAD_0,
|
||||
KEY_EN_NUMPAD_PERIOD,
|
||||
KEY_EN_NUMPAD_ENTER
|
||||
};
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Sinowealth Keyboard 16
|
||||
@category Keyboard
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :x:
|
||||
@effects :white_check_mark:
|
||||
@detectors DetectSinowealthKeyboard
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_SinowealthKeyboard16::RGBController_SinowealthKeyboard16(SinowealthKeyboard16Controller* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetName();
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "Sinowealth Keyboard Device";
|
||||
location = controller->GetLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
std::vector<ModeCfg> modes_cfg = controller->GetDeviceModes();
|
||||
std::vector<ModeColorCfg> color_presets = controller->GetDeviceColors();
|
||||
|
||||
int mode_id = 0;
|
||||
|
||||
for(const ModeCfg &cfg : modes_cfg)
|
||||
{
|
||||
mode Mode = getModeItem(mode_id);
|
||||
|
||||
Mode.brightness = cfg.brightness;
|
||||
Mode.speed = cfg.speed;
|
||||
Mode.direction = cfg.direction_left;
|
||||
|
||||
if(cfg.color == COLOR_PRESET_RANDOM)
|
||||
{
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
}
|
||||
else
|
||||
{
|
||||
Mode.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
}
|
||||
|
||||
ModeColorCfg mode_color = color_presets[mode_id];
|
||||
|
||||
for(unsigned int i = Mode.colors_min; i < Mode.colors_max; i++)
|
||||
{
|
||||
RGBColor color = (mode_color.preset[i].blue << 16) | (mode_color.preset[i].green << 8) | (mode_color.preset[i].red);
|
||||
Mode.colors.push_back(color);
|
||||
}
|
||||
|
||||
modes.push_back(Mode);
|
||||
mode_id++;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
| This keyboard supports 5 configurable custom profiles. |
|
||||
| The first one is named "Custom" and the others are "Custom 2" to |
|
||||
| "Custom 5". Leaving the first one just "Custom" to adhere to |
|
||||
| common mode names scheme. |
|
||||
\*-----------------------------------------------------------------*/
|
||||
for(unsigned int i = 0; i < 5; i++)
|
||||
{
|
||||
mode PerLed;
|
||||
|
||||
PerLed.name = "Custom";
|
||||
|
||||
if(i > 0)
|
||||
{
|
||||
PerLed.name += " " + std::to_string(i + 1);
|
||||
}
|
||||
|
||||
PerLed.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
PerLed.color_mode = MODE_COLORS_PER_LED;
|
||||
PerLed.value = MODE_PER_KEY1+i;
|
||||
|
||||
modes.push_back(PerLed);
|
||||
}
|
||||
|
||||
SetupZones();
|
||||
|
||||
int device_mode = controller->GetCurrentMode();
|
||||
|
||||
if(device_mode >= MODE_PER_KEY1)
|
||||
{
|
||||
device_mode = mode_id+(device_mode & 0x0F);
|
||||
colors = controller->GetPerLedColors();
|
||||
}
|
||||
|
||||
active_mode = device_mode;
|
||||
}
|
||||
|
||||
RGBController_SinowealthKeyboard16::~RGBController_SinowealthKeyboard16()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
mode RGBController_SinowealthKeyboard16::getModeItem(unsigned int mode_id)
|
||||
{
|
||||
mode Mode;
|
||||
|
||||
Mode.value = mode_id;
|
||||
Mode.brightness_min = BRIGHTNESS_OFF;
|
||||
Mode.brightness_max = BRIGHTNESS_FULL;
|
||||
Mode.speed_min = SPEED_SLOW;
|
||||
Mode.speed_max = SPEED_FASTEST;
|
||||
Mode.colors_min = 0;
|
||||
Mode.colors_max = COLOR_PRESETS_IN_MODE;
|
||||
|
||||
switch(mode_id)
|
||||
{
|
||||
case 0:
|
||||
Mode.name = "Off";
|
||||
Mode.flags = 0;
|
||||
Mode.color_mode = MODE_COLORS_NONE;
|
||||
break;
|
||||
case 1:
|
||||
Mode.name = "Spectrum Cycle";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Mode.color_mode = MODE_COLORS_NONE;
|
||||
break;
|
||||
case 2:
|
||||
Mode.name = "Breathing";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 3:
|
||||
Mode.name = "Static";
|
||||
Mode.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 4:
|
||||
Mode.name = "Ripples Shining";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 5:
|
||||
Mode.name = "Reactive";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 6:
|
||||
Mode.name = "Flash Away";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 7:
|
||||
Mode.name = "Sine Wave";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 8:
|
||||
Mode.name = "Raindrops";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 9:
|
||||
Mode.name = "Rainbow Wave";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_DIRECTION_LR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 10:
|
||||
Mode.name = "Rainbow Wheel";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_DIRECTION_LR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 11:
|
||||
Mode.name = "Adorn";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 12:
|
||||
Mode.name = "Stars Twinkle";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 13:
|
||||
Mode.name = "Shadow Disappear";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
case 14:
|
||||
Mode.name = "Retro Snake";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
default:
|
||||
Mode.name = "Unknown Mode";
|
||||
Mode.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Mode.color_mode = MODE_COLORS_RANDOM;
|
||||
break;
|
||||
}
|
||||
|
||||
return Mode;
|
||||
}
|
||||
|
||||
void RGBController_SinowealthKeyboard16::SetupZones()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Set up zones |
|
||||
\*---------------------------------------------------------*/
|
||||
zone new_zone;
|
||||
|
||||
new_zone.name = ZONE_EN_KEYBOARD;
|
||||
new_zone.type = ZONE_TYPE_MATRIX;
|
||||
new_zone.leds_count = controller->GetLEDCount();
|
||||
new_zone.leds_min = new_zone.leds_count;
|
||||
new_zone.leds_max = new_zone.leds_count;
|
||||
new_zone.matrix_map = new matrix_map_type;
|
||||
new_zone.matrix_map->height = 6;
|
||||
new_zone.matrix_map->width = 22;
|
||||
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
|
||||
|
||||
zones.push_back(new_zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Set up LEDs |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int led_idx = 0; led_idx < new_zone.leds_count; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
new_led.name = led_names_tkl[led_idx];
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_SinowealthKeyboard16::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_SinowealthKeyboard16::DeviceUpdateLEDs()
|
||||
{
|
||||
controller->SetLEDsDirect(colors);
|
||||
}
|
||||
|
||||
void RGBController_SinowealthKeyboard16::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_SinowealthKeyboard16::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_SinowealthKeyboard16::DeviceUpdateMode()
|
||||
{
|
||||
mode ActiveMode = modes[active_mode];
|
||||
|
||||
int color_mode;
|
||||
|
||||
if(ActiveMode.color_mode == MODE_COLORS_MODE_SPECIFIC)
|
||||
{
|
||||
color_mode = COLOR_PRESET_0;
|
||||
}
|
||||
else
|
||||
{
|
||||
color_mode = COLOR_PRESET_RANDOM;
|
||||
}
|
||||
|
||||
controller->ClearMode();
|
||||
|
||||
if(ActiveMode.colors.size())
|
||||
{
|
||||
controller->SetColorsForMode(ActiveMode.value, &ActiveMode.colors[0]);
|
||||
}
|
||||
|
||||
controller->SetMode(ActiveMode.value, ActiveMode.brightness, ActiveMode.speed, ActiveMode.direction, color_mode);
|
||||
|
||||
if(ActiveMode.value >= MODE_PER_KEY1)
|
||||
{
|
||||
colors = controller->GetPerLedColors();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(color_mode == COLOR_PRESET_RANDOM)
|
||||
{
|
||||
std::generate(colors.begin(), colors.end(), std::rand);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::fill(colors.begin(), colors.end(), ActiveMode.colors[0]);
|
||||
}
|
||||
}
|
||||
|
||||
SignalUpdate();
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*------------------------------------------*\
|
||||
| RGBController_SinowealthKeyboard16.h |
|
||||
| |
|
||||
| Definitions and types for Sinowealth |
|
||||
| Keyboard with PID:0016, |
|
||||
| Hopefully generic for this PID, |
|
||||
| this was made spefically for ZUOYA X51 |
|
||||
| |
|
||||
| Zagorodnikov Aleksey (glooom) 26.07.2021 |
|
||||
| based on initial implementation from |
|
||||
| Dmitri Kalinichenko (Dima-Kal) 23/06/2021 |
|
||||
\*-----------------------------------------=*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "SinowealthKeyboard16Controller.h"
|
||||
|
||||
class RGBController_SinowealthKeyboard16 : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_SinowealthKeyboard16(SinowealthKeyboard16Controller* controller_ptr);
|
||||
~RGBController_SinowealthKeyboard16();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
SinowealthKeyboard16Controller* controller;
|
||||
|
||||
mode getModeItem(unsigned int mode_id);
|
||||
};
|
||||
+340
@@ -0,0 +1,340 @@
|
||||
/*------------------------------------------*\
|
||||
| SinowealthKeyboard16Controller.cpp |
|
||||
| |
|
||||
| Definitions and types for Sinowealth |
|
||||
| Keyboard with PID:0016, |
|
||||
| Hopefully generic for this PID, |
|
||||
| this was made spefically for ZUOYA X51 |
|
||||
| |
|
||||
| Zagorodnikov Aleksey (glooom) 26.07.2021 |
|
||||
| based on initial implementation from |
|
||||
| Dmitri Kalinichenko (Dima-Kal) 23/06/2021 |
|
||||
\*-----------------------------------------=*/
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include "LogManager.h"
|
||||
#include "SinowealthKeyboard16Controller.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace kbd16;
|
||||
|
||||
static unsigned char request_init[] = {0x05, 0x01, 0xAA, 0xBB, 0x2F, 0x3E};
|
||||
static unsigned char request_modes[] = {0x05, 0x83, 0x00, 0x00, 0x00, 0x00};
|
||||
static unsigned char request_colors[] = {0x05, 0x88, 0xA8, 0x00, 0x40, 0x00};
|
||||
static unsigned char request_per_led_cm12[] = {0x05, 0x89, 0xAC, 0x00, 0x40, 0x00};
|
||||
static unsigned char request_per_led_cm34[] = {0x05, 0x89, 0xB0, 0x00, 0x40, 0x00};
|
||||
static unsigned char request_per_led_cm5[] = {0x05, 0x89, 0xB4, 0x00, 0x40, 0x00};
|
||||
|
||||
|
||||
SinowealthKeyboard16Controller::SinowealthKeyboard16Controller(hid_device* cmd_handle, hid_device* data_handle, char* path, std::string dev_name)
|
||||
{
|
||||
dev_cmd = cmd_handle;
|
||||
dev_data = data_handle;
|
||||
name = dev_name;
|
||||
|
||||
led_count = 132;
|
||||
|
||||
current_mode = MODE_OFF;
|
||||
location = path;
|
||||
|
||||
memset(mode_config_buf, 0x00, sizeof(mode_config_buf));
|
||||
|
||||
initCommunication();
|
||||
UpdateConfigurationFromDevice();
|
||||
}
|
||||
|
||||
SinowealthKeyboard16Controller::~SinowealthKeyboard16Controller()
|
||||
{
|
||||
hid_close(dev_cmd);
|
||||
hid_close(dev_data);
|
||||
}
|
||||
|
||||
std::string SinowealthKeyboard16Controller::GetLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string SinowealthKeyboard16Controller::GetName()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
unsigned char SinowealthKeyboard16Controller::GetCurrentMode()
|
||||
{
|
||||
return current_mode;
|
||||
}
|
||||
|
||||
unsigned int SinowealthKeyboard16Controller::GetLEDCount()
|
||||
{
|
||||
return led_count;
|
||||
}
|
||||
|
||||
std::string SinowealthKeyboard16Controller::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev_cmd, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
return(StringUtils::wstring_to_string(serial_string));
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::SetLEDsDirect(std::vector<RGBColor> colors)
|
||||
{
|
||||
const int colors_offset = led_count;
|
||||
int i = colors_start_idx;
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
| CM2 and CM4 presets are located in second half of corresponding arrays |
|
||||
\*-------------------------------------------------------------------------*/
|
||||
if(current_custom_preset == 1 || current_custom_preset == 3)
|
||||
{
|
||||
i += (led_count * 3);
|
||||
}
|
||||
|
||||
for(const RGBColor &color : colors)
|
||||
{
|
||||
per_button_color_buf[i] = RGBGetBValue(color);
|
||||
per_button_color_buf[i + colors_offset] = RGBGetGValue(color);
|
||||
per_button_color_buf[i + colors_offset + colors_offset] = RGBGetRValue(color);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
sendConfig(per_button_color_buf);
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::SetMode(unsigned char mode, unsigned char brightness, unsigned char speed, bool direction_left, unsigned char color_mode)
|
||||
{
|
||||
if(mode >= MODE_PER_KEY1)
|
||||
{
|
||||
current_custom_preset = (mode & 0x0F);
|
||||
mode_config_buf[current_mode_idx] = MODE_PER_KEY;
|
||||
mode_config_buf[per_key_mode_idx] = 1;
|
||||
mode_config_buf[current_mode_idx+1] = (0x20 | current_custom_preset);
|
||||
|
||||
GetButtonColorsConfig(per_button_color_buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
mode_config_buf[current_mode_idx] = mode;
|
||||
device_modes[mode].brightness = brightness;
|
||||
device_modes[mode].speed = speed;
|
||||
device_modes[mode].color = color_mode;
|
||||
device_modes[mode].direction_left = direction_left;
|
||||
mode_config_buf[per_key_mode_idx] = 0;
|
||||
}
|
||||
|
||||
if(sendConfig(mode_config_buf))
|
||||
{
|
||||
current_mode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::SetColorsForMode(unsigned char mode, RGBColor *profiles)
|
||||
{
|
||||
if(mode >= MODE_PER_KEY1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < COLOR_PRESETS_IN_MODE; i++)
|
||||
{
|
||||
modes_colors[mode].preset[i].red = RGBGetRValue(profiles[i]);
|
||||
modes_colors[mode].preset[i].green = RGBGetGValue(profiles[i]);
|
||||
modes_colors[mode].preset[i].blue = RGBGetBValue(profiles[i]);
|
||||
}
|
||||
|
||||
sendConfig(colors_config_buf);
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::ClearMode()
|
||||
{
|
||||
mode_config_buf[per_key_mode_idx] = 0;
|
||||
mode_config_buf[current_mode_idx] = 0;
|
||||
mode_config_buf[current_mode_idx+1] = 0;
|
||||
|
||||
sendConfig(mode_config_buf);
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Before apply new settings, keyboard needs turn off LEDs and wait |
|
||||
| ~200ms, otherwise sometime glitches happens. |
|
||||
\*-----------------------------------------------------------------*/
|
||||
std::this_thread::sleep_for(200ms);
|
||||
}
|
||||
|
||||
std::vector<ModeCfg> SinowealthKeyboard16Controller::GetDeviceModes()
|
||||
{
|
||||
std::vector<ModeCfg> modes;
|
||||
|
||||
for(int i = 0; i < profiles_count; i++)
|
||||
{
|
||||
modes.push_back(device_modes[i]);
|
||||
}
|
||||
|
||||
return modes;
|
||||
}
|
||||
|
||||
std::vector<ModeColorCfg> SinowealthKeyboard16Controller::GetDeviceColors()
|
||||
{
|
||||
std::vector<ModeColorCfg> presets;
|
||||
|
||||
for(int i = 0; i < profiles_count; i++)
|
||||
{
|
||||
presets.push_back(modes_colors[i]);
|
||||
}
|
||||
|
||||
return presets;
|
||||
}
|
||||
|
||||
std::vector<RGBColor> SinowealthKeyboard16Controller::GetPerLedColors()
|
||||
{
|
||||
const int colors_offset = led_count;
|
||||
int start_idx = colors_start_idx;
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
| CM2 and CM4 presets are located in second half of corresponding arrays |
|
||||
\*-------------------------------------------------------------------------*/
|
||||
if(current_custom_preset == 1 || current_custom_preset == 3)
|
||||
{
|
||||
start_idx += (led_count * 3);
|
||||
}
|
||||
|
||||
std::vector<RGBColor> res;
|
||||
res.resize(led_count);
|
||||
|
||||
for(unsigned int i = 0; i < led_count; i++)
|
||||
{
|
||||
RGBColor color = (per_button_color_buf[start_idx+i] << 16)
|
||||
| (per_button_color_buf[start_idx+i+colors_offset] << 8)
|
||||
| (per_button_color_buf[start_idx+i+colors_offset+colors_offset]);
|
||||
|
||||
res[i] = color;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::UpdateConfigurationFromDevice()
|
||||
{
|
||||
GetModesConfig(mode_config_buf);
|
||||
GetColorsConfig(colors_config_buf);
|
||||
|
||||
current_mode = mode_config_buf[current_mode_idx];
|
||||
device_modes = (struct ModeCfg*) &mode_config_buf[profiles_start_idx];
|
||||
modes_colors = (struct ModeColorCfg*) &colors_config_buf[colors_start_idx];
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
| When OEM software switch keyboard to custom mode it set 0x0F into 0x15 |
|
||||
| byte and 01 into 0x14 byte. However if user manually switch to this mode |
|
||||
| through Fn+1 the keyboard only sets 0x14 byte by itself, but not touched |
|
||||
| 0x15 byte. Not sure what part is more important, so managing both bytes. |
|
||||
\*-------------------------------------------------------------------------*/
|
||||
if(current_mode == MODE_PER_KEY || mode_config_buf[per_key_mode_idx] == 1)
|
||||
{
|
||||
current_custom_preset = (mode_config_buf[current_mode_idx+1] & 0x0F);
|
||||
current_mode = ((MODE_PER_KEY&0xF) << 4) | current_custom_preset;
|
||||
|
||||
GetButtonColorsConfig(per_button_color_buf);
|
||||
}
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::GetModesConfig(unsigned char *buf)
|
||||
{
|
||||
if(!getConfig(request_modes, buf))
|
||||
{
|
||||
LOG_ERROR("[%s] Could not read modes config table", name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::GetColorsConfig(unsigned char *buf)
|
||||
{
|
||||
if(!getConfig(request_colors, buf))
|
||||
{
|
||||
LOG_ERROR("[%s] Could not read colors config table", name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::GetButtonColorsConfig(unsigned char *buf)
|
||||
{
|
||||
unsigned char *req;
|
||||
|
||||
switch(current_custom_preset)
|
||||
{
|
||||
case 2: // CM3
|
||||
case 3: // CM4
|
||||
req = request_per_led_cm34;
|
||||
break;
|
||||
case 4: // CM5
|
||||
req = request_per_led_cm5;
|
||||
break;
|
||||
case 0: // CM1
|
||||
case 1: // CM2
|
||||
default:
|
||||
req = request_per_led_cm12;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!getConfig(req, buf))
|
||||
{
|
||||
LOG_ERROR("[%s] Could not read per LED config table", name.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void SinowealthKeyboard16Controller::initCommunication()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This needs to be sent first time after powerup keyboard. |
|
||||
\*---------------------------------------------------------*/
|
||||
hid_send_feature_report(dev_cmd, request_init, 6);
|
||||
}
|
||||
|
||||
bool SinowealthKeyboard16Controller::getConfig(unsigned char *request, unsigned char *buf)
|
||||
{
|
||||
hid_send_feature_report(dev_cmd, request, 6);
|
||||
|
||||
unsigned char response[PAYLOAD_LEN];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*---------------------------------------------------------*/
|
||||
memset(response, 0x00, PAYLOAD_LEN);
|
||||
|
||||
response[0] = 0x06;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the response and put it in the response buffer |
|
||||
\*---------------------------------------------------------*/
|
||||
if(hid_get_feature_report(dev_data, response, PAYLOAD_LEN) != -1)
|
||||
{
|
||||
response[1] &= ~0x80; // Clear response flag
|
||||
response[2] = request[2];
|
||||
response[3] = request[3];
|
||||
response[4] = request[4];
|
||||
response[5] = request[5];
|
||||
memcpy(buf,response,PAYLOAD_LEN);
|
||||
read_config_error = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
read_config_error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SinowealthKeyboard16Controller::sendConfig(unsigned char *buf)
|
||||
{
|
||||
if(read_config_error)
|
||||
{
|
||||
LOG_ERROR("[%s] Can't send new config if reading old config fail", name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int result = hid_send_feature_report(dev_data, buf, PAYLOAD_LEN);
|
||||
return (result != -1);
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
/*------------------------------------------*\
|
||||
| SinowealthKeyboard16Controller.h |
|
||||
| |
|
||||
| Definitions and types for Sinowealth |
|
||||
| Keyboard with PID:0016, |
|
||||
| Hopefully generic for this PID, |
|
||||
| this was made spefically for ZUOYA X51 |
|
||||
| |
|
||||
| Zagorodnikov Aleksey (glooom) 26.07.2021 |
|
||||
| based on initial implementation from |
|
||||
| Dmitri Kalinichenko (Dima-Kal) 23/06/2021 |
|
||||
\*-----------------------------------------=*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <vector>
|
||||
#include <hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
#define PAYLOAD_LEN 1032
|
||||
#define COLOR_PRESETS_IN_MODE 7
|
||||
|
||||
namespace kbd16
|
||||
{
|
||||
enum
|
||||
{
|
||||
MODE_OFF = 0,
|
||||
/*
|
||||
MODE_COLOR_LOOP = 1,
|
||||
MODE_RESPIRE = 2,
|
||||
MODE_STATIC = 3,
|
||||
MODE_RIPPLES_SHINING = 4,
|
||||
MODE_REACTION = 5,
|
||||
MODE_FLASH_AWAY = 6,
|
||||
MODE_SINE_WAVE = 7,
|
||||
MODE_RAINDROPS = 8,
|
||||
MODE_NEON_STREAM = 9,
|
||||
MODE_RAINBOW_WHEEL = 10,
|
||||
MODE_ADORN = 11,
|
||||
MODE_STARS_TWINKLE = 12,
|
||||
MODE_SHADOW_DISAPPEAR = 13,
|
||||
MODE_RETRO_SNAKE = 14,
|
||||
*/
|
||||
MODE_PER_KEY = 0x0F, // General mode for custom presets
|
||||
MODE_PER_KEY1 = 0xF0,
|
||||
MODE_PER_KEY2 = 0xF1,
|
||||
MODE_PER_KEY3 = 0xF2,
|
||||
MODE_PER_KEY4 = 0xF3,
|
||||
MODE_PER_KEY5 = 0xF4,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SPEED_SLOW = 0x00,
|
||||
SPEED_NORMAL = 0x01,
|
||||
SPEED_FAST = 0x02,
|
||||
SPEED_FASTER = 0x03,
|
||||
SPEED_FASTEST = 0x04,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
BRIGHTNESS_OFF = 0x00,
|
||||
BRIGHTNESS_QUARTER = 0x01,
|
||||
BRIGHTNESS_HALF = 0x02,
|
||||
BRIGHTNESS_THREE_QUARTERS = 0x03,
|
||||
BRIGHTNESS_FULL = 0x04,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
COLOR_PRESET_0 = 0,
|
||||
COLOR_PRESET_1 = 1,
|
||||
COLOR_PRESET_2 = 2,
|
||||
COLOR_PRESET_3 = 3,
|
||||
COLOR_PRESET_4 = 4,
|
||||
COLOR_PRESET_5 = 5,
|
||||
COLOR_PRESET_6 = 6,
|
||||
COLOR_PRESET_RANDOM = 7,
|
||||
};
|
||||
}
|
||||
|
||||
struct ModeCfg
|
||||
{
|
||||
unsigned char color:3;
|
||||
unsigned char :4;
|
||||
unsigned char direction_left:1;
|
||||
unsigned char brightness:4;
|
||||
unsigned char speed:4;
|
||||
};
|
||||
|
||||
struct ColorCfg
|
||||
{
|
||||
unsigned char blue:8;
|
||||
unsigned char green:8;
|
||||
unsigned char red:8;
|
||||
};
|
||||
|
||||
struct ModeColorCfg
|
||||
{
|
||||
ColorCfg preset[COLOR_PRESETS_IN_MODE];
|
||||
};
|
||||
|
||||
class SinowealthKeyboard16Controller
|
||||
{
|
||||
public:
|
||||
SinowealthKeyboard16Controller(hid_device* cmd_handle, hid_device* data_handle, char *_path, std::string dev_name);
|
||||
~SinowealthKeyboard16Controller();
|
||||
|
||||
unsigned int GetLEDCount();
|
||||
std::string GetLocation();
|
||||
std::string GetName();
|
||||
std::string GetSerialString();
|
||||
unsigned char GetCurrentMode();
|
||||
std::vector<ModeCfg> GetDeviceModes();
|
||||
std::vector<ModeColorCfg> GetDeviceColors();
|
||||
std::vector<RGBColor> GetPerLedColors();
|
||||
|
||||
void SetLEDColor(RGBColor* color_buf);
|
||||
void SetMode(unsigned char mode, unsigned char brightness, unsigned char speed, RGBColor* color_buf);
|
||||
void ClearMode();
|
||||
void SetMode(unsigned char mode, unsigned char brightness, unsigned char speed, bool direction_left, unsigned char color_mode);
|
||||
void SetColorsForMode(unsigned char mode, RGBColor profiles[COLOR_PRESETS_IN_MODE]);
|
||||
void GetProfile();
|
||||
void ReadFirmwareInfo();
|
||||
void SetLEDsDirect(std::vector<RGBColor> colors);
|
||||
|
||||
const int per_key_mode_idx = 20;
|
||||
const int current_mode_idx = 21;
|
||||
const int profiles_start_idx = 32;
|
||||
const int profiles_count = 15;
|
||||
const int colors_start_idx = 8;
|
||||
|
||||
private:
|
||||
hid_device* dev_cmd;
|
||||
hid_device* dev_data;
|
||||
device_type type;
|
||||
std::string name;
|
||||
|
||||
unsigned int led_count;
|
||||
|
||||
unsigned char current_mode;
|
||||
struct ModeCfg* device_modes;
|
||||
struct ModeColorCfg* modes_colors;
|
||||
|
||||
std::string location;
|
||||
|
||||
unsigned char mode_config_buf[PAYLOAD_LEN];
|
||||
unsigned char colors_config_buf[PAYLOAD_LEN];
|
||||
unsigned char per_button_color_buf[PAYLOAD_LEN];
|
||||
bool read_config_error = false;
|
||||
unsigned char current_custom_preset = 0;
|
||||
|
||||
void GetModesConfig(unsigned char *buf);
|
||||
void GetColorsConfig(unsigned char *buf);
|
||||
void GetButtonColorsConfig(unsigned char *buf);
|
||||
|
||||
void initCommunication();
|
||||
bool getConfig(unsigned char reqest[], unsigned char *buf);
|
||||
bool sendConfig(unsigned char *buf);
|
||||
|
||||
void UpdateConfigurationFromDevice();
|
||||
};
|
||||
Reference in New Issue
Block a user