Add Asus Aura Keyboard controller for ROG Strix Flare (Direct mode only for now)

This commit is contained in:
Adam Honse 2021-03-27 00:23:47 -05:00
parent 1fdd4379a7
commit 2103982d7d
6 changed files with 473 additions and 0 deletions

View file

@ -0,0 +1,110 @@
/*-----------------------------------------*\
| AsusAuraKeyboardController.cpp |
| |
| Driver for ASUS Aura RGB USB |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 3/19/2020 |
\*-----------------------------------------*/
#include "AsusAuraKeyboardController.h"
#include <cstring>
AuraKeyboardController::AuraKeyboardController(hid_device* dev_handle, const char* path)
{
dev = dev_handle;
location = path;
}
AuraKeyboardController::~AuraKeyboardController()
{
hid_close(dev);
}
std::string AuraKeyboardController::GetDeviceLocation()
{
return("HID: " + location);
}
std::string AuraKeyboardController::GetSerialString()
{
wchar_t serial_string[128];
hid_get_serial_number_string(dev, serial_string, 128);
std::wstring return_wstring = serial_string;
std::string return_string(return_wstring.begin(), return_wstring.end());
return(return_string);
}
void AuraKeyboardController::SendDirect
(
unsigned char frame_count,
unsigned char * frame_data
)
{
unsigned char usb_buf[65];
unsigned int packet_count = frame_count / 15 + (((frame_count % 15) == 0) ? 0 : 1);
unsigned int total_frame_idx = 0;
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up message packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = 0xC0;
usb_buf[0x02] = 0x81;
usb_buf[0x03] = packet_count * 15;
usb_buf[0x04] = 0x00;
/*-----------------------------------------------------*\
| Copy in frame data and send packets until all data |
| has been sent |
\*-----------------------------------------------------*/
for(unsigned int packet_idx = 0; packet_idx < packet_count; packet_idx++)
{
unsigned int packet_data_size = 15 * 4;
if((frame_count - total_frame_idx) < 15)
{
packet_data_size = (frame_count - total_frame_idx) * 4;
memset(&usb_buf[0x05 + packet_data_size], 0xFF, (15*4) - packet_data_size);
}
memcpy(&usb_buf[0x05], &frame_data[packet_idx * 15 * 4], packet_data_size);
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 65);
/*-----------------------------------------------------*\
| Decrement remaining frame count |
\*-----------------------------------------------------*/
usb_buf[0x03] -= 0x0F;
total_frame_idx += 0x0F;
}
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up message packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = 0xC0;
usb_buf[0x02] = 0x81;
usb_buf[0x03] = 0x90;
/*-----------------------------------------------------*\
| Read to apply |
\*-----------------------------------------------------*/
hid_read(dev,usb_buf, 65);
}

View file

@ -0,0 +1,36 @@
/*-----------------------------------------*\
| AsusAuraKeyboardController.h |
| |
| Definitions and types for ASUS Aura |
| USB RGB lighting controller |
| |
| Adam Honse (CalcProgrammer1) 3/19/2020 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <vector>
#include <hidapi/hidapi.h>
#pragma once
class AuraKeyboardController
{
public:
AuraKeyboardController(hid_device* dev_handle, const char* path);
virtual ~AuraKeyboardController();
std::string GetDeviceLocation();
std::string GetSerialString();
void SendDirect
(
unsigned char frame_count,
unsigned char * frame_data
);
private:
hid_device* dev;
std::string location;
};

View file

@ -1,9 +1,11 @@
#include "Detector.h"
#include "AsusAuraAddressableController.h"
#include "AsusAuraKeyboardController.h"
#include "AsusAuraMainboardController.h"
#include "AsusAuraMouseController.h"
#include "RGBController.h"
#include "RGBController_AsusAuraUSB.h"
#include "RGBController_AsusAuraKeyboard.h"
#include "RGBController_AsusAuraMouse.h"
#include <stdexcept>
#include <hidapi/hidapi.h>
@ -18,6 +20,7 @@
#define AURA_MOTHERBOARD_2_PID 0x1939
#define AURA_ROG_GLADIUS_II_CORE_PID 0x18DD
#define AURA_ROG_GLADIUS_II_PID 0x1845
#define AURA_ROG_STRIX_FLARE_PID 0x1875
#define AURA_ROG_GLADIUS_II_ORIGIN_PID 0x1877
#define AURA_ROG_GLADIUS_II_ORIGIN_PNK_LTD_PID 0x18CD
#define AURA_ROG_CHAKRAM_WIRELESS_PID 0x18E5
@ -55,6 +58,18 @@ void DetectAsusAuraUSBMotherboards(hid_device_info* info, const std::string& nam
}
}
void DetectAsusAuraUSBKeyboards(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
AuraKeyboardController* controller = new AuraKeyboardController(dev, info->path);
RGBController_AuraKeyboard* rgb_controller = new RGBController_AuraKeyboard(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
void DetectAsusAuraUSBMice(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
@ -80,3 +95,4 @@ REGISTER_HID_DETECTOR_IP("ASUS ROG Gladius II Origin", DetectAsusAuraUS
REGISTER_HID_DETECTOR_IP("ASUS ROG Gladius II Origin PNK LTD", DetectAsusAuraUSBMice, AURA_USB_VID, AURA_ROG_GLADIUS_II_ORIGIN_PNK_LTD_PID, 2, 0xFF01);
REGISTER_HID_DETECTOR_IP("Asus ROG Chakram (Wireless)", DetectAsusAuraUSBMice, AURA_USB_VID, AURA_ROG_CHAKRAM_WIRELESS_PID, 0, 0xFF01);
REGISTER_HID_DETECTOR_IP("Asus ROG Chakram (Wired)", DetectAsusAuraUSBMice, AURA_USB_VID, AURA_ROG_CHAKRAM_WIRED_PID, 0, 0xFF01);
REGISTER_HID_DETECTOR_IP("Asus ROG Strix Flare", DetectAsusAuraUSBKeyboards, AURA_USB_VID, AURA_ROG_STRIX_FLARE_PID, 1, 0xFF00);

View file

@ -0,0 +1,274 @@
/*-----------------------------------------*\
| RGBController_AsusAuraKeyboard.cpp |
| |
| Generic RGB Interface for Asus Aura |
| USB controller driver |
| |
| Adam Honse (CalcProgrammer1) 3/19/2020 |
\*-----------------------------------------*/
#include "RGBController_AsusAuraKeyboard.h"
//0xFFFFFFFF indicates an unused entry in matrix
#define NA 0xFFFFFFFF
static unsigned int matrix_map[6][22] =
{ { 0, NA, 12, 17, 22, 27, 37, 42, 48, 53, 59, 64, 67, 68, NA, 74, 78, 83, NA, NA, NA, NA },
{ 1, 7, 13, 18, 23, 28, 33, 38, 43, 49, 54, 60, 65, 69, NA, 75, 79, 84, 87, 92, 96, 101 },
{ 2, NA, 8, 14, 19, 24, 29, 34, 39, 44, 50, 55, 61, 66, 70, 76, 80, 85, 88, 93, 97, 102 },
{ 3, NA, 9, 15, 20, 25, 30, 35, 40, 45, 51, 56, 62, 71, NA, NA, NA, NA, 89, 94, 98, NA },
{ 4, NA, 10, 16, 21, 26, 31, 36, 41, 46, 52, 57, NA, NA, 72, NA, 81, NA, 90, 95, 99, 103 },
{ 5, 6, 11, NA, NA, NA, NA, 32, NA, 47, NA, 58, 63, 73, NA, 77, 82, 86, 91, NA, 100, NA } };
static const char* zone_names[] =
{
"Keyboard",
"Logo",
"Underglow"
};
static zone_type zone_types[] =
{
ZONE_TYPE_MATRIX,
ZONE_TYPE_SINGLE,
ZONE_TYPE_SINGLE
};
static const unsigned int zone_sizes[] =
{
104,
1,
2,
};
typedef struct
{
const char * name;
const unsigned char idx;
} led_type;
static const led_type led_names[] =
{
/* Key Label Index */
{ "Key: Escape", 0x00 },
{ "Key: `", 0x01 },
{ "Key: Tab", 0x02 },
{ "Key: Caps Lock", 0x03 },
{ "Key: Left Shift", 0x04 },
{ "Key: Left Control", 0x05 },
{ "Key: Left Windows", 0x0D },
{ "Key: 1", 0x11 },
{ "Key: Q", 0x12 },
{ "Key: A", 0x13 },
{ "Key: Z", 0x14 },
{ "Key: Left Alt", 0x15 },
{ "Key: F1", 0x18 },
{ "Key: 2", 0x19 },
{ "Key: W", 0x1A },
{ "Key: S", 0x1B },
{ "Key: X", 0x1C },
{ "Key: F2", 0x20 },
{ "Key: 3", 0x21 },
{ "Key: E", 0x22 },
{ "Key: D", 0x23 },
{ "Key: C", 0x24 },
{ "Key: F3", 0x28 },
{ "Key: 4", 0x29 },
{ "Key: R", 0x2A },
{ "Key: F", 0x2B },
{ "Key: V", 0x2C },
{ "Key: F4", 0x30 },
{ "Key: 5", 0x31 },
{ "Key: T", 0x32 },
{ "Key: G", 0x33 },
{ "Key: B", 0x34 },
{ "Key: Space", 0x35 },
{ "Key: 6", 0x39 },
{ "Key: Y", 0x3A },
{ "Key: H", 0x3B },
{ "Key: N", 0x3C },
{ "Key: F5", 0x40 },
{ "Key: 7", 0x41 },
{ "Key: U", 0x42 },
{ "Key: J", 0x43 },
{ "Key: M", 0x44 },
{ "Key: F6", 0x48 },
{ "Key: 8", 0x49 },
{ "Key: I", 0x4A },
{ "Key: K", 0x4B },
{ "Key: ,", 0x4C },
{ "Key: Right Alt", 0x4D },
{ "Key: F7", 0x50 },
{ "Key: 9", 0x51 },
{ "Key: O", 0x52 },
{ "Key: L", 0x53 },
{ "Key: .", 0x54 },
{ "Key: F8", 0x58 },
{ "Key: 0", 0x59 },
{ "Key: P", 0x5A },
{ "Key: ;", 0x5B },
{ "Key: /", 0x5C },
{ "Key: Right Fn", 0x5D },
{ "Key: F9", 0x60 },
{ "Key: -", 0x61 },
{ "Key: [", 0x62 },
{ "Key: '", 0x63 },
{ "Key: Menu", 0x65 },
{ "Key: F10", 0x68 },
{ "Key: =", 0x69 },
{ "Key: ]", 0x6A },
{ "Key: F11", 0x70 },
{ "Key: F12", 0x78 },
{ "Key: Backspace", 0x79 },
{ "Key: \\ (ANSI)", 0x7A },
{ "Key: Enter", 0x7B },
{ "Key: Right Shift", 0x7C },
{ "Key: Right Control", 0x7D },
{ "Key: Print Screen", 0x80 },
{ "Key: Insert", 0x81 },
{ "Key: Delete", 0x82 },
{ "Key: Left Arrow", 0x85 },
{ "Key: Scroll Lock", 0x88 },
{ "Key: Home", 0x89 },
{ "Key: End", 0x8A },
{ "Key: Up Arrow", 0x8C },
{ "Key: Down Arrow", 0x8D },
{ "Key: Pause/Break", 0x90 },
{ "Key: Page Up", 0x91 },
{ "Key: Page Down", 0x92 },
{ "Key: Right Arrow", 0x95 },
{ "Key: Num Lock", 0x99 },
{ "Key: Number Pad 7", 0x9A },
{ "Key: Number Pad 4", 0x9B },
{ "Key: Number Pad 1", 0x9C },
{ "Key: Number Pad 0", 0x9D },
{ "Key: Number Pad /", 0xA1 },
{ "Key: Number Pad 8", 0xA2 },
{ "Key: Number Pad 5", 0xA3 },
{ "Key: Number Pad 2", 0xA4 },
{ "Key: Number Pad *", 0xA9 },
{ "Key: Number Pad 9", 0xAA },
{ "Key: Number Pad 6", 0xAB },
{ "Key: Number Pad 3", 0xAC },
{ "Key: Number Pad .", 0xAD },
{ "Key: Number Pad -", 0xB1 },
{ "Key: Number Pad +", 0xB2 },
{ "Key: Number Pad Enter", 0xB4 },
{ "Logo", 0xB8 },
{ "Left Underglow", 0xB9 },
{ "Right Underglow", 0xBA },
};
RGBController_AuraKeyboard::RGBController_AuraKeyboard(AuraKeyboardController* aura_ptr)
{
aura = aura_ptr;
name = "ASUS Aura Keyboard";
vendor = "ASUS";
type = DEVICE_TYPE_KEYBOARD;
description = "ASUS Aura Keyboard Device";
location = aura->GetDeviceLocation();
serial = aura->GetSerialString();
mode Direct;
Direct.name = "Direct";
Direct.value = 0;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
}
RGBController_AuraKeyboard::~RGBController_AuraKeyboard()
{
delete aura;
}
void RGBController_AuraKeyboard::SetupZones()
{
/*---------------------------------------------------------*\
| Set up zones |
\*---------------------------------------------------------*/
unsigned int total_led_count = 0;
for(unsigned int zone_idx = 0; zone_idx < 3; 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 = 22;
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].name;
new_led.value = led_names[led_idx].idx;
leds.push_back(new_led);
}
SetupColors();
}
void RGBController_AuraKeyboard::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_AuraKeyboard::DeviceUpdateLEDs()
{
unsigned char frame_buf[107 * 4];
/*---------------------------------------------------------*\
| TODO: Send packets with multiple LED frames |
\*---------------------------------------------------------*/
for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++)
{
frame_buf[(led_idx * 4) + 0] = leds[led_idx].value;
frame_buf[(led_idx * 4) + 1] = RGBGetRValue(colors[led_idx]);
frame_buf[(led_idx * 4) + 2] = RGBGetGValue(colors[led_idx]);
frame_buf[(led_idx * 4) + 3] = RGBGetBValue(colors[led_idx]);
}
aura->SendDirect(107, frame_buf);
}
void RGBController_AuraKeyboard::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_AuraKeyboard::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_AuraKeyboard::SetCustomMode()
{
active_mode = 0;
}
void RGBController_AuraKeyboard::DeviceUpdateMode()
{
}

View file

@ -0,0 +1,33 @@
/*-----------------------------------------*\
| RGBController_AsusAuraKeyboard.h |
| |
| Generic RGB Interface for Asus Aura |
| USB controller driver |
| |
| Adam Honse (CalcProgrammer1) 3/19/2021 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "AsusAuraKeyboardController.h"
class RGBController_AuraKeyboard : public RGBController
{
public:
RGBController_AuraKeyboard(AuraKeyboardController* aura_ptr);
~RGBController_AuraKeyboard();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
AuraKeyboardController* aura;
};

View file

@ -164,8 +164,10 @@ HEADERS +=
Controllers/AsusAuraSMBusController/RGBController_AsusAuraSMBus.h \
Controllers/AsusAuraUSBController/AsusAuraUSBController.h \
Controllers/AsusAuraUSBController/AsusAuraAddressableController.h \
Controllers/AsusAuraUSBController/AsusAuraKeyboardController.h \
Controllers/AsusAuraUSBController/AsusAuraMainboardController.h \
Controllers/AsusAuraUSBController/AsusAuraMouseController.h \
Controllers/AsusAuraUSBController/RGBController_AsusAuraKeyboard.h \
Controllers/AsusAuraUSBController/RGBController_AsusAuraMouse.h \
Controllers/AsusAuraUSBController/RGBController_AsusAuraUSB.h \
Controllers/CoolerMasterController/CMARGBcontroller.h \
@ -384,9 +386,11 @@ SOURCES +=
Controllers/AsusAuraSMBusController/RGBController_AsusAuraSMBus.cpp \
Controllers/AsusAuraUSBController/AsusAuraUSBController.cpp \
Controllers/AsusAuraUSBController/AsusAuraAddressableController.cpp \
Controllers/AsusAuraUSBController/AsusAuraKeyboardController.cpp \
Controllers/AsusAuraUSBController/AsusAuraMainboardController.cpp \
Controllers/AsusAuraUSBController/AsusAuraMouseController.cpp \
Controllers/AsusAuraUSBController/AsusAuraUSBControllerDetect.cpp \
Controllers/AsusAuraUSBController/RGBController_AsusAuraKeyboard.cpp \
Controllers/AsusAuraUSBController/RGBController_AsusAuraMouse.cpp \
Controllers/AsusAuraUSBController/RGBController_AsusAuraUSB.cpp \
Controllers/CoolerMasterController/CMARGBcontroller.cpp \