1
0
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:
MatMoul 2017-01-06 06:08:09 +01:00
parent 338876a006
commit 3596a85315

View File

@ -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,12 +328,7 @@ int setFXCWave(string speed) {
return 1; return 1;
} }
int loadProfile(string profileFile) { int parseProfile(istream &is) {
ifstream file;
file.open(profileFile);
if (file.is_open()) {
string line; string line;
int lineCount = 1; int lineCount = 1;
int ind; int ind;
@ -347,8 +345,8 @@ int loadProfile(string profileFile) {
lg_kbd.attach(); lg_kbd.attach();
while (!file.eof()) { while (!is.eof()) {
getline(file, line); getline(is, line);
if (line.substr(0, 3) == "var") { if (line.substr(0, 3) == "var") {
line = line.substr(4); line = line.substr(4);
@ -506,13 +504,25 @@ int loadProfile(string profileFile) {
lg_kbd.detach(); lg_kbd.detach();
file.close();
return 0; return 0;
}
int loadProfile(string profileFile) {
ifstream file;
file.open(profileFile);
if (file.is_open()) {
int retval = parseProfile(file);
file.close();
return retval;
} }
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]);