1+ /* -----------------------------------------*\
2+ | HPOmen30LController.cpp |
3+ | |
4+ | Driver for HP Omen 30L RGB lighting |
5+ | controller |
6+ \*-----------------------------------------*/
7+
8+ #include " HPOmen30LController.h"
9+ #include < cstring>
10+ #include < stdio.h>
11+ #include < stdlib.h>
12+
13+ HPOmen30LController::HPOmen30LController (hid_device* dev_handle, const char * path)
14+ {
15+ dev = dev_handle;
16+ location = path;
17+
18+ strcpy (device_name, " HP Omen 30L" );
19+
20+ hp_zone logo;
21+ logo.value = HP_OMEN_30L_LOGO_ZONE;
22+ logo.mode = HP_OMEN_30L_DIRECT;
23+ logo.speed = HP_OMEN_30L_SPEED_MED;
24+ logo.brightness = 0x64 ;
25+ hp_zones.push_back (logo);
26+
27+ hp_zone bar;
28+ bar.value = HP_OMEN_30L_BAR_ZONE;
29+ bar.mode = HP_OMEN_30L_DIRECT;
30+ bar.speed = HP_OMEN_30L_SPEED_MED;
31+ bar.brightness = 0x64 ;
32+ hp_zones.push_back (bar);
33+
34+ hp_zone fan;
35+ fan.value = HP_OMEN_30L_FAN_ZONE;
36+ fan.mode = HP_OMEN_30L_DIRECT;
37+ fan.speed = HP_OMEN_30L_SPEED_MED;
38+ fan.brightness = 0x64 ;
39+ hp_zones.push_back (fan);
40+
41+ hp_zone cpu;
42+ cpu.value = HP_OMEN_30L_CPU_ZONE;
43+ cpu.mode = HP_OMEN_30L_DIRECT;
44+ cpu.speed = HP_OMEN_30L_SPEED_MED;
45+ cpu.brightness = 0x64 ;
46+ hp_zones.push_back (cpu);
47+
48+ }
49+
50+ HPOmen30LController::~HPOmen30LController ()
51+ {
52+ hid_close (dev);
53+ }
54+
55+ std::string HPOmen30LController::GetLocationString ()
56+ {
57+ return (" HID: " + location);
58+ }
59+
60+ char * HPOmen30LController::GetDeviceName ()
61+ {
62+ return device_name;
63+ }
64+
65+ std::string HPOmen30LController::GetSerialString ()
66+ {
67+ std::string ret_string = " " ;
68+ return (ret_string);
69+ }
70+
71+ std::string HPOmen30LController::GetEffectChannelString (unsigned char channel)
72+ {
73+ std::string ret_string = " " ;
74+ return (ret_string);
75+ }
76+
77+ std::string HPOmen30LController::GetFirmwareVersionString ()
78+ {
79+ std::string ret_string = " " ;
80+ return (ret_string);
81+ }
82+
83+ void HPOmen30LController::SetZoneMode (int zone,unsigned char mode, unsigned char speed,unsigned char brightness)
84+ {
85+ hp_zones[zone].mode = mode;
86+ hp_zones[zone].speed = speed;
87+ hp_zones[zone].brightness = brightness;
88+
89+ }
90+
91+ void HPOmen30LController::SetZoneColor (int zone, std::vector<RGBColor> colors)
92+ {
93+ SendZoneUpdate (zone, colors);
94+ }
95+
96+ void HPOmen30LController::SendZoneUpdate (int zone, std::vector<RGBColor> colors)
97+ {
98+ unsigned char usb_buf[] =
99+ {
100+ 0x00 , 0x00 , // [0x00-0x01]
101+ 0x12 , 0x05 , 0x00 , 0x00 , // [0x02-0x05]
102+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x06-0x09]
103+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x0A-0x0D]
104+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x0E-0x11]
105+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x12-0x15]
106+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x16-0x19]
107+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x1A-0x1D]
108+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x1E-0x21]
109+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x22-0x25]
110+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x26-0x29]
111+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x2A-0x2D]
112+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x2E-0x31]
113+ 0x00 , 0x00 , 0x00 , 0x00 , // [0x32-0x35] Always 0x00*4
114+ 0x00 , 0x00 , 0x00 , 0x00 // [0x36-0x39] zone / 0x01 / theme / speed
115+ };
116+
117+ usb_buf[0x36 ] = hp_zones[zone].value ;
118+
119+ if (hp_zones[zone].mode != HP_OMEN_30L_DIRECT)
120+ {
121+ hid_write (dev, usb_buf, 58 );
122+ }
123+
124+ usb_buf[0x37 ] = 0x01 ;
125+ usb_buf[0x39 ] = hp_zones[zone].speed ;
126+ usb_buf[0x03 ] = hp_zones[zone].mode ;
127+ usb_buf[0x30 ] = hp_zones[zone].brightness ;
128+
129+ if (hp_zones[zone].mode == HP_OMEN_30L_DIRECT)
130+ {
131+ usb_buf[0x31 ] = HP_OMEN_30L_DIRECT;
132+ usb_buf[0x04 ] = 0x01 ;
133+ }
134+ else
135+ {
136+ usb_buf[0x31 ] = 0x0A ;
137+ }
138+
139+ if (hp_zones[zone].mode == HP_OMEN_30L_DIRECT)
140+ {
141+ usb_buf[0x08 ] = usb_buf[0x0C ] = usb_buf[0x10 ] = usb_buf[0x14 ] = 0x64 ;
142+ usb_buf[0x09 ] = usb_buf[0x0D ] = usb_buf[0x11 ] = usb_buf[0x15 ] = RGBGetRValue (colors[zone]);
143+ usb_buf[0x0A ] = usb_buf[0x0E ] = usb_buf[0x12 ] = usb_buf[0x16 ] = RGBGetGValue (colors[zone]);
144+ usb_buf[0x0B ] = usb_buf[0x0F ] = usb_buf[0x13 ] = usb_buf[0x17 ] = RGBGetBValue (colors[zone]);
145+
146+ hid_write (dev, usb_buf, 58 );
147+ }
148+ else if (hp_zones[zone].mode == HP_OMEN_30L_STATIC)
149+ {
150+ usb_buf[0x08 ] = usb_buf[0x0B ] = usb_buf[0x0E ] = usb_buf[0x11 ] = RGBGetRValue (colors[zone]);
151+ usb_buf[0x09 ] = usb_buf[0x0C ] = usb_buf[0x0F ] = usb_buf[0x12 ] = RGBGetGValue (colors[zone]);
152+ usb_buf[0x0A ] = usb_buf[0x0D ] = usb_buf[0x10 ] = usb_buf[0x13 ] = RGBGetBValue (colors[zone]);
153+
154+ hid_write (dev, usb_buf, 58 );
155+ }
156+ else
157+ {
158+ usb_buf[0x04 ] = colors.size ();
159+
160+ for (int i = 0 ; i < colors.size (); i++)
161+ {
162+ usb_buf[0x05 ] = i + 1 ;
163+
164+ usb_buf[0x08 ] = usb_buf[0x0B ] = usb_buf[0x0E ] = usb_buf[0x11 ] = RGBGetRValue (colors[i]);
165+ usb_buf[0x09 ] = usb_buf[0x0C ] = usb_buf[0x0F ] = usb_buf[0x12 ] = RGBGetGValue (colors[i]);
166+ usb_buf[0x0A ] = usb_buf[0x0D ] = usb_buf[0x10 ] = usb_buf[0x13 ] = RGBGetBValue (colors[i]);
167+
168+ hid_write (dev, usb_buf, 58 );
169+ }
170+ }
171+ }
0 commit comments