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
33
src/main.cpp
33
src/main.cpp
@ -1,7 +1,9 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <istream>
|
||||
#include "classes/Keyboard.h"
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -29,7 +31,8 @@ void usage() {
|
||||
cout<<" -fx-vwave speed :\t\tSet vertical color wave effect\n";
|
||||
cout<<" -fx-cwave speed :\t\tSet center color wave effect\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<<" -h | --help :\t\t\tthis help message\n";
|
||||
cout<<" -lk | --list-keys :\t\tList keys in groups\n";
|
||||
@ -325,12 +328,7 @@ int setFXCWave(string speed) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int loadProfile(string profileFile) {
|
||||
ifstream file;
|
||||
|
||||
file.open(profileFile);
|
||||
if (file.is_open()) {
|
||||
|
||||
int parseProfile(istream &is) {
|
||||
string line;
|
||||
int lineCount = 1;
|
||||
int ind;
|
||||
@ -347,8 +345,8 @@ int loadProfile(string profileFile) {
|
||||
|
||||
lg_kbd.attach();
|
||||
|
||||
while (!file.eof()) {
|
||||
getline(file, line);
|
||||
while (!is.eof()) {
|
||||
getline(is, line);
|
||||
|
||||
if (line.substr(0, 3) == "var") {
|
||||
line = line.substr(4);
|
||||
@ -506,13 +504,25 @@ int loadProfile(string profileFile) {
|
||||
|
||||
lg_kbd.detach();
|
||||
|
||||
file.close();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int pipeProfile() {
|
||||
if (isatty(fileno(stdin))) return 1;
|
||||
return parseProfile(cin);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
string str = argv[0];
|
||||
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 == "-c" && argc == 2) return commit();
|
||||
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-breathing" && argc == 4) return setFXBreathing(argv[2], argv[3]);
|
||||
else if (argCmd == "-fx-cycle" && argc == 3) return setFXColorCycle(argv[2]);
|
||||
|
Loading…
Reference in New Issue
Block a user