From 3596a85315e61d162a9c583dd053eb0468968b4d Mon Sep 17 00:00:00 2001 From: MatMoul Date: Fri, 6 Jan 2017 06:08:09 +0100 Subject: [PATCH] Add profile pipe support --- src/main.cpp | 349 ++++++++++++++++++++++++++------------------------- 1 file changed, 180 insertions(+), 169 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 241659e..f184cc6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ #include #include #include +#include #include "classes/Keyboard.h" +#include 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,194 +328,201 @@ int setFXCWave(string speed) { return 1; } -int loadProfile(string profileFile) { - ifstream file; +int parseProfile(istream &is) { + string line; + int lineCount = 1; + int ind; - file.open(profileFile); - if (file.is_open()) { + Keyboard lg_kbd; + Keyboard::KeyGroup keyGroup; + Keyboard::KeyAddress keyAddress; + Keyboard::KeyValue keyValue; + Keyboard::KeyColors colors; + uint8_t speedValue; + + map var; + vector keys; + + lg_kbd.attach(); + + while (!is.eof()) { + getline(is, line); - string line; - int lineCount = 1; - int ind; - - Keyboard lg_kbd; - Keyboard::KeyGroup keyGroup; - Keyboard::KeyAddress keyAddress; - Keyboard::KeyValue keyValue; - Keyboard::KeyColors colors; - uint8_t speedValue; - - map var; - vector keys; - - lg_kbd.attach(); - - while (!file.eof()) { - getline(file, line); - - if (line.substr(0, 3) == "var") { - line = line.substr(4); + if (line.substr(0, 3) == "var") { + line = line.substr(4); + ind = line.find(" "); + var[line.substr(0, ind)] = line.substr(ind + 1, 6); + } else if (line.substr(0, 1) == "a") { + line = line.substr(2); + if (line.substr(0, 1) == "$") { ind = line.find(" "); - var[line.substr(0, ind)] = line.substr(ind + 1, 6); - } else if (line.substr(0, 1) == "a") { - line = line.substr(2); - 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 "<