ASUS TUF Aura Core port (WMI)

Commit amended to move files to Windows-specific section of Qt project by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
k1-801 2020-09-09 16:04:30 +04:00 committed by Adam Honse
parent 08718044d0
commit e4a819913a
7 changed files with 522 additions and 5 deletions

View file

@ -0,0 +1,48 @@
#ifdef _WIN32
#include "RGBController_AsusTUFLaptopWMI.h"
#include "acpiwmi.h"
#include "Detector.h"
#include "wmi.h"
#include <string>
static void DetectAsusTUFLaptopWMIControllers(std::vector<RGBController*>&)
{
// Try to retrieve ProductID / Device name from WMI; Possibly can be rewritten to use wmi.cpp
// IF you encounter false detection ( e.g. if your laptop keyboard backlight uses USB interface
// instead of ACPI WMI) please add a WHITELIST by checking the
// `name` variable for model substrings like "FX505DU"
// For now, checking for "TUF Gaming" should suffice
Wmi wmi;
wmi.init();
std::vector<QueryObj> systemProduct;
if (wmi.query("SELECT * FROM Win32_ComputerSystemProduct", systemProduct))
{
return;
}
// There should only be one, a cycle is a precaution
if(systemProduct.size() != 1)
{
return;
}
std::string& name = systemProduct[0]["Name"];
if(name.find("TUF Gaming") == name.npos)
{
return;
}
if(AsWMI_Open())
{
RGBController* new_controller = new RGBController_AsusTUFLaptopWMI();
ResourceManager::get()->RegisterRGBController(new_controller);
// Success! No more if's
}
} /* DetectFaustusControllers() */
REGISTER_DETECTOR("TUF Laptop WMI", DetectAsusTUFLaptopWMIControllers);
#endif

View file

@ -0,0 +1,142 @@
#ifdef _WIN32
#include "RGBController_AsusTUFLaptopWMI.h"
#include "acpiwmi.h"
#include "ResourceManager.h"
#include "Detector.h"
#include "wmi.h"
#include <string>
using namespace std::chrono_literals;
RGBController_AsusTUFLaptopWMI::RGBController_AsusTUFLaptopWMI()
{
name = "ASUS TUF Keyboard";
type = DEVICE_TYPE_KEYBOARD;
description = "WMI Device";
location = "\\\\.\\ATKACPI";
modes.resize(5);
modes[0].name = "Direct";
modes[0].value = 4;
modes[0].flags = MODE_FLAG_HAS_PER_LED_COLOR;
modes[0].color_mode = MODE_COLORS_PER_LED;
modes[1].name = "Static";
modes[1].value = 0;
modes[1].flags = MODE_FLAG_HAS_PER_LED_COLOR;
modes[1].color_mode = MODE_COLORS_PER_LED;
modes[2].name = "Breathing";
modes[2].value = 1;
modes[2].flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR;
modes[2].speed_min = 0;
modes[2].speed_max = 2;
modes[2].color_mode = MODE_COLORS_PER_LED;
modes[2].speed = 1;
modes[3].name = "Color Cycle";
modes[3].value = 2;
modes[3].flags = MODE_FLAG_HAS_SPEED;
modes[3].speed_min = 0;
modes[3].speed_max = 2;
modes[3].color_mode = MODE_COLORS_NONE;
modes[3].speed = 1;
modes[4].name = "Strobe";
modes[4].value = 0x0A;
modes[4].flags = MODE_FLAG_HAS_PER_LED_COLOR;
modes[4].color_mode = MODE_COLORS_PER_LED;
SetupZones();
}
RGBController_AsusTUFLaptopWMI::~RGBController_AsusTUFLaptopWMI()
{
AsWMI_Close();
}
void RGBController_AsusTUFLaptopWMI::SetupZones()
{
/*---------------------------------------------------------*\
| Set up zone |
\*---------------------------------------------------------*/
zones.resize(1);
zones[0].type = ZONE_TYPE_SINGLE;
zones[0].name = "Keyboard Backlight zone";
zones[0].leds_min = 1;
zones[0].leds_max = 1;
zones[0].leds_count = 1;
zones[0].matrix_map = NULL;
/*---------------------------------------------------------*\
| Set up LED |
\*---------------------------------------------------------*/
leds.resize(1);
leds[0].name = "Keyboard Backlight LED";
SetupColors();
}
void RGBController_AsusTUFLaptopWMI::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_AsusTUFLaptopWMI::DeviceUpdateLEDs()
{
uint8_t red = RGBGetRValue(colors[0]);
uint8_t green = RGBGetGValue(colors[0]);
uint8_t blue = RGBGetBValue(colors[0]);
uint8_t speed_byte = 0;
uint8_t mode = modes[active_mode].value;
uint8_t inv = 0;
if(mode == 4)
{
mode = 1;
inv = 4; // Any invalid mode, i.e. anything other than 0, 1, 2 and 10
}
if(mode == 1 || mode == 2)
{
switch(modes[active_mode].speed)
{
case 0: speed_byte = 0xE1; break;
case 1: speed_byte = 0xEB; break;
case 2: speed_byte = 0xF5; break;
}
}
int high = ((mode | ((red | (green << 8)) << 8)) << 8) | 0xB3;
int low = blue | (speed_byte << 8);
AsWMI_NB_DeviceControl_2arg(0x100056, high, low);
if(inv)
{
//std::this_thread::sleep_for(10ms);
high = ((inv | ((red | (green << 8)) << 8)) << 8) | 0xB3;
AsWMI_NB_DeviceControl_2arg(0x100056, high, low);
}
}
void RGBController_AsusTUFLaptopWMI::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_AsusTUFLaptopWMI::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_AsusTUFLaptopWMI::SetCustomMode()
{
SetMode(0);
}
void RGBController_AsusTUFLaptopWMI::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}
#endif

View file

@ -0,0 +1,29 @@
#ifndef RGBCONTROLLER_ASUSTUFLAPTOPWMI_H
#define RGBCONTROLLER_ASUSTUFLAPTOPWMI_H
#ifdef _WIN32
#include "RGBController.h"
class RGBController_AsusTUFLaptopWMI : public RGBController
{
public:
RGBController_AsusTUFLaptopWMI();
virtual ~RGBController_AsusTUFLaptopWMI();
void SetupZones() override;
void ResizeZone(int zone, int new_size) override;
void DeviceUpdateLEDs() override;
void UpdateZoneLEDs(int zone) override;
void UpdateSingleLED(int led) override;
void DeviceUpdateMode() override;
void SetCustomMode() override;
};
#endif
#endif // RGBCONTROLLER_ASUSTUFLAPTOPWMI_H