mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-05-19 03:56:26 -04:00
Organize most controller files into subfolders
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
/*-----------------------------------------*\
|
||||
| HyperXPulsefireSurgeController.cpp |
|
||||
| |
|
||||
| Driver for HyperX Pulsefire Surge |
|
||||
| lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 7/25/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "HyperXPulsefireSurgeController.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
HyperXPulsefireSurgeController::HyperXPulsefireSurgeController(hid_device* dev_handle, const char* path)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
}
|
||||
|
||||
HyperXPulsefireSurgeController::~HyperXPulsefireSurgeController()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string HyperXPulsefireSurgeController::GetDeviceLocation()
|
||||
{
|
||||
return("HID " + location);
|
||||
}
|
||||
|
||||
std::string HyperXPulsefireSurgeController::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
std::wstring return_wstring = serial_string;
|
||||
std::string return_string(return_wstring.begin(), return_wstring.end());
|
||||
|
||||
return(return_string);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void HyperXPulsefireSurgeController::SelectProfile
|
||||
(
|
||||
unsigned char profile
|
||||
)
|
||||
{
|
||||
unsigned char buf[264];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Select Profile packet |
|
||||
\*-----------------------------------------------------*/
|
||||
buf[0x00] = 0x07;
|
||||
buf[0x01] = HYPERX_PULSEFIRE_SURGE_PACKET_ID_SELECT_PROFILE;
|
||||
buf[0x02] = profile;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, buf, 264);
|
||||
}
|
||||
|
||||
void HyperXPulsefireSurgeController::SetProfileBrightness
|
||||
(
|
||||
unsigned char profile,
|
||||
unsigned char brightness
|
||||
)
|
||||
{
|
||||
unsigned char buf[264];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Select Profile packet |
|
||||
\*-----------------------------------------------------*/
|
||||
buf[0x00] = 0x07;
|
||||
buf[0x01] = HYPERX_PULSEFIRE_SURGE_PACKET_ID_SET_BRIGHTNESS;
|
||||
buf[0x02] = profile;
|
||||
buf[0x03] = 0x01;
|
||||
buf[0x04] = 0x01;
|
||||
buf[0x05] = 0x01;
|
||||
buf[0x06] = brightness;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, buf, 264);
|
||||
}
|
||||
|
||||
void HyperXPulsefireSurgeController::SendDirect
|
||||
(
|
||||
RGBColor* color_data
|
||||
)
|
||||
{
|
||||
unsigned char buf[264];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Select Profile packet |
|
||||
\*-----------------------------------------------------*/
|
||||
buf[0x00] = 0x07;
|
||||
buf[0x01] = HYPERX_PULSEFIRE_SURGE_PACKET_ID_DIRECT;
|
||||
buf[0x03] = 0xA0;
|
||||
|
||||
for(int red_idx = 0; red_idx < 32; red_idx++)
|
||||
{
|
||||
buf[0x08 + red_idx] = RGBGetRValue(color_data[red_idx]);
|
||||
}
|
||||
|
||||
for(int grn_idx = 0; grn_idx < 32; grn_idx++)
|
||||
{
|
||||
buf[0x28 + grn_idx] = RGBGetGValue(color_data[grn_idx]);
|
||||
}
|
||||
|
||||
for(int blu_idx = 0; blu_idx < 32; blu_idx++)
|
||||
{
|
||||
buf[0x48 + blu_idx] = RGBGetBValue(color_data[blu_idx]);
|
||||
}
|
||||
|
||||
buf[0x6C] = RGBGetRValue(color_data[32]);
|
||||
buf[0x6D] = RGBGetGValue(color_data[32]);
|
||||
buf[0x6E] = RGBGetBValue(color_data[32]);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, buf, 264);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*-----------------------------------------*\
|
||||
| HyperXPulsefireSurgeController.h |
|
||||
| |
|
||||
| Definitions and types for HyperX |
|
||||
| Pulsefire Surge lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 7/25/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
HYPERX_PULSEFIRE_SURGE_PACKET_ID_SET_CONFIGURATION = 0x01, /* Set profile configuration packet */
|
||||
HYPERX_PULSEFIRE_SURGE_PACKET_ID_SET_BRIGHTNESS = 0x03, /* Set profile settings and brightness */
|
||||
HYPERX_PULSEFIRE_SURGE_PACKET_ID_SELECT_PROFILE = 0x07, /* Select profile */
|
||||
HYPERX_PULSEFIRE_SURGE_PACKET_ID_DIRECT = 0x14, /* Direct control packet */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
HYPERX_PULSEFIRE_SURGE_MODE_SOLID = 0x00, /* Solid color mode */
|
||||
HYPERX_PULSEFIRE_SURGE_MODE_CYCLE = 0x01, /* Spectrum cycle mode */
|
||||
HYPERX_PULSEFIRE_SURGE_MODE_BREATHING = 0x02, /* Breathing mode */
|
||||
HYPERX_PULSEFIRE_SURGE_MODE_WAVE = 0x03, /* Wave mode */
|
||||
HYPERX_PULSEFIRE_SURGE_MODE_TRIGGER = 0x04, /* Trigger mode */
|
||||
};
|
||||
|
||||
class HyperXPulsefireSurgeController
|
||||
{
|
||||
public:
|
||||
HyperXPulsefireSurgeController(hid_device* dev_handle, const char* path);
|
||||
~HyperXPulsefireSurgeController();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetSerialString();
|
||||
|
||||
void SelectProfile
|
||||
(
|
||||
unsigned char profile
|
||||
);
|
||||
|
||||
void SetProfileBrightness
|
||||
(
|
||||
unsigned char profile,
|
||||
unsigned char brightness
|
||||
);
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
RGBColor* color_data
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
};
|
||||
@@ -0,0 +1,154 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_HyperXPulsefireSurge.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for HyperX |
|
||||
| Pulsefire Surge |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/2/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_HyperXPulsefireSurge.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name HyperX Pulsefire Surge
|
||||
@category Mouse
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectHyperXPulsefireSurgeControllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_HyperXPulsefireSurge::RGBController_HyperXPulsefireSurge(HyperXPulsefireSurgeController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = "HyperX Pulsefire Surge Device";
|
||||
vendor = "HyperX";
|
||||
type = DEVICE_TYPE_MOUSE;
|
||||
description = "HyperX Pulsefire Surge Device";
|
||||
location = controller->GetDeviceLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = 0xFFFF;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
SetupZones();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| The Corsair Lighting Node Pro requires a packet within|
|
||||
| 20 seconds of sending the lighting change in order |
|
||||
| to not revert back into rainbow mode. Start a thread |
|
||||
| to continuously send a keepalive packet every 5s |
|
||||
\*-----------------------------------------------------*/
|
||||
keepalive_thread_run = 1;
|
||||
keepalive_thread = new std::thread(&RGBController_HyperXPulsefireSurge::KeepaliveThread, this);
|
||||
};
|
||||
|
||||
RGBController_HyperXPulsefireSurge::~RGBController_HyperXPulsefireSurge()
|
||||
{
|
||||
keepalive_thread_run = 0;
|
||||
keepalive_thread->join();
|
||||
delete keepalive_thread;
|
||||
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_HyperXPulsefireSurge::SetupZones()
|
||||
{
|
||||
zone led_strip;
|
||||
led_strip.name = "LED Strip";
|
||||
led_strip.type = ZONE_TYPE_LINEAR;
|
||||
led_strip.leds_min = 32;
|
||||
led_strip.leds_max = 32;
|
||||
led_strip.leds_count = 32;
|
||||
led_strip.matrix_map = NULL;
|
||||
zones.push_back(led_strip);
|
||||
|
||||
zone logo;
|
||||
logo.name = "Logo";
|
||||
logo.type = ZONE_TYPE_SINGLE;
|
||||
logo.leds_min = 1;
|
||||
logo.leds_max = 1;
|
||||
logo.leds_count = 1;
|
||||
logo.matrix_map = NULL;
|
||||
zones.push_back(logo);
|
||||
|
||||
for(unsigned int zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
for(unsigned int led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
|
||||
new_led.name = zones[zone_idx].name;
|
||||
|
||||
if(zones[zone_idx].leds_count > 1)
|
||||
{
|
||||
new_led.name.append(" LED ");
|
||||
new_led.name.append(std::to_string(led_idx + 1));
|
||||
}
|
||||
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_HyperXPulsefireSurge::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_HyperXPulsefireSurge::DeviceUpdateLEDs()
|
||||
{
|
||||
last_update_time = std::chrono::steady_clock::now();
|
||||
|
||||
if(active_mode == 0)
|
||||
{
|
||||
controller->SendDirect(&colors[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RGBController_HyperXPulsefireSurge::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_HyperXPulsefireSurge::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_HyperXPulsefireSurge::DeviceUpdateMode()
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_HyperXPulsefireSurge::KeepaliveThread()
|
||||
{
|
||||
while(keepalive_thread_run.load())
|
||||
{
|
||||
if(active_mode == 0)
|
||||
{
|
||||
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50))
|
||||
{
|
||||
UpdateLEDs();
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_HyperXPulsefireSurge.h |
|
||||
| |
|
||||
| Generic RGB Interface for HyperX |
|
||||
| Pulsefire Surge |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 7/25/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "HyperXPulsefireSurgeController.h"
|
||||
|
||||
class RGBController_HyperXPulsefireSurge : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_HyperXPulsefireSurge(HyperXPulsefireSurgeController* controller_ptr);
|
||||
~RGBController_HyperXPulsefireSurge();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
void KeepaliveThread();
|
||||
|
||||
private:
|
||||
HyperXPulsefireSurgeController* controller;
|
||||
std::thread* keepalive_thread;
|
||||
std::atomic<bool> keepalive_thread_run;
|
||||
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
|
||||
};
|
||||
Reference in New Issue
Block a user