mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 09:16:11 +00:00
Add G410 support
This commit is contained in:
parent
841176763a
commit
44e029c57d
@ -12,12 +12,12 @@ bool Keyboard::isAttached() {
|
|||||||
return m_isAttached;
|
return m_isAttached;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Keyboard::attach() {
|
bool Keyboard::attach(int lg_pid) {
|
||||||
if (m_isAttached == true) return false;
|
if (m_isAttached == true) return false;
|
||||||
int r;
|
int r;
|
||||||
r = libusb_init(&ctx);
|
r = libusb_init(&ctx);
|
||||||
if (r < 0) return false;
|
if (r < 0) return false;
|
||||||
dev_handle = libusb_open_device_with_vid_pid(ctx, 0x046d, 0xc331);
|
dev_handle = libusb_open_device_with_vid_pid(ctx, 0x046d, lg_pid);
|
||||||
if (dev_handle == NULL) {
|
if (dev_handle == NULL) {
|
||||||
libusb_exit(ctx);
|
libusb_exit(ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
|
@ -33,7 +33,7 @@ class Keyboard {
|
|||||||
struct KeyValue { KeyAddress key; KeyColors colors; };
|
struct KeyValue { KeyAddress key; KeyColors colors; };
|
||||||
|
|
||||||
bool isAttached();
|
bool isAttached();
|
||||||
bool attach();
|
bool attach(int lg_pid);
|
||||||
bool detach();
|
bool detach();
|
||||||
bool commit();
|
bool commit();
|
||||||
bool getKeyAddress(Key key, KeyAddress &keyAddress);
|
bool getKeyAddress(Key key, KeyAddress &keyAddress);
|
||||||
|
21
src/main.cpp
21
src/main.cpp
@ -4,13 +4,16 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
#include "classes/Keyboard.h"
|
#include "classes/Keyboard.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
int lg_pid = 0xc331;
|
||||||
|
|
||||||
void usage() {
|
void usage() {
|
||||||
cout<<"g810-led Usages :\n";
|
if (lg_pid == 0xc330) cout << "g410-led Usages :\n";
|
||||||
|
else cout<<"g810-led Usages :\n";
|
||||||
cout<<"-----------------\n";
|
cout<<"-----------------\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -s effect :\t\tSet keyboard startup effect\n";
|
cout<<" -s effect :\t\tSet keyboard startup effect\n";
|
||||||
@ -44,7 +47,7 @@ void usage() {
|
|||||||
|
|
||||||
int commit() {
|
int commit() {
|
||||||
Keyboard g810;
|
Keyboard g810;
|
||||||
g810.attach();
|
g810.attach(lg_pid);
|
||||||
g810.commit();
|
g810.commit();
|
||||||
g810.detach();
|
g810.detach();
|
||||||
|
|
||||||
@ -55,7 +58,7 @@ int setStartupEffect(string effect) {
|
|||||||
Keyboard g810;
|
Keyboard g810;
|
||||||
Keyboard::PowerOnEffect powerOnEffect;
|
Keyboard::PowerOnEffect powerOnEffect;
|
||||||
if (g810.parsePowerOnEffect(effect, powerOnEffect) == true) {
|
if (g810.parsePowerOnEffect(effect, powerOnEffect) == true) {
|
||||||
g810.attach();
|
g810.attach(lg_pid);
|
||||||
g810.setPowerOnEffect(powerOnEffect);
|
g810.setPowerOnEffect(powerOnEffect);
|
||||||
g810.commit();
|
g810.commit();
|
||||||
g810.detach();
|
g810.detach();
|
||||||
@ -73,7 +76,7 @@ int setKey(string key, string color, bool commit) {
|
|||||||
Keyboard::KeyValue keyValue;
|
Keyboard::KeyValue keyValue;
|
||||||
keyValue.key = keyAddress;
|
keyValue.key = keyAddress;
|
||||||
keyValue.colors = colors;
|
keyValue.colors = colors;
|
||||||
g810.attach();
|
g810.attach(lg_pid);
|
||||||
g810.setKey(keyValue);
|
g810.setKey(keyValue);
|
||||||
if (commit == true) g810.commit();
|
if (commit == true) g810.commit();
|
||||||
g810.detach();
|
g810.detach();
|
||||||
@ -87,7 +90,7 @@ int setAllKeys(string color, bool commit) {
|
|||||||
Keyboard g810;
|
Keyboard g810;
|
||||||
Keyboard::KeyColors colors;
|
Keyboard::KeyColors colors;
|
||||||
if (g810.parseColor(color, colors) == true) {
|
if (g810.parseColor(color, colors) == true) {
|
||||||
g810.attach();
|
g810.attach(lg_pid);
|
||||||
g810.setAllKeys(colors);
|
g810.setAllKeys(colors);
|
||||||
if (commit == true) g810.commit();
|
if (commit == true) g810.commit();
|
||||||
g810.detach();
|
g810.detach();
|
||||||
@ -102,7 +105,7 @@ int setGroupKeys(string groupKeys, string color, bool commit) {
|
|||||||
if (g810.parseKeyGroup(groupKeys, keyGroup) == true) {
|
if (g810.parseKeyGroup(groupKeys, keyGroup) == true) {
|
||||||
Keyboard::KeyColors colors;
|
Keyboard::KeyColors colors;
|
||||||
if (g810.parseColor(color, colors) == true) {
|
if (g810.parseColor(color, colors) == true) {
|
||||||
g810.attach();
|
g810.attach(lg_pid);
|
||||||
g810.setGroupKeys(keyGroup, colors);
|
g810.setGroupKeys(keyGroup, colors);
|
||||||
if (commit == true) g810.commit();
|
if (commit == true) g810.commit();
|
||||||
g810.detach();
|
g810.detach();
|
||||||
@ -131,7 +134,7 @@ int loadProfile(string profileFile) {
|
|||||||
map<string, string> var;
|
map<string, string> var;
|
||||||
vector<Keyboard::KeyValue> keys;
|
vector<Keyboard::KeyValue> keys;
|
||||||
|
|
||||||
g810.attach();
|
g810.attach(lg_pid);
|
||||||
|
|
||||||
while (!file.eof()) {
|
while (!file.eof()) {
|
||||||
getline(file, line);
|
getline(file, line);
|
||||||
@ -204,6 +207,10 @@ int loadProfile(string profileFile) {
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
string str = argv[0];
|
||||||
|
size_t split = str.find_last_of("/\\");
|
||||||
|
str = str.substr(split + 1);
|
||||||
|
if (str == "g410-led") lg_pid = 0xc330;
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
string argCmd = argv[1];
|
string argCmd = argv[1];
|
||||||
if (argCmd == "-h" || argCmd == "--help") { usage(); return 0; }
|
if (argCmd == "-h" || argCmd == "--help") { usage(); return 0; }
|
||||||
|
Loading…
Reference in New Issue
Block a user