Initial HP Omen 30L Support

Commits squashed and amended for code style/brightness control by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
Travis Sandmann 2021-06-28 12:12:18 -05:00 committed by Adam Honse
parent e52ba49815
commit 85631bfd52
6 changed files with 518 additions and 0 deletions

View file

@ -0,0 +1,171 @@
/*-----------------------------------------*\
| HPOmen30LController.cpp |
| |
| Driver for HP Omen 30L RGB lighting |
| controller |
\*-----------------------------------------*/
#include "HPOmen30LController.h"
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
HPOmen30LController::HPOmen30LController(hid_device* dev_handle, const char* path)
{
dev = dev_handle;
location = path;
strcpy(device_name, "HP Omen 30L");
hp_zone logo;
logo.value = HP_OMEN_30L_LOGO_ZONE;
logo.mode = HP_OMEN_30L_DIRECT;
logo.speed = HP_OMEN_30L_SPEED_MED;
logo.brightness = 0x64;
hp_zones.push_back(logo);
hp_zone bar;
bar.value = HP_OMEN_30L_BAR_ZONE;
bar.mode = HP_OMEN_30L_DIRECT;
bar.speed = HP_OMEN_30L_SPEED_MED;
bar.brightness = 0x64;
hp_zones.push_back(bar);
hp_zone fan;
fan.value = HP_OMEN_30L_FAN_ZONE;
fan.mode = HP_OMEN_30L_DIRECT;
fan.speed = HP_OMEN_30L_SPEED_MED;
fan.brightness = 0x64;
hp_zones.push_back(fan);
hp_zone cpu;
cpu.value = HP_OMEN_30L_CPU_ZONE;
cpu.mode = HP_OMEN_30L_DIRECT;
cpu.speed = HP_OMEN_30L_SPEED_MED;
cpu.brightness = 0x64;
hp_zones.push_back(cpu);
}
HPOmen30LController::~HPOmen30LController()
{
hid_close(dev);
}
std::string HPOmen30LController::GetLocationString()
{
return("HID: " + location);
}
char* HPOmen30LController::GetDeviceName()
{
return device_name;
}
std::string HPOmen30LController::GetSerialString()
{
std::string ret_string = "";
return(ret_string);
}
std::string HPOmen30LController::GetEffectChannelString(unsigned char channel)
{
std::string ret_string = "";
return(ret_string);
}
std::string HPOmen30LController::GetFirmwareVersionString()
{
std::string ret_string = "";
return(ret_string);
}
void HPOmen30LController::SetZoneMode(int zone,unsigned char mode, unsigned char speed,unsigned char brightness)
{
hp_zones[zone].mode = mode;
hp_zones[zone].speed = speed;
hp_zones[zone].brightness = brightness;
}
void HPOmen30LController::SetZoneColor(int zone, std::vector<RGBColor> colors)
{
SendZoneUpdate(zone, colors);
}
void HPOmen30LController::SendZoneUpdate(int zone, std::vector<RGBColor> colors)
{
unsigned char usb_buf[] =
{
0x00, 0x00, // [0x00-0x01]
0x12, 0x05, 0x00, 0x00, // [0x02-0x05]
0x00, 0x00, 0x00, 0x00, // [0x06-0x09]
0x00, 0x00, 0x00, 0x00, // [0x0A-0x0D]
0x00, 0x00, 0x00, 0x00, // [0x0E-0x11]
0x00, 0x00, 0x00, 0x00, // [0x12-0x15]
0x00, 0x00, 0x00, 0x00, // [0x16-0x19]
0x00, 0x00, 0x00, 0x00, // [0x1A-0x1D]
0x00, 0x00, 0x00, 0x00, // [0x1E-0x21]
0x00, 0x00, 0x00, 0x00, // [0x22-0x25]
0x00, 0x00, 0x00, 0x00, // [0x26-0x29]
0x00, 0x00, 0x00, 0x00, // [0x2A-0x2D]
0x00, 0x00, 0x00, 0x00, // [0x2E-0x31]
0x00, 0x00, 0x00, 0x00, // [0x32-0x35] Always 0x00*4
0x00, 0x00, 0x00, 0x00 // [0x36-0x39] zone / 0x01 / theme / speed
};
usb_buf[0x36] = hp_zones[zone].value;
if(hp_zones[zone].mode != HP_OMEN_30L_DIRECT)
{
hid_write(dev, usb_buf, 58);
}
usb_buf[0x37] = 0x01;
usb_buf[0x39] = hp_zones[zone].speed;
usb_buf[0x03] = hp_zones[zone].mode;
usb_buf[0x30] = hp_zones[zone].brightness;
if(hp_zones[zone].mode == HP_OMEN_30L_DIRECT)
{
usb_buf[0x31] = HP_OMEN_30L_DIRECT;
usb_buf[0x04] = 0x01;
}
else
{
usb_buf[0x31] = 0x0A;
}
if(hp_zones[zone].mode == HP_OMEN_30L_DIRECT)
{
usb_buf[0x08] = usb_buf[0x0C] = usb_buf[0x10] = usb_buf[0x14] = 0x64;
usb_buf[0x09] = usb_buf[0x0D] = usb_buf[0x11] = usb_buf[0x15] = RGBGetRValue(colors[zone]);
usb_buf[0x0A] = usb_buf[0x0E] = usb_buf[0x12] = usb_buf[0x16] = RGBGetGValue(colors[zone]);
usb_buf[0x0B] = usb_buf[0x0F] = usb_buf[0x13] = usb_buf[0x17] = RGBGetBValue(colors[zone]);
hid_write(dev, usb_buf, 58);
}
else if(hp_zones[zone].mode == HP_OMEN_30L_STATIC)
{
usb_buf[0x08] = usb_buf[0x0B] = usb_buf[0x0E] = usb_buf[0x11] = RGBGetRValue(colors[zone]);
usb_buf[0x09] = usb_buf[0x0C] = usb_buf[0x0F] = usb_buf[0x12] = RGBGetGValue(colors[zone]);
usb_buf[0x0A] = usb_buf[0x0D] = usb_buf[0x10] = usb_buf[0x13] = RGBGetBValue(colors[zone]);
hid_write(dev, usb_buf, 58);
}
else
{
usb_buf[0x04] = colors.size();
for(int i = 0; i < colors.size(); i++)
{
usb_buf[0x05] = i + 1;
usb_buf[0x08] = usb_buf[0x0B] = usb_buf[0x0E] = usb_buf[0x11] = RGBGetRValue(colors[i]);
usb_buf[0x09] = usb_buf[0x0C] = usb_buf[0x0F] = usb_buf[0x12] = RGBGetGValue(colors[i]);
usb_buf[0x0A] = usb_buf[0x0D] = usb_buf[0x10] = usb_buf[0x13] = RGBGetBValue(colors[i]);
hid_write(dev, usb_buf, 58);
}
}
}

View file

@ -0,0 +1,74 @@
/*-----------------------------------------*\
| HPOmen30LController.h |
| |
| Driver for HP Omen 30L RGB lighting |
| controller |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#include <vector>
#pragma once
typedef struct
{
unsigned char value;
unsigned char mode;
unsigned char speed;
unsigned char brightness;
} hp_zone;
enum
{
HP_OMEN_30L_STATIC = 0x01, /* Static effect channel */
HP_OMEN_30L_DIRECT = 0x04, /* Direct for effects plugin */
HP_OMEN_30L_BREATHING = 0x06, /* Breathing effect channel */
HP_OMEN_30L_COLOR_CYCLE = 0x07, /* Color cycle effect channel */
HP_OMEN_30L_BLINKING = 0x08, /* Led blink */
};
enum
{
HP_OMEN_30L_SPEED_SLOW = 0x01, /* Slow speed */
HP_OMEN_30L_SPEED_MED = 0x02, /* Normal speed */
HP_OMEN_30L_SPEED_FAST = 0x03, /* Fast speed */
};
enum
{
HP_OMEN_30L_LOGO_ZONE = 0x01,
HP_OMEN_30L_BAR_ZONE = 0x02,
HP_OMEN_30L_FAN_ZONE = 0x03,
HP_OMEN_30L_CPU_ZONE = 0x04,
};
class HPOmen30LController
{
public:
HPOmen30LController(hid_device* dev_handle, const char* path);
~HPOmen30LController();
char* GetDeviceName();
std::string GetEffectChannelString(unsigned char channel);
std::string GetFirmwareVersionString();
std::string GetLocationString();
std::string GetSerialString();
void SetRingEffectChannel(unsigned char channel);
void SetZoneMode(int zone,unsigned char mode, unsigned char speed, unsigned char brightness);
void SetZoneColor(int zone, std::vector<RGBColor> colors);
private:
char device_name[32];
hid_device* dev;
std::string location;
std::vector<hp_zone> hp_zones;
void SendZoneUpdate(int zone, std::vector<RGBColor> colors);
};

View file

@ -0,0 +1,31 @@
#include "Detector.h"
#include "HPOmen30LController.h"
#include "RGBController.h"
#include "RGBController_HPOmen30L.h"
#include <hidapi/hidapi.h>
#define HP_OMEN_30L_VID 0x103C
#define HP_OMEN_30L_PID 0x84FD
/******************************************************************************************\
* *
* DetectHPOmen30LController *
* *
* Tests the USB address to see if an HP Omen 30L controller exists there. *
* *
\******************************************************************************************/
void DetectHPOmen30LController(hid_device_info* info, const std::string&)
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
HPOmen30LController* controller = new HPOmen30LController(dev, info->path);
RGBController_HPOmen30L* rgb_controller = new RGBController_HPOmen30L(controller);
// Constructor sets the name
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
REGISTER_HID_DETECTOR("HP Omen 30L", DetectHPOmen30LController, HP_OMEN_30L_VID, HP_OMEN_30L_PID);

View file

@ -0,0 +1,205 @@
/*-----------------------------------------*\
| RGBController_HPOmen30L.cpp |
| |
| Generic RGB Interface for HP Omen 30L |
\*-----------------------------------------*/
#include "RGBController_HPOmen30L.h"
RGBController_HPOmen30L::RGBController_HPOmen30L(HPOmen30LController* omen_ptr)
{
omen = omen_ptr;
name = "HP Omen 30L";
vendor = "HP";
type = DEVICE_TYPE_MOTHERBOARD;
description = "HP Omen 30L Device";
version = "";
location = omen->GetLocationString();
serial = "";
mode Direct;
Direct.name = "Direct";
Direct.value = HP_OMEN_30L_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
Direct.color_mode = MODE_COLORS_PER_LED;
Direct.brightness_min = 0;
Direct.brightness_max = 100;
Direct.brightness = 100;
modes.push_back(Direct);
mode Static;
Static.name = "Static";
Static.value = HP_OMEN_30L_STATIC;
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
Static.color_mode = MODE_COLORS_PER_LED;
Static.brightness_min = 0;
Static.brightness_max = 100;
Static.brightness = 100;
modes.push_back(Static);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = HP_OMEN_30L_BREATHING;
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
Breathing.speed_min = HP_OMEN_30L_SPEED_SLOW;
Breathing.speed_max = HP_OMEN_30L_SPEED_FAST;
Breathing.speed = HP_OMEN_30L_SPEED_MED;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.colors_min = 1;
Breathing.colors_max = 6;
Breathing.colors.resize(4);
Breathing.brightness_min = 0;
Breathing.brightness_max = 100;
Breathing.brightness = 100;
modes.push_back(Breathing);
mode ColorCycle;
ColorCycle.name = "Color Cycle";
ColorCycle.value = HP_OMEN_30L_COLOR_CYCLE;
ColorCycle.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
ColorCycle.speed_min = HP_OMEN_30L_SPEED_SLOW;
ColorCycle.speed_max = HP_OMEN_30L_SPEED_FAST;
ColorCycle.speed = HP_OMEN_30L_SPEED_MED;
ColorCycle.color_mode = MODE_COLORS_MODE_SPECIFIC;
ColorCycle.colors_min = 1;
ColorCycle.colors_max = 6;
ColorCycle.colors.resize(4);
ColorCycle.brightness_min = 0;
ColorCycle.brightness_max = 100;
ColorCycle.brightness = 100;
modes.push_back(ColorCycle);
mode Blinking;
Blinking.name = "Blinking";
Blinking.value = HP_OMEN_30L_BLINKING;
Blinking.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
Blinking.speed_min = HP_OMEN_30L_SPEED_SLOW;
Blinking.speed_max = HP_OMEN_30L_SPEED_FAST;
Blinking.speed = HP_OMEN_30L_SPEED_MED;
Blinking.color_mode = MODE_COLORS_MODE_SPECIFIC;
Blinking.colors_min = 1;
Blinking.colors_max = 6;
Blinking.colors.resize(4);
Blinking.brightness_min = 0;
Blinking.brightness_max = 100;
Blinking.brightness = 100;
modes.push_back(Blinking);
SetupZones();
}
RGBController_HPOmen30L::~RGBController_HPOmen30L()
{
delete omen;
}
void RGBController_HPOmen30L::SetupZones()
{
/*---------------------------------------------------------*\
| Set up zones |
\*---------------------------------------------------------*/
zone logo_zone;
logo_zone.name = "Omen Logo";
logo_zone.type = ZONE_TYPE_SINGLE;
logo_zone.leds_min = 1;
logo_zone.leds_max = 1;
logo_zone.leds_count = 1;
logo_zone.matrix_map = NULL;
zones.push_back(logo_zone);
zone light_bar;
light_bar.name = "Light Bar";
light_bar.type = ZONE_TYPE_SINGLE;
light_bar.leds_min = 1;
light_bar.leds_max = 1;
light_bar.leds_count = 1;
light_bar.matrix_map = NULL;
zones.push_back(light_bar);
zone ring_zone;
ring_zone.name = "Front Fan";
ring_zone.type = ZONE_TYPE_SINGLE;
ring_zone.leds_min = 1;
ring_zone.leds_max = 1;
ring_zone.leds_count = 1;
ring_zone.matrix_map = NULL;
zones.push_back(ring_zone);
zone cpu_zone;
cpu_zone.name = "CPU Cooler";
cpu_zone.type = ZONE_TYPE_SINGLE;
cpu_zone.leds_min = 1;
cpu_zone.leds_max = 1;
cpu_zone.leds_count = 1;
cpu_zone.matrix_map = NULL;
zones.push_back(cpu_zone);
/*---------------------------------------------------------*\
| Set up LEDs |
\*---------------------------------------------------------*/
led logo_led;
logo_led.name = "Logo LED";
leds.push_back(logo_led);
led bar_led;
bar_led.name = "Bar LED";
leds.push_back(bar_led);
led fan_led;
fan_led.name = "Fan LED";
leds.push_back(fan_led);
led cpu_led;
cpu_led.name = "CPU LED";
leds.push_back(cpu_led);
SetupColors();
}
void RGBController_HPOmen30L::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_HPOmen30L::DeviceUpdateLEDs()
{
for(int i = 0; i < zones.size(); i++)
{
if(modes[active_mode].value == HP_OMEN_30L_STATIC || modes[active_mode].value == HP_OMEN_30L_DIRECT)
{
omen->SetZoneColor(i, colors);
}
else
{
omen->SetZoneColor(i, modes[active_mode].colors);
}
}
}
void RGBController_HPOmen30L::UpdateZoneLEDs(int zone)
{
omen->SetZoneColor(zone,colors);
}
void RGBController_HPOmen30L::UpdateSingleLED(int led)
{
UpdateZoneLEDs(led);
}
void RGBController_HPOmen30L::SetCustomMode()
{
active_mode = 0;
}
void RGBController_HPOmen30L::DeviceUpdateMode()
{
for(int i = 0; i < zones.size(); i++)
{
omen->SetZoneMode(i, modes[active_mode].value, modes[active_mode].speed, modes[active_mode].brightness);
}
DeviceUpdateLEDs();
}

View file

@ -0,0 +1,31 @@
/*-----------------------------------------*\
| RGBController_HPOmen30L.h |
| |
| Generic RGB Interface for HP Omen 30L |
| |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "HPOmen30LController.h"
class RGBController_HPOmen30L : public RGBController
{
public:
RGBController_HPOmen30L(HPOmen30LController* omen_ptr);
~RGBController_HPOmen30L();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
HPOmen30LController* omen;
};

View file

@ -100,6 +100,7 @@ INCLUDEPATH +=
Controllers/GigabyteRGBFusionController/ \
Controllers/GigabyteRGBFusionGPUController/ \
Controllers/HoltekController/ \
Controllers/HPOmen30LController/ \
Controllers/HyperXDRAMController/ \
Controllers/HyperXKeyboardController/ \
Controllers/HyperXMouseController/ \
@ -276,6 +277,8 @@ HEADERS +=
Controllers/HoltekController/HoltekA1FAController.h \
Controllers/HoltekController/RGBController_HoltekA070.h \
Controllers/HoltekController/RGBController_HoltekA1FA.h \
Controllers/HPOmen30LController/HPOmen30LController.h \
Controllers/HPOmen30LController/RGBController_HPOmen30L.h \
Controllers/HyperXDRAMController/HyperXDRAMController.h \
Controllers/HyperXDRAMController/RGBController_HyperXDRAM.h \
Controllers/HyperXKeyboardController/HyperXAlloyElite2Controller.h \
@ -607,6 +610,9 @@ SOURCES +=
Controllers/HoltekController/HoltekControllerDetect.cpp \
Controllers/HoltekController/RGBController_HoltekA070.cpp \
Controllers/HoltekController/RGBController_HoltekA1FA.cpp \
Controllers/HPOmen30LController/HPOmen30LController.cpp \
Controllers/HPOmen30LController/HPOmen30LControllerDetect.cpp \
Controllers/HPOmen30LController/RGBController_HPOmen30L.cpp \
Controllers/HyperXDRAMController/HyperXDRAMController.cpp \
Controllers/HyperXDRAMController/HyperXDRAMControllerDetect.cpp \
Controllers/HyperXDRAMController/RGBController_HyperXDRAM.cpp \