Publish LumaOps source
This commit is contained in:
+191
@@ -0,0 +1,191 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| HyperXAlloyOriginsCoreController.cpp |
|
||||
| |
|
||||
| Driver for HyperX Alloy Origins Core keyboard |
|
||||
| |
|
||||
| Volodymyr Nazarchuk (Vavooon) 28 Apr 2021 |
|
||||
| Mike White (kamaaina) 09 Jun 2021 |
|
||||
| carlos jordao 15 Mar 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include "HyperXAlloyOriginsCoreController.h"
|
||||
#include "StringUtils.h"
|
||||
#include "LogManager.h"
|
||||
|
||||
|
||||
HyperXAlloyOriginsCoreController::HyperXAlloyOriginsCoreController(hid_device* dev_handle, hid_device_info* dev_info, std::string dev_name)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = dev_info->path;
|
||||
name = dev_name;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the firmware version from the device info |
|
||||
\*-----------------------------------------------------*/
|
||||
char fw_version_buf[8];
|
||||
memset(fw_version_buf, '\0', sizeof(fw_version_buf));
|
||||
|
||||
unsigned short version = dev_info->release_number;
|
||||
snprintf(fw_version_buf, 8, "%.2X.%.2X", (version & 0xFF00) >> 8, version & 0x00FF);
|
||||
|
||||
firmware_version = fw_version_buf;
|
||||
}
|
||||
|
||||
HyperXAlloyOriginsCoreController::~HyperXAlloyOriginsCoreController()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string HyperXAlloyOriginsCoreController::GetDeviceLocation()
|
||||
{
|
||||
return("HID " + location);
|
||||
}
|
||||
|
||||
std::string HyperXAlloyOriginsCoreController::GetNameString()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
std::string HyperXAlloyOriginsCoreController::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
return(StringUtils::wstring_to_string(serial_string));
|
||||
}
|
||||
|
||||
std::string HyperXAlloyOriginsCoreController::GetFirmwareVersion()
|
||||
{
|
||||
return(firmware_version);
|
||||
}
|
||||
|
||||
unsigned int HyperXAlloyOriginsCoreController::GetVariant()
|
||||
{
|
||||
unsigned char packet[65];
|
||||
unsigned int variant = 0;
|
||||
int actual = 0;
|
||||
|
||||
memset(packet, 0x00, sizeof(packet));
|
||||
|
||||
/*---------------------------------------*\
|
||||
| Command 10 asks some data from keyboard |
|
||||
| The answer looks like: |
|
||||
| * command answer header (bytes 0-4) |
|
||||
| * data length: byte 4 |
|
||||
| * version (bytes 5-6) |
|
||||
| * Product string (bytes 9-33) |
|
||||
| * Layout variant (byte 56) |
|
||||
\*---------------------------------------*/
|
||||
packet[1] = 0x10;
|
||||
hid_write(dev, packet, 65);
|
||||
memset(packet, 0x00, sizeof(packet));
|
||||
actual = hid_read(dev, packet, 65);
|
||||
|
||||
if(actual > 0)
|
||||
variant = packet[56];
|
||||
else
|
||||
variant = 0;
|
||||
|
||||
LOG_DEBUG("[HyperX Alloy Origins Core] variant: 0x%02X", variant);
|
||||
return variant;
|
||||
}
|
||||
|
||||
|
||||
void HyperXAlloyOriginsCoreController::SetBrightness(unsigned int brightness)
|
||||
{
|
||||
unsigned char packet[65];
|
||||
memset(packet, 0x00, sizeof(packet));
|
||||
|
||||
packet[1] = 0xA7;
|
||||
packet[4] = 0x01;
|
||||
packet[5] = brightness;
|
||||
|
||||
hid_write(dev, packet, 65);
|
||||
}
|
||||
|
||||
void HyperXAlloyOriginsCoreController::SetLEDsDirect(std::vector<led> leds, std::vector<RGBColor> colors)
|
||||
{
|
||||
/*------------------------------------------------------------------------------*\
|
||||
| * Always send 380 bytes to the keyboard and a total of 94 led indexes. |
|
||||
| The colors are grouped into segments of 48 bytes. |
|
||||
| Each one is divided into: |
|
||||
| 6 Green + 2 zeroes + 6 Green + 2 zeroes + |
|
||||
| 6 Red + 2 zeroes + 6 Red + 2 zeroes + |
|
||||
| 6 Blue + 2 zeroes + 6 Blue + 2 zeroes |
|
||||
| \=---> sector 0 \=--> sector 1 |
|
||||
| Every 6 colors form a sector. The names are arbitrary, just to make clear how |
|
||||
| to set the colors into the buffer. |
|
||||
| So each segment has 2 sectors and 12 colors. |
|
||||
| The last 10 colors don't fill completely the last segment. |
|
||||
| * All 94 colors can be sent even if some of them aren't used by the physical |
|
||||
| keyboard. This allows to lit every key, even if not mapped directly. |
|
||||
\*------------------------------------------------------------------------------*/
|
||||
unsigned int segment = 0, sector = 0, sequence = 0;
|
||||
unsigned int total_colors = 0;
|
||||
memset(color_buf, 0x00, sizeof(color_buf));
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
| transfer the colors to the buffer. Max 94 colors to avoid buffer overflow. |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
if(colors.size() > 94)
|
||||
{
|
||||
total_colors = 94;
|
||||
}
|
||||
else
|
||||
{
|
||||
total_colors = (unsigned int)colors.size();
|
||||
}
|
||||
|
||||
unsigned int pos = 0, color_idx = 0;
|
||||
for(unsigned int i = 0; i < total_colors; i++)
|
||||
{
|
||||
color_idx = leds[i].value;
|
||||
segment = (color_idx / 12) * 48;
|
||||
sector = ((color_idx / 6) & 1) * 8;
|
||||
sequence = color_idx % 6;
|
||||
|
||||
pos = segment + sector + sequence;
|
||||
|
||||
color_buf[pos ] = RGBGetGValue(colors[i]);
|
||||
color_buf[pos + 16] = RGBGetRValue(colors[i]);
|
||||
color_buf[pos + 32] = RGBGetBValue(colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HyperXAlloyOriginsCoreController::SendRGBToDevice()
|
||||
{
|
||||
unsigned int sentBytes = 0;
|
||||
unsigned int bytesToSend = sizeof(color_buf);
|
||||
unsigned int payloadSize = 60;
|
||||
unsigned int seq = 0;
|
||||
|
||||
while(sentBytes < bytesToSend)
|
||||
{
|
||||
if (bytesToSend - sentBytes < payloadSize)
|
||||
{
|
||||
payloadSize = bytesToSend - sentBytes;
|
||||
}
|
||||
|
||||
unsigned char packet[65];
|
||||
memset(packet, 0x00, sizeof(packet));
|
||||
|
||||
packet[1] = 0xA2;
|
||||
packet[2] = seq++;
|
||||
packet[4] = payloadSize;
|
||||
|
||||
memcpy(&packet[5], &color_buf[sentBytes], payloadSize);
|
||||
hid_write(dev, packet, payloadSize + 5);
|
||||
|
||||
sentBytes += payloadSize;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| HyperXAlloyOriginsCoreController.h |
|
||||
| |
|
||||
| Driver for HyperX Alloy Origins Core keyboard |
|
||||
| |
|
||||
| Volodymyr Nazarchuk (Vavooon) 28 Apr 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController.h"
|
||||
|
||||
#define HYPERX_ALLOY_ORIGINS_CORE_ANSI 0x09
|
||||
#define HYPERX_ALLOY_ORIGINS_CORE_ABNT2 0x10
|
||||
|
||||
class HyperXAlloyOriginsCoreController
|
||||
{
|
||||
public:
|
||||
HyperXAlloyOriginsCoreController(hid_device* dev_handle, hid_device_info* dev_info, std::string dev_name);
|
||||
~HyperXAlloyOriginsCoreController();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetNameString();
|
||||
std::string GetSerialString();
|
||||
std::string GetFirmwareVersion();
|
||||
unsigned int GetVariant();
|
||||
|
||||
void SetLEDsDirect(std::vector<led> leds, std::vector<RGBColor> colors);
|
||||
void SendRGBToDevice();
|
||||
void SetBrightness(unsigned int brightness);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
std::string firmware_version;
|
||||
std::string name;
|
||||
unsigned char color_buf[380];
|
||||
};
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_HyperXAlloyOriginsCore.cpp |
|
||||
| |
|
||||
| RGBController for HyperX Alloy Origins Core keyboard |
|
||||
| |
|
||||
| Volodymyr Nazarchuk (Vavooon) 28 Apr 2021 |
|
||||
| carlos jordao 15 Mar 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBControllerKeyNames.h"
|
||||
#include "RGBController_HyperXAlloyOriginsCore.h"
|
||||
#include "KeyboardLayoutManager.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
#define HYPERX_MIN_BRIGHTNESS 0
|
||||
#define HYPERX_MAX_BRIGHTNESS 255
|
||||
|
||||
#define NA 0xFFFFFFFF
|
||||
|
||||
/*----------------------------------*\
|
||||
| Maps LED position number to keys |
|
||||
| * based on ANSI QWERTY |
|
||||
\*----------------------------------*/
|
||||
static const char* zone_names[] =
|
||||
{
|
||||
ZONE_EN_KEYBOARD,
|
||||
};
|
||||
|
||||
static zone_type zone_types[] =
|
||||
{
|
||||
ZONE_TYPE_MATRIX,
|
||||
};
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------------*\
|
||||
| This keyboard (TKL) always receives 94 led colors. |
|
||||
| * Some indexes are just blank (unused). |
|
||||
| * Regional layouts have a few different enabled or disabled led indexes. |
|
||||
| * Below there is the association of the led indexes and the keyboard keys for |
|
||||
| DEFAULT layout. |
|
||||
\*--------------------------------------------------------------------------------*/
|
||||
|
||||
std::vector<unsigned int> hyperx_core_default_values
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 48, 49, 50, 51, 52, 53, 54, 55,
|
||||
8, 9, 10, 11, 12, 13, 14, 15, 16, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 64, 65, 66, 67, 68, 69, 70, 71, 72,
|
||||
25, 26, 27, 28, 29, 30, 31, 32, 73, 74, 75, 76, 77, 78,
|
||||
33, 34, 35, 36, 37, 38, 39, 40, 79, 80, 81, 82, 84, 85,
|
||||
41, 42, 43, 45, 86, 87, 88, 89, 90, 91, 92,
|
||||
};
|
||||
|
||||
layout_values hyperx_core_layout
|
||||
{
|
||||
hyperx_core_default_values,
|
||||
{
|
||||
},
|
||||
};
|
||||
|
||||
/*--------------------------------------------*\
|
||||
| Provide values to keys that has been changed |
|
||||
| in DEFAULT layout. |
|
||||
\*--------------------------------------------*/
|
||||
std::map<KEYBOARD_LAYOUT, key_set> regional_overlay_abnt2
|
||||
{
|
||||
{
|
||||
KEYBOARD_LAYOUT_ABNT2,
|
||||
{
|
||||
/*-------------------------------------------------------------------------------------------------------------------------------------*\
|
||||
| Edit Keys |
|
||||
| Zone, Row, Column, Value, Key, Alternate Name, OpCode, |
|
||||
\*-------------------------------------------------------------------------------------------------------------------------------------*/
|
||||
{ 0, 4, 11, 82, KEY_EN_SEMICOLON, KEY_EN_UNUSED, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 4, 12, 83, KEY_EN_FORWARD_SLASH, KEY_EN_UNUSED, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name HyperX Alloy Origins Core
|
||||
@category Keyboard
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectHyperXAlloyOriginsCore
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_HyperXAlloyOriginsCore::RGBController_HyperXAlloyOriginsCore(HyperXAlloyOriginsCoreController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetNameString();
|
||||
vendor = "HyperX";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "HyperX Alloy Origins Core Keyboard Device";
|
||||
location = controller->GetDeviceLocation();
|
||||
serial = controller->GetSerialString();
|
||||
version = controller->GetFirmwareVersion();
|
||||
variant = controller->GetVariant();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = 0xFFFF;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Direct.brightness_min = HYPERX_MIN_BRIGHTNESS;
|
||||
Direct.brightness_max = HYPERX_MAX_BRIGHTNESS;
|
||||
Direct.brightness = HYPERX_MAX_BRIGHTNESS;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
SetupZones();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| The HyperX Origins Core requires a packet within few |
|
||||
| seconds of sending the lighting change in order to |
|
||||
| not revert back into current profile. Start a thread |
|
||||
| to continuously send color values each 10ms |
|
||||
\*-----------------------------------------------------*/
|
||||
keepalive_thread_run = 1;
|
||||
keepalive_thread = new std::thread(&RGBController_HyperXAlloyOriginsCore::KeepaliveThread, this);
|
||||
}
|
||||
|
||||
RGBController_HyperXAlloyOriginsCore::~RGBController_HyperXAlloyOriginsCore()
|
||||
{
|
||||
keepalive_thread_run = 0;
|
||||
keepalive_thread->join();
|
||||
delete keepalive_thread;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Delete the matrix map |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
|
||||
{
|
||||
if(zones[zone_index].matrix_map != NULL)
|
||||
{
|
||||
delete zones[zone_index].matrix_map;
|
||||
}
|
||||
}
|
||||
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_HyperXAlloyOriginsCore::SetupZones()
|
||||
{
|
||||
unsigned int total_leds = 0;
|
||||
zone new_zone;
|
||||
KEYBOARD_LAYOUT layout_name;
|
||||
|
||||
for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
|
||||
{
|
||||
new_zone.name = zone_names[zone_idx];
|
||||
new_zone.type = zone_types[zone_idx];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Regional configuration |
|
||||
| * variant is extracted from keyboard info |
|
||||
\*-----------------------------------------------------*/
|
||||
switch(variant)
|
||||
{
|
||||
case HYPERX_ALLOY_ORIGINS_CORE_ABNT2:
|
||||
layout_name = KEYBOARD_LAYOUT_ABNT2;
|
||||
hyperx_core_layout.regional_overlay = regional_overlay_abnt2;
|
||||
break;
|
||||
|
||||
case HYPERX_ALLOY_ORIGINS_CORE_ANSI:
|
||||
default:
|
||||
layout_name = KEYBOARD_LAYOUT_ANSI_QWERTY;
|
||||
break;
|
||||
}
|
||||
KeyboardLayoutManager new_kb(layout_name, KEYBOARD_SIZE_TKL, hyperx_core_layout);
|
||||
|
||||
total_leds = new_kb.GetKeyCount();
|
||||
|
||||
matrix_map_type * keyboard_map = new matrix_map_type;
|
||||
new_zone.leds_count = total_leds;
|
||||
new_zone.leds_min = new_zone.leds_count;
|
||||
new_zone.leds_max = new_zone.leds_count;
|
||||
|
||||
if(zone_types[zone_idx] == ZONE_TYPE_MATRIX)
|
||||
{
|
||||
new_zone.matrix_map = keyboard_map;
|
||||
keyboard_map->height = new_kb.GetRowCount();
|
||||
keyboard_map->width = new_kb.GetColumnCount();
|
||||
keyboard_map->map = new unsigned int[keyboard_map->height * keyboard_map->width];
|
||||
|
||||
new_kb.GetKeyMap(keyboard_map->map, KEYBOARD_MAP_FILL_TYPE_COUNT);
|
||||
}
|
||||
else
|
||||
{
|
||||
new_zone.matrix_map = NULL;
|
||||
}
|
||||
zones.push_back(new_zone);
|
||||
|
||||
for(unsigned int led_idx = 0; led_idx < total_leds; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
new_led.name = new_kb.GetKeyAltNameAt(led_idx);
|
||||
if(new_led.name == KEY_EN_UNUSED)
|
||||
new_led.name = new_kb.GetKeyNameAt(led_idx);
|
||||
new_led.value = new_kb.GetKeyValueAt(led_idx);
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
}
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_HyperXAlloyOriginsCore::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_HyperXAlloyOriginsCore::DeviceUpdateLEDs()
|
||||
{
|
||||
controller->SetLEDsDirect(leds, colors);
|
||||
}
|
||||
|
||||
void RGBController_HyperXAlloyOriginsCore::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_HyperXAlloyOriginsCore::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_HyperXAlloyOriginsCore::DeviceUpdateMode()
|
||||
{
|
||||
controller->SetBrightness(modes[active_mode].brightness);
|
||||
}
|
||||
|
||||
void RGBController_HyperXAlloyOriginsCore::KeepaliveThread()
|
||||
{
|
||||
while(keepalive_thread_run.load())
|
||||
{
|
||||
if(active_mode == 0)
|
||||
{
|
||||
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50))
|
||||
{
|
||||
controller->SendRGBToDevice();
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_HyperXAlloyOriginsCore.h |
|
||||
| |
|
||||
| RGBController for HyperX Alloy Origins Core keyboard |
|
||||
| |
|
||||
| Volodymyr Nazarchuk (Vavooon) 28 Apr 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include "RGBController.h"
|
||||
#include "HyperXAlloyOriginsCoreController.h"
|
||||
|
||||
#define HYPERX_ALLOY_ORIGINS_CORE_ANSI 0x09
|
||||
#define HYPERX_ALLOY_ORIGINS_CORE_ABNT2 0x10
|
||||
|
||||
class RGBController_HyperXAlloyOriginsCore : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_HyperXAlloyOriginsCore(HyperXAlloyOriginsCoreController* controller_ptr);
|
||||
~RGBController_HyperXAlloyOriginsCore();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
void KeepaliveThread();
|
||||
|
||||
private:
|
||||
HyperXAlloyOriginsCoreController* controller;
|
||||
std::thread* keepalive_thread;
|
||||
std::atomic<bool> keepalive_thread_run;
|
||||
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
|
||||
unsigned int variant;
|
||||
};
|
||||
Reference in New Issue
Block a user