mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 09:16:11 +00:00
Add profile pipe support
This commit is contained in:
parent
338876a006
commit
3596a85315
339
src/main.cpp
339
src/main.cpp
@ -1,7 +1,9 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <istream>
|
||||||
#include "classes/Keyboard.h"
|
#include "classes/Keyboard.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -29,7 +31,8 @@ void usage() {
|
|||||||
cout<<" -fx-vwave speed :\t\tSet vertical color wave effect\n";
|
cout<<" -fx-vwave speed :\t\tSet vertical color wave effect\n";
|
||||||
cout<<" -fx-cwave speed :\t\tSet center color wave effect\n";
|
cout<<" -fx-cwave speed :\t\tSet center color wave effect\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -p profilefile :\t\tLoad a profile\n";
|
cout<<" -p profilefile :\t\tLoad a profile from a file\n";
|
||||||
|
cout<<" -pp profilepipe :\t\tLoad a profile from stdin\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -h | --help :\t\t\tthis help message\n";
|
cout<<" -h | --help :\t\t\tthis help message\n";
|
||||||
cout<<" -lk | --list-keys :\t\tList keys in groups\n";
|
cout<<" -lk | --list-keys :\t\tList keys in groups\n";
|
||||||
@ -325,194 +328,201 @@ int setFXCWave(string speed) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadProfile(string profileFile) {
|
int parseProfile(istream &is) {
|
||||||
ifstream file;
|
string line;
|
||||||
|
int lineCount = 1;
|
||||||
|
int ind;
|
||||||
|
|
||||||
file.open(profileFile);
|
Keyboard lg_kbd;
|
||||||
if (file.is_open()) {
|
Keyboard::KeyGroup keyGroup;
|
||||||
|
Keyboard::KeyAddress keyAddress;
|
||||||
|
Keyboard::KeyValue keyValue;
|
||||||
|
Keyboard::KeyColors colors;
|
||||||
|
uint8_t speedValue;
|
||||||
|
|
||||||
string line;
|
map<string, string> var;
|
||||||
int lineCount = 1;
|
vector<Keyboard::KeyValue> keys;
|
||||||
int ind;
|
|
||||||
|
|
||||||
Keyboard lg_kbd;
|
lg_kbd.attach();
|
||||||
Keyboard::KeyGroup keyGroup;
|
|
||||||
Keyboard::KeyAddress keyAddress;
|
|
||||||
Keyboard::KeyValue keyValue;
|
|
||||||
Keyboard::KeyColors colors;
|
|
||||||
uint8_t speedValue;
|
|
||||||
|
|
||||||
map<string, string> var;
|
while (!is.eof()) {
|
||||||
vector<Keyboard::KeyValue> keys;
|
getline(is, line);
|
||||||
|
|
||||||
lg_kbd.attach();
|
if (line.substr(0, 3) == "var") {
|
||||||
|
line = line.substr(4);
|
||||||
while (!file.eof()) {
|
ind = line.find(" ");
|
||||||
getline(file, line);
|
var[line.substr(0, ind)] = line.substr(ind + 1, 6);
|
||||||
|
} else if (line.substr(0, 1) == "a") {
|
||||||
if (line.substr(0, 3) == "var") {
|
line = line.substr(2);
|
||||||
line = line.substr(4);
|
if (line.substr(0, 1) == "$") {
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
var[line.substr(0, ind)] = line.substr(ind + 1, 6);
|
line = var[line.substr(1, ind - 1)];
|
||||||
} else if (line.substr(0, 1) == "a") {
|
} else line = line.substr(0, 6);
|
||||||
line = line.substr(2);
|
if (lg_kbd.parseColor(line, colors) == true) {
|
||||||
if (line.substr(0, 1) == "$") {
|
|
||||||
ind = line.find(" ");
|
|
||||||
line = var[line.substr(1, ind - 1)];
|
|
||||||
} else line = line.substr(0, 6);
|
|
||||||
if (lg_kbd.parseColor(line, colors) == true) {
|
|
||||||
keys.clear();
|
|
||||||
lg_kbd.setAllKeys(colors);
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else if (line.substr(0,1) == "g") {
|
|
||||||
line = line.substr(2);
|
|
||||||
ind = line.find(" ");
|
|
||||||
if (lg_kbd.parseKeyGroup(line.substr(0, ind), keyGroup) == true) {
|
|
||||||
line = line.substr(ind + 1);
|
|
||||||
if (line.substr(0, 1) == "$") {
|
|
||||||
ind = line.find(" ");
|
|
||||||
line = var[line.substr(1, ind - 1)];
|
|
||||||
};
|
|
||||||
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
|
||||||
lg_kbd.setGroupKeys(keyGroup, colors);
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else if (line.substr(0,1) == "k") {
|
|
||||||
line = line.substr(2);
|
|
||||||
ind = line.find(" ");
|
|
||||||
if (lg_kbd.parseKey(line.substr(0, ind), keyAddress) == true) {
|
|
||||||
line = line.substr(ind + 1);
|
|
||||||
if (line.substr(0, 1) == "$") {
|
|
||||||
ind = line.find(" ");
|
|
||||||
line = var[line.substr(1, ind - 1)];
|
|
||||||
}
|
|
||||||
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
|
||||||
keyValue.key = keyAddress;
|
|
||||||
keyValue.colors = colors;
|
|
||||||
keys.push_back(keyValue);
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else if (line.substr(0,1) == "c") {
|
|
||||||
lg_kbd.commit();
|
|
||||||
lg_kbd.setKeys(&keys[0], keys.size());
|
|
||||||
keys.clear();
|
keys.clear();
|
||||||
lg_kbd.commit();
|
lg_kbd.setAllKeys(colors);
|
||||||
} else if (line.substr(0,8) == "fx-color") {
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
line = line.substr(9);
|
} else if (line.substr(0,1) == "g") {
|
||||||
|
line = line.substr(2);
|
||||||
|
ind = line.find(" ");
|
||||||
|
if (lg_kbd.parseKeyGroup(line.substr(0, ind), keyGroup) == true) {
|
||||||
|
line = line.substr(ind + 1);
|
||||||
if (line.substr(0, 1) == "$") {
|
if (line.substr(0, 1) == "$") {
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
line = var[line.substr(1, ind - 1)];
|
line = var[line.substr(1, ind - 1)];
|
||||||
} else line = line.substr(0, 6);
|
};
|
||||||
if (lg_kbd.parseColor(line, colors) == true) {
|
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
||||||
keys.clear();
|
lg_kbd.setGroupKeys(keyGroup, colors);
|
||||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
|
||||||
lg_kbd.commit();
|
|
||||||
lg_kbd.detach();
|
|
||||||
lg_kbd.attach();
|
|
||||||
lg_kbd.setFXColor(colors);
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
} else if (line.substr(0,12) == "fx-breathing") {
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
line = line.substr(13);
|
} else if (line.substr(0,1) == "k") {
|
||||||
|
line = line.substr(2);
|
||||||
|
ind = line.find(" ");
|
||||||
|
if (lg_kbd.parseKey(line.substr(0, ind), keyAddress) == true) {
|
||||||
|
line = line.substr(ind + 1);
|
||||||
if (line.substr(0, 1) == "$") {
|
if (line.substr(0, 1) == "$") {
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
line = var[line.substr(1, ind - 1)] + " " + line.substr(ind + 1);
|
line = var[line.substr(1, ind - 1)];
|
||||||
}
|
}
|
||||||
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
||||||
ind = line.find(" ");
|
keyValue.key = keyAddress;
|
||||||
line = line.substr(ind + 1, 2);
|
keyValue.colors = colors;
|
||||||
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
keys.push_back(keyValue);
|
||||||
keys.clear();
|
|
||||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
|
||||||
lg_kbd.commit();
|
|
||||||
lg_kbd.detach();
|
|
||||||
lg_kbd.attach();
|
|
||||||
lg_kbd.setFXBreathing(colors, speedValue);
|
|
||||||
} else cout<<"Error1 on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else cout<<"Error2 on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else if (line.substr(0,8) == "fx-cycle") {
|
|
||||||
line = line.substr(9);
|
|
||||||
if (line.substr(0, 1) == "$") {
|
|
||||||
ind = line.find(" ");
|
|
||||||
line = var[line.substr(1, ind - 1)];
|
|
||||||
} else line = line.substr(0, 2);
|
|
||||||
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
|
||||||
keys.clear();
|
|
||||||
colors.red = 0xff;
|
|
||||||
colors.green = 0xff;
|
|
||||||
colors.blue = 0xff;
|
|
||||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
|
||||||
lg_kbd.commit();
|
|
||||||
lg_kbd.detach();
|
|
||||||
lg_kbd.attach();
|
|
||||||
lg_kbd.setFXColorCycle(speedValue);
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
} else if (line.substr(0,8) == "fx-hwave") {
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
line = line.substr(9);
|
} else if (line.substr(0,1) == "c") {
|
||||||
if (line.substr(0, 1) == "$") {
|
lg_kbd.commit();
|
||||||
ind = line.find(" ");
|
lg_kbd.setKeys(&keys[0], keys.size());
|
||||||
line = var[line.substr(1, ind - 1)];
|
keys.clear();
|
||||||
} else line = line.substr(0, 2);
|
lg_kbd.commit();
|
||||||
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
} else if (line.substr(0,8) == "fx-color") {
|
||||||
keys.clear();
|
line = line.substr(9);
|
||||||
colors.red = 0xff;
|
if (line.substr(0, 1) == "$") {
|
||||||
colors.green = 0xff;
|
ind = line.find(" ");
|
||||||
colors.blue = 0xff;
|
line = var[line.substr(1, ind - 1)];
|
||||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
} else line = line.substr(0, 6);
|
||||||
lg_kbd.commit();
|
if (lg_kbd.parseColor(line, colors) == true) {
|
||||||
lg_kbd.detach();
|
keys.clear();
|
||||||
lg_kbd.attach();
|
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||||
lg_kbd.setFXHWave(speedValue);
|
lg_kbd.commit();
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
lg_kbd.detach();
|
||||||
} else if (line.substr(0,8) == "fx-vwave") {
|
lg_kbd.attach();
|
||||||
line = line.substr(9);
|
lg_kbd.setFXColor(colors);
|
||||||
if (line.substr(0, 1) == "$") {
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
ind = line.find(" ");
|
} else if (line.substr(0,12) == "fx-breathing") {
|
||||||
line = var[line.substr(1, ind - 1)];
|
line = line.substr(13);
|
||||||
} else line = line.substr(0, 2);
|
if (line.substr(0, 1) == "$") {
|
||||||
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
ind = line.find(" ");
|
||||||
keys.clear();
|
line = var[line.substr(1, ind - 1)] + " " + line.substr(ind + 1);
|
||||||
colors.red = 0xff;
|
|
||||||
colors.green = 0xff;
|
|
||||||
colors.blue = 0xff;
|
|
||||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
|
||||||
lg_kbd.commit();
|
|
||||||
lg_kbd.detach();
|
|
||||||
lg_kbd.attach();
|
|
||||||
lg_kbd.setFXVWave(speedValue);
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else if (line.substr(0,8) == "fx-cwave") {
|
|
||||||
line = line.substr(9);
|
|
||||||
if (line.substr(0, 1) == "$") {
|
|
||||||
ind = line.find(" ");
|
|
||||||
line = var[line.substr(1, ind - 1)];
|
|
||||||
} else line = line.substr(0, 2);
|
|
||||||
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
|
||||||
keys.clear();
|
|
||||||
colors.red = 0xff;
|
|
||||||
colors.green = 0xff;
|
|
||||||
colors.blue = 0xff;
|
|
||||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
|
||||||
lg_kbd.commit();
|
|
||||||
lg_kbd.detach();
|
|
||||||
lg_kbd.attach();
|
|
||||||
lg_kbd.setFXCWave(speedValue);
|
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
} else if ((line.substr(0, 1) != "#") && (line.substr(0, 1) != "")) {
|
|
||||||
cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
|
||||||
}
|
}
|
||||||
|
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
||||||
lineCount++;
|
ind = line.find(" ");
|
||||||
|
line = line.substr(ind + 1, 2);
|
||||||
|
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
||||||
|
keys.clear();
|
||||||
|
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||||
|
lg_kbd.commit();
|
||||||
|
lg_kbd.detach();
|
||||||
|
lg_kbd.attach();
|
||||||
|
lg_kbd.setFXBreathing(colors, speedValue);
|
||||||
|
} else cout<<"Error1 on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
|
} else cout<<"Error2 on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
|
} else if (line.substr(0,8) == "fx-cycle") {
|
||||||
|
line = line.substr(9);
|
||||||
|
if (line.substr(0, 1) == "$") {
|
||||||
|
ind = line.find(" ");
|
||||||
|
line = var[line.substr(1, ind - 1)];
|
||||||
|
} else line = line.substr(0, 2);
|
||||||
|
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
||||||
|
keys.clear();
|
||||||
|
colors.red = 0xff;
|
||||||
|
colors.green = 0xff;
|
||||||
|
colors.blue = 0xff;
|
||||||
|
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||||
|
lg_kbd.commit();
|
||||||
|
lg_kbd.detach();
|
||||||
|
lg_kbd.attach();
|
||||||
|
lg_kbd.setFXColorCycle(speedValue);
|
||||||
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
|
} else if (line.substr(0,8) == "fx-hwave") {
|
||||||
|
line = line.substr(9);
|
||||||
|
if (line.substr(0, 1) == "$") {
|
||||||
|
ind = line.find(" ");
|
||||||
|
line = var[line.substr(1, ind - 1)];
|
||||||
|
} else line = line.substr(0, 2);
|
||||||
|
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
||||||
|
keys.clear();
|
||||||
|
colors.red = 0xff;
|
||||||
|
colors.green = 0xff;
|
||||||
|
colors.blue = 0xff;
|
||||||
|
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||||
|
lg_kbd.commit();
|
||||||
|
lg_kbd.detach();
|
||||||
|
lg_kbd.attach();
|
||||||
|
lg_kbd.setFXHWave(speedValue);
|
||||||
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
|
} else if (line.substr(0,8) == "fx-vwave") {
|
||||||
|
line = line.substr(9);
|
||||||
|
if (line.substr(0, 1) == "$") {
|
||||||
|
ind = line.find(" ");
|
||||||
|
line = var[line.substr(1, ind - 1)];
|
||||||
|
} else line = line.substr(0, 2);
|
||||||
|
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
||||||
|
keys.clear();
|
||||||
|
colors.red = 0xff;
|
||||||
|
colors.green = 0xff;
|
||||||
|
colors.blue = 0xff;
|
||||||
|
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||||
|
lg_kbd.commit();
|
||||||
|
lg_kbd.detach();
|
||||||
|
lg_kbd.attach();
|
||||||
|
lg_kbd.setFXVWave(speedValue);
|
||||||
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
|
} else if (line.substr(0,8) == "fx-cwave") {
|
||||||
|
line = line.substr(9);
|
||||||
|
if (line.substr(0, 1) == "$") {
|
||||||
|
ind = line.find(" ");
|
||||||
|
line = var[line.substr(1, ind - 1)];
|
||||||
|
} else line = line.substr(0, 2);
|
||||||
|
if (lg_kbd.parseSpeed(line, speedValue) == true) {
|
||||||
|
keys.clear();
|
||||||
|
colors.red = 0xff;
|
||||||
|
colors.green = 0xff;
|
||||||
|
colors.blue = 0xff;
|
||||||
|
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||||
|
lg_kbd.commit();
|
||||||
|
lg_kbd.detach();
|
||||||
|
lg_kbd.attach();
|
||||||
|
lg_kbd.setFXCWave(speedValue);
|
||||||
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
|
} else if ((line.substr(0, 1) != "#") && (line.substr(0, 1) != "")) {
|
||||||
|
cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
lg_kbd.detach();
|
lineCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
lg_kbd.detach();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int loadProfile(string profileFile) {
|
||||||
|
ifstream file;
|
||||||
|
file.open(profileFile);
|
||||||
|
if (file.is_open()) {
|
||||||
|
int retval = parseProfile(file);
|
||||||
file.close();
|
file.close();
|
||||||
|
return retval;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pipeProfile() {
|
||||||
|
if (isatty(fileno(stdin))) return 1;
|
||||||
|
return parseProfile(cin);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
string str = argv[0];
|
string str = argv[0];
|
||||||
size_t split = str.find_last_of("/\\");
|
size_t split = str.find_last_of("/\\");
|
||||||
@ -530,6 +540,7 @@ int main(int argc, char *argv[]) {
|
|||||||
else if (argCmd == "-kn" && argc == 4) return setKey(argv[2], argv[3], false);
|
else if (argCmd == "-kn" && argc == 4) return setKey(argv[2], argv[3], false);
|
||||||
else if (argCmd == "-c" && argc == 2) return commit();
|
else if (argCmd == "-c" && argc == 2) return commit();
|
||||||
else if (argCmd == "-p" && argc == 3) return loadProfile(argv[2]);
|
else if (argCmd == "-p" && argc == 3) return loadProfile(argv[2]);
|
||||||
|
else if (argCmd == "-pp" && argc == 2) return pipeProfile();
|
||||||
else if (argCmd == "-fx-color" && argc == 3) return setFXColor(argv[2]);
|
else if (argCmd == "-fx-color" && argc == 3) return setFXColor(argv[2]);
|
||||||
else if (argCmd == "-fx-breathing" && argc == 4) return setFXBreathing(argv[2], argv[3]);
|
else if (argCmd == "-fx-breathing" && argc == 4) return setFXBreathing(argv[2], argv[3]);
|
||||||
else if (argCmd == "-fx-cycle" && argc == 3) return setFXColorCycle(argv[2]);
|
else if (argCmd == "-fx-cycle" && argc == 3) return setFXColorCycle(argv[2]);
|
||||||
|
Loading…
Reference in New Issue
Block a user