From 7847bd16d553e242b2b7a147f5ac1613d657f91a Mon Sep 17 00:00:00 2001 From: MatMoul Date: Sat, 13 May 2017 20:59:41 +0200 Subject: [PATCH] Add daemon feature --- sample_scenarios/scenario0 | 6 + src/helpers/daemonizer.cpp | 92 +++++++++ src/helpers/daemonizer.h | 18 ++ src/helpers/utils.cpp | 255 +++++++++++++++++++++++++ src/helpers/utils.h | 19 ++ src/main.cpp | 287 +++-------------------------- systemd/g810-led-scenarios.service | 11 ++ 7 files changed, 422 insertions(+), 266 deletions(-) create mode 100644 sample_scenarios/scenario0 create mode 100644 src/helpers/daemonizer.cpp create mode 100644 src/helpers/daemonizer.h create mode 100644 systemd/g810-led-scenarios.service diff --git a/sample_scenarios/scenario0 b/sample_scenarios/scenario0 new file mode 100644 index 0000000..3a42512 --- /dev/null +++ b/sample_scenarios/scenario0 @@ -0,0 +1,6 @@ +p sample_profiles/all_blue +w 1000 +p sample_profiles/all_green +w 1000 +p sample_profiles/all_red +w 1000 diff --git a/src/helpers/daemonizer.cpp b/src/helpers/daemonizer.cpp new file mode 100644 index 0000000..5038f31 --- /dev/null +++ b/src/helpers/daemonizer.cpp @@ -0,0 +1,92 @@ +#include "daemonizer.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "../classes/Keyboard.h" + +namespace daemonizer { + + void start(char *arg0, std::string scenarioFile) { + pid_t pid, sid; + pid = fork(); + if (pid < 0) exit(EXIT_FAILURE); + if (pid > 0) exit(EXIT_SUCCESS); + umask(0); + sid = setsid(); + if (sid < 0) exit(EXIT_FAILURE); + + //signal(SIGINT, stop); + std::cout< scenaryFileLastUpdate) { + fileChanged = true; + scenaryFileLastUpdate = file_stat.st_mtime; + } + } + } + + if (fileChanged) { + fileChanged = false; + std::ifstream file; + file.open(scenarioFile); + if (file.is_open()) { + std::string line; + parsedFileString = ""; + while (!file.eof()) { + getline(file, line); + if (line.substr(0, 2) == "p ") { + std::ifstream profileFile; + profileFile.open(line.substr(2)); + if (file.is_open()) { + std::string profileLine; + while (!profileFile.eof()) { + getline(profileFile, profileLine); + if (profileLine != "" && profileLine.substr(0,1) != "#") parsedFileString = parsedFileString + profileLine + "\n"; + } + profileFile.close(); + } + } else { + if (line != "" && line.substr(0,1) != "#") parsedFileString = parsedFileString + line + "\n"; + } + } + file.close(); + } + } + + std::istringstream parsedFile(parsedFileString); + utils::parseProfile(kbd, parsedFile); + + } +} + diff --git a/src/helpers/daemonizer.h b/src/helpers/daemonizer.h new file mode 100644 index 0000000..8078a1f --- /dev/null +++ b/src/helpers/daemonizer.h @@ -0,0 +1,18 @@ +#ifndef DAEMONIZER_HELPER +#define DAEMONIZER_HELPER + +#include + +#include "../classes/Keyboard.h" + +namespace daemonizer { + + void start(char *arg0, std::string scenarioFile); + //void stop(); + //void stop(int signum); + + void process(LedKeyboard &kbd, std::string scenarioFile); + +} + +#endif diff --git a/src/helpers/utils.cpp b/src/helpers/utils.cpp index 5398838..9c868c5 100644 --- a/src/helpers/utils.cpp +++ b/src/helpers/utils.cpp @@ -2,6 +2,11 @@ #include #include +#include +#include +#include +#include +#include #include "../classes/Keyboard.h" @@ -225,4 +230,254 @@ namespace utils { return true; } + bool parseUSeconds(std::string val, useconds_t &useconds) { + useconds = std::stoul(val); + return true; + } + + + int commit(LedKeyboard &kbd) { + if (! kbd.open()) return 1; + if (kbd.commit()) return 0; + return 1; + } + + void printDeviceInfo(LedKeyboard::DeviceInfo device) { + std::cout<<"Device: "< deviceList = kbd.listKeyboards(); + if (deviceList.empty()) { + std::cout<<"Matching or compatible device not found !"<::iterator iterator; + for (iterator = deviceList.begin(); iterator != deviceList.end(); iterator++) { + LedKeyboard::DeviceInfo device = *iterator; + printDeviceInfo(device); + } + + return 0; + } + + int setAllKeys(LedKeyboard &kbd, std::string arg2, bool commit) { + LedKeyboard::Color color; + if (! utils::parseColor(arg2, color)) return 1; + if (! kbd.open()) return 1; + if(! kbd.setAllKeys(color)) return 1; + if (commit) if(! kbd.commit()) return 1; + return 0; + } + + int setGroupKeys(LedKeyboard &kbd, std::string arg2, std::string arg3, bool commit) { + LedKeyboard::KeyGroup keyGroup; + LedKeyboard::Color color; + if (! utils::parseKeyGroup(arg2, keyGroup)) return 1; + if (! utils::parseColor(arg3, color)) return 1; + if (! kbd.open()) return 1; + if (! kbd.setGroupKeys(keyGroup, color)) return 1; + if (commit) if(! kbd.commit()) return 1; + return 0; + } + + int setKey(LedKeyboard &kbd, std::string arg2, std::string arg3, bool commit) { + LedKeyboard::Key key; + LedKeyboard::Color color; + if (! utils::parseKey(arg2, key)) return 1; + if (! utils::parseColor(arg3, color)) return 1; + LedKeyboard::KeyValue keyValue = { key, color }; + if (! kbd.open()) return 1; + if (! kbd.setKey(keyValue)) return 1; + if (commit) if(! kbd.commit()) return 1; + return 0; + } + + int setMRKey(LedKeyboard &kbd, std::string arg2) { + uint8_t value; + if (! utils::parseUInt8(arg2, value)) return 1; + if (! kbd.open()) return 1; + if (! kbd.setMRKey(value)) return 1; + return 0; + } + + int setMNKey(LedKeyboard &kbd, std::string arg2) { + uint8_t value; + if (! utils::parseUInt8(arg2, value)) return 1; + if (! kbd.open()) return 1; + if (! kbd.setMNKey(value)) return 1; + return 0; + } + + int setGKeysMode(LedKeyboard &kbd, std::string arg2) { + uint8_t value; + if (! utils::parseUInt8(arg2, value)) return 1; + if (! kbd.open()) return 1; + if (! kbd.setGKeysMode(value)) return 1; + return 0; + } + + int setRegion(LedKeyboard &kbd, std::string arg2, std::string arg3) { + uint8_t region = 0; + LedKeyboard::Color color; + if (! utils::parseColor(arg3, color)) return 1; + if (! utils::parseUInt8(arg2, region)) return 1; + if (kbd.setRegion(region, color)) return 0; + return 1; + } + + int setFX(LedKeyboard &kbd, std::string arg2, std::string arg3, std::string arg4, std::string arg5) { + LedKeyboard::NativeEffect effect; + LedKeyboard::NativeEffectPart effectPart; + uint8_t speed = 0; + LedKeyboard::Color color; + if (! utils::parseNativeEffect(arg2, effect)) return 1; + if (! utils::parseNativeEffectPart(arg3, effectPart)) return 1; + + switch (effect) { + case LedKeyboard::NativeEffect::color: + if (! utils::parseColor(arg4, color)) return 1; + break; + case LedKeyboard::NativeEffect::breathing: + if (! utils::parseColor(arg4, color)) return 1; + if (arg5 == "") return 1; + if (! utils::parseSpeed(arg5, speed)) return 1; + break; + case LedKeyboard::NativeEffect::cycle: + case LedKeyboard::NativeEffect::hwave: + case LedKeyboard::NativeEffect::vwave: + case LedKeyboard::NativeEffect::cwave: + if (! utils::parseSpeed(arg4, speed)) return 1; + break; + } + + if (! kbd.open()) return 1; + + int retval = 0; + + switch (effectPart) { + case LedKeyboard::NativeEffectPart::all: + switch (effect) { + case LedKeyboard::NativeEffect::color: + if (! kbd.setGroupKeys(LedKeyboard::KeyGroup::indicators, color)) retval = 1; + if (! kbd.commit()) retval = 1; + break; + case LedKeyboard::NativeEffect::breathing: + if (! kbd.setGroupKeys(LedKeyboard::KeyGroup::indicators, color)) retval = 1; + if (! kbd.commit()) retval = 1; + break; + case LedKeyboard::NativeEffect::cycle: + case LedKeyboard::NativeEffect::hwave: + case LedKeyboard::NativeEffect::vwave: + case LedKeyboard::NativeEffect::cwave: + if (! kbd.setGroupKeys( + LedKeyboard::KeyGroup::indicators, + LedKeyboard::Color({0xff, 0xff, 0xff})) + ) retval = 1; + if (! kbd.commit()) retval = 1; + break; + } + if (! kbd.setNativeEffect(effect, LedKeyboard::NativeEffectPart::keys, speed, color)) retval = 1; + if (! kbd.setNativeEffect(effect, LedKeyboard::NativeEffectPart::logo, speed, color)) retval = 1; + break; + default: + if (! kbd.setNativeEffect(effect, effectPart, speed, color)) retval = 1; + break; + } + + return retval; + } + + + int setStartupMode(LedKeyboard &kbd, std::string arg2) { + LedKeyboard::StartupMode startupMode; + if (! utils::parseStartupMode(arg2, startupMode)) return 1; + if (! kbd.open()) return 1; + if (kbd.setStartupMode(startupMode)) return 0; + return 1; + } + + + int parseProfile(LedKeyboard &kbd, std::istream &stream) { + std::string line; + std::map vars; + LedKeyboard::KeyValueArray keys = {}; + int retval = 0; + while (!stream.eof()) { + getline(stream, line); + if (line.size() > 0 && line.substr(0, 1) != "#") { + std::vector args = {}; + while (line.size() > 0) { + uint32_t ind = line.find(" "); + std::string argValue = line.substr(0, ind); + if (argValue.substr(0, 1) == "$") argValue = vars[argValue.substr(1)]; + args.push_back(argValue); + if (line.substr(0, ind) == line) line.clear(); + else line = line.substr(ind + 1); + } + if (args[0] == "var" && args.size() > 2) { + vars[args[1]] = args[2]; + } else if (args[0] == "c") { + if (kbd.open()) { + if (keys.size() > 0) { + if (! kbd.setKeys(keys)) retval = 1; + keys.clear(); + } + if(! kbd.commit()) retval = 1; + } else retval = 1; + } else if (args[0] == "w" && args.size() > 1) { + useconds_t sleepTime = 0; + utils::parseUSeconds(args[1], sleepTime); + sleepTime = sleepTime * 1000; + usleep(sleepTime); + } else if (args[0] == "a" && args.size() > 1) { + if (setAllKeys(kbd, args[1], false) == 1) retval = 1; + } else if (args[0] == "g" && args.size() > 2) { + if (setGroupKeys(kbd, args[1], args[2], false) == 1) retval = 1; + } else if (args[0] == "k" && args.size() > 2) { + LedKeyboard::Key key; + LedKeyboard::Color color; + if (utils::parseKey(args[1], key)) + if (utils::parseColor(args[2], color)) + keys.push_back({ key, color }); + } else if (args[0] == "r" && args.size() > 2) { + if (setRegion(kbd, args[1], args[2]) == 1) retval = 1; + } else if (args[0] == "mr" && args.size() > 1) { + if (setMRKey(kbd, args[1]) == 1) retval = 1; + } else if (args[0] == "mn" && args.size() > 1) { + if (setMNKey(kbd, args[1]) == 1) retval = 1; + } else if (args[0] == "gkm" && args.size() > 1) { + if (setGKeysMode(kbd, args[1]) == 1) retval = 1; + } else if (args[0] == "fx" && args.size() > 4) { + if (setFX(kbd, args[1], args[2], args[3], args[4]) == 1) retval = 1; + } else if (args[0] == "fx" && args.size() > 3) { + if (setFX(kbd, args[1], args[2], args[3]) == 1) retval = 1; + } + } + } + return retval; + } + + int loadProfile(LedKeyboard &kbd, char *arg2) { + std::ifstream file; + file.open(arg2); + if (file.is_open()) { + int retval = 0; + retval = parseProfile(kbd, file); + file.close(); + return retval; + } + return 1; + } + + int pipeProfile(LedKeyboard &kbd) { + if (isatty(fileno(stdin))) return 1; + return parseProfile(kbd, std::cin); + } + + } diff --git a/src/helpers/utils.h b/src/helpers/utils.h index 92de26b..531daf3 100644 --- a/src/helpers/utils.h +++ b/src/helpers/utils.h @@ -2,6 +2,8 @@ #define UTILS_HELPER #include +#include + #include "../classes/Keyboard.h" namespace utils { @@ -17,6 +19,23 @@ namespace utils { bool parseSpeed(std::string val, uint8_t &speed); bool parseUInt8(std::string val, uint8_t &uint8); bool parseUInt16(std::string val, uint16_t &uint16); + bool parseUSeconds(std::string val, useconds_t &useconds); + + int commit(LedKeyboard &kbd); + void printDeviceInfo(LedKeyboard::DeviceInfo device); + int listKeyboards(LedKeyboard &kbd); + int setAllKeys(LedKeyboard &kbd, std::string arg2, bool commit = true); + int setGroupKeys(LedKeyboard &kbd, std::string arg2, std::string arg3, bool commit = true); + int setKey(LedKeyboard &kbd, std::string arg2, std::string arg3, bool commit = true); + int setMRKey(LedKeyboard &kbd, std::string arg2); + int setMNKey(LedKeyboard &kbd, std::string arg2); + int setGKeysMode(LedKeyboard &kbd, std::string arg2); + int setRegion(LedKeyboard &kbd, std::string arg2, std::string arg3); + int setFX(LedKeyboard &kbd, std::string arg2, std::string arg3, std::string arg4, std::string arg5 = ""); + int setStartupMode(LedKeyboard &kbd, std::string arg2); + int parseProfile(LedKeyboard &kbd, std::istream &stream); + int loadProfile(LedKeyboard &kbd, char *arg2); + int pipeProfile(LedKeyboard &kbd); } diff --git a/src/main.cpp b/src/main.cpp index 06c76db..eab09e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,254 +1,8 @@ -#include -#include -#include -#include -#include - #include "helpers/help.h" #include "helpers/utils.h" +#include "helpers/daemonizer.h" #include "classes/Keyboard.h" - -int commit(LedKeyboard &kbd) { - if (! kbd.open()) return 1; - if (kbd.commit()) return 0; - return 1; -} - -void printDeviceInfo(LedKeyboard::DeviceInfo device) { - std::cout<<"Device: "< deviceList = kbd.listKeyboards(); - if (deviceList.empty()) { - std::cout<<"Matching or compatible device not found !"<::iterator iterator; - for (iterator = deviceList.begin(); iterator != deviceList.end(); iterator++) { - LedKeyboard::DeviceInfo device = *iterator; - printDeviceInfo(device); - } - - return 0; -} - -int setAllKeys(LedKeyboard &kbd, std::string arg2, bool commit = true) { - LedKeyboard::Color color; - if (! utils::parseColor(arg2, color)) return 1; - if (! kbd.open()) return 1; - if(! kbd.setAllKeys(color)) return 1; - if (commit) if(! kbd.commit()) return 1; - return 0; -} - -int setGroupKeys(LedKeyboard &kbd, std::string arg2, std::string arg3, bool commit = true) { - LedKeyboard::KeyGroup keyGroup; - LedKeyboard::Color color; - if (! utils::parseKeyGroup(arg2, keyGroup)) return 1; - if (! utils::parseColor(arg3, color)) return 1; - if (! kbd.open()) return 1; - if (! kbd.setGroupKeys(keyGroup, color)) return 1; - if (commit) if(! kbd.commit()) return 1; - return 0; -} - -int setKey(LedKeyboard &kbd, std::string arg2, std::string arg3, bool commit = true) { - LedKeyboard::Key key; - LedKeyboard::Color color; - if (! utils::parseKey(arg2, key)) return 1; - if (! utils::parseColor(arg3, color)) return 1; - LedKeyboard::KeyValue keyValue = { key, color }; - if (! kbd.open()) return 1; - if (! kbd.setKey(keyValue)) return 1; - if (commit) if(! kbd.commit()) return 1; - return 0; -} - -int setMRKey(LedKeyboard &kbd, std::string arg2) { - uint8_t value; - if (! utils::parseUInt8(arg2, value)) return 1; - if (! kbd.open()) return 1; - if (! kbd.setMRKey(value)) return 1; - return 0; -} - -int setMNKey(LedKeyboard &kbd, std::string arg2) { - uint8_t value; - if (! utils::parseUInt8(arg2, value)) return 1; - if (! kbd.open()) return 1; - if (! kbd.setMNKey(value)) return 1; - return 0; -} - -int setGKeysMode(LedKeyboard &kbd, std::string arg2) { - uint8_t value; - if (! utils::parseUInt8(arg2, value)) return 1; - if (! kbd.open()) return 1; - if (! kbd.setGKeysMode(value)) return 1; - return 0; -} - -int setRegion(LedKeyboard &kbd, std::string arg2, std::string arg3) { - uint8_t region = 0; - LedKeyboard::Color color; - if (! utils::parseColor(arg3, color)) return 1; - if (! utils::parseUInt8(arg2, region)) return 1; - if (kbd.setRegion(region, color)) return 0; - return 1; -} - -int setFX(LedKeyboard &kbd, std::string arg2, std::string arg3, std::string arg4, std::string arg5 = "") { - LedKeyboard::NativeEffect effect; - LedKeyboard::NativeEffectPart effectPart; - uint8_t speed = 0; - LedKeyboard::Color color; - if (! utils::parseNativeEffect(arg2, effect)) return 1; - if (! utils::parseNativeEffectPart(arg3, effectPart)) return 1; - - switch (effect) { - case LedKeyboard::NativeEffect::color: - if (! utils::parseColor(arg4, color)) return 1; - break; - case LedKeyboard::NativeEffect::breathing: - if (! utils::parseColor(arg4, color)) return 1; - if (arg5 == "") return 1; - if (! utils::parseSpeed(arg5, speed)) return 1; - break; - case LedKeyboard::NativeEffect::cycle: - case LedKeyboard::NativeEffect::hwave: - case LedKeyboard::NativeEffect::vwave: - case LedKeyboard::NativeEffect::cwave: - if (! utils::parseSpeed(arg4, speed)) return 1; - break; - } - - if (! kbd.open()) return 1; - - int retval = 0; - - switch (effectPart) { - case LedKeyboard::NativeEffectPart::all: - switch (effect) { - case LedKeyboard::NativeEffect::color: - if (! kbd.setGroupKeys(LedKeyboard::KeyGroup::indicators, color)) retval = 1; - if (! kbd.commit()) retval = 1; - break; - case LedKeyboard::NativeEffect::breathing: - if (! kbd.setGroupKeys(LedKeyboard::KeyGroup::indicators, color)) retval = 1; - if (! kbd.commit()) retval = 1; - break; - case LedKeyboard::NativeEffect::cycle: - case LedKeyboard::NativeEffect::hwave: - case LedKeyboard::NativeEffect::vwave: - case LedKeyboard::NativeEffect::cwave: - if (! kbd.setGroupKeys( - LedKeyboard::KeyGroup::indicators, - LedKeyboard::Color({0xff, 0xff, 0xff})) - ) retval = 1; - if (! kbd.commit()) retval = 1; - break; - } - if (! kbd.setNativeEffect(effect, LedKeyboard::NativeEffectPart::keys, speed, color)) retval = 1; - if (! kbd.setNativeEffect(effect, LedKeyboard::NativeEffectPart::logo, speed, color)) retval = 1; - break; - default: - if (! kbd.setNativeEffect(effect, effectPart, speed, color)) retval = 1; - break; - } - - return retval; -} - - -int setStartupMode(LedKeyboard &kbd, std::string arg2) { - LedKeyboard::StartupMode startupMode; - if (! utils::parseStartupMode(arg2, startupMode)) return 1; - if (! kbd.open()) return 1; - if (kbd.setStartupMode(startupMode)) return 0; - return 1; -} - - -int parseProfile(LedKeyboard &kbd, std::istream &stream) { - std::string line; - std::map vars; - LedKeyboard::KeyValueArray keys = {}; - int retval = 0; - while (!stream.eof()) { - getline(stream, line); - if (line.size() > 0 && line.substr(0, 1) != "#") { - std::vector args = {}; - while (line.size() > 0) { - uint32_t ind = line.find(" "); - std::string argValue = line.substr(0, ind); - if (argValue.substr(0, 1) == "$") argValue = vars[argValue.substr(1)]; - args.push_back(argValue); - if (line.substr(0, ind) == line) line.clear(); - else line = line.substr(ind + 1); - } - if (args[0] == "var" && args.size() > 2) { - vars[args[1]] = args[2]; - } else if (args[0] == "c") { - if (kbd.open()) { - if (keys.size() > 0) { - if (! kbd.setKeys(keys)) retval = 1; - keys.clear(); - } - if(! kbd.commit()) retval = 1; - } else retval = 1; - } else if (args[0] == "a" && args.size() > 1) { - if (setAllKeys(kbd, args[1], false) == 1) retval = 1; - } else if (args[0] == "g" && args.size() > 2) { - if (setGroupKeys(kbd, args[1], args[2], false) == 1) retval = 1; - } else if (args[0] == "k" && args.size() > 2) { - LedKeyboard::Key key; - LedKeyboard::Color color; - if (utils::parseKey(args[1], key)) - if (utils::parseColor(args[2], color)) - keys.push_back({ key, color }); - } else if (args[0] == "r" && args.size() > 2) { - if (setRegion(kbd, args[1], args[2]) == 1) retval = 1; - } else if (args[0] == "mr" && args.size() > 1) { - if (setMRKey(kbd, args[1]) == 1) retval = 1; - } else if (args[0] == "mn" && args.size() > 1) { - if (setMNKey(kbd, args[1]) == 1) retval = 1; - } else if (args[0] == "gkm" && args.size() > 1) { - if (setGKeysMode(kbd, args[1]) == 1) retval = 1; - } else if (args[0] == "fx" && args.size() > 4) { - if (setFX(kbd, args[1], args[2], args[3], args[4]) == 1) retval = 1; - } else if (args[0] == "fx" && args.size() > 3) { - if (setFX(kbd, args[1], args[2], args[3]) == 1) retval = 1; - } - } - } - return retval; -} - -int loadProfile(LedKeyboard &kbd, char *arg2) { - std::ifstream file; - file.open(arg2); - if (file.is_open()) { - int retval = 0; - retval = parseProfile(kbd, file); - file.close(); - return retval; - } - return 1; -} - -int pipeProfile(LedKeyboard &kbd) { - if (isatty(fileno(stdin))) return 1; - return parseProfile(kbd, std::cin); -} - - - int main(int argc, char **argv) { if (argc < 2) { help::usage(argv[0]); @@ -298,13 +52,14 @@ int main(int argc, char **argv) { continue; } - + //Commands that do not need to initialize a specific device if (arg == "--help" || arg == "-h") {help::usage(argv[0]); return 0;} - else if (arg == "--list-keyboards") return listKeyboards(kbd); + else if (arg == "--list-keyboards") return utils::listKeyboards(kbd); else if (arg == "--help-keys") {help::keys(argv[0]); return 0;} else if (arg == "--help-effects") {help::effects(argv[0]); return 0;} else if (arg == "--help-samples") {help::samples(argv[0]); return 0;} + else if (argc > (argIndex + 1) && arg == "--daemon" ) {daemonizer::start(argv[0], argv[argIndex + 1]); return 0;} //Initialize the device for use if (!kbd.open(vendorID, productID, serial)) { @@ -313,26 +68,26 @@ int main(int argc, char **argv) { } // Command arguments, these will cause parsing to ignore anything beyond the command and its arguments - if (arg == "-c") return commit(kbd); - else if (arg == "--print-device") {printDeviceInfo(kbd.getCurrentDevice()); return 0;} - else if (argc > (argIndex + 1) && arg == "-a") return setAllKeys(kbd, argv[argIndex + 1]); - else if (argc > (argIndex + 2) && arg == "-g") return setGroupKeys(kbd, argv[argIndex + 1], argv[argIndex + 2]); - else if (argc > (argIndex + 2) && arg == "-k") return setKey(kbd, argv[argIndex + 1], argv[argIndex + 2]); - else if (argc > (argIndex + 1) && arg == "-mr") return setMRKey(kbd, argv[argIndex + 1]); - else if (argc > (argIndex + 1) && arg == "-mn") return setMNKey(kbd, argv[argIndex + 1]); - else if (argc > (argIndex + 1) && arg == "-an") return setAllKeys(kbd, argv[argIndex + 1], false); + if (arg == "-c") return utils::commit(kbd); + else if (arg == "--print-device") {utils::printDeviceInfo(kbd.getCurrentDevice()); return 0;} + else if (argc > (argIndex + 1) && arg == "-a") return utils::setAllKeys(kbd, argv[argIndex + 1]); + else if (argc > (argIndex + 2) && arg == "-g") return utils::setGroupKeys(kbd, argv[argIndex + 1], argv[argIndex + 2]); + else if (argc > (argIndex + 2) && arg == "-k") return utils::setKey(kbd, argv[argIndex + 1], argv[argIndex + 2]); + else if (argc > (argIndex + 1) && arg == "-mr") return utils::setMRKey(kbd, argv[argIndex + 1]); + else if (argc > (argIndex + 1) && arg == "-mn") return utils::setMNKey(kbd, argv[argIndex + 1]); + else if (argc > (argIndex + 1) && arg == "-an") return utils::setAllKeys(kbd, argv[argIndex + 1], false); else if (argc > (argIndex + 2) && arg == "-gn") - return setGroupKeys(kbd, argv[argIndex + 1], argv[argIndex + 2], false); - else if (argc > (argIndex + 2) && arg == "-kn") return setKey(kbd, argv[argIndex + 1], argv[argIndex + 2], false); - else if (argc > (argIndex + 2) && arg == "-r") return setRegion(kbd, argv[argIndex + 1], argv[argIndex + 2]); - else if (argc > (argIndex + 1) && arg == "-gkm") return setGKeysMode(kbd, argv[argIndex + 1]); - else if (argc > (argIndex + 1) && arg == "-p") return loadProfile(kbd, argv[argIndex + 1]); - else if (arg == "-pp") return pipeProfile(kbd); + return utils::setGroupKeys(kbd, argv[argIndex + 1], argv[argIndex + 2], false); + else if (argc > (argIndex + 2) && arg == "-kn") return utils::setKey(kbd, argv[argIndex + 1], argv[argIndex + 2], false); + else if (argc > (argIndex + 2) && arg == "-r") return utils::setRegion(kbd, argv[argIndex + 1], argv[argIndex + 2]); + else if (argc > (argIndex + 1) && arg == "-gkm") return utils::setGKeysMode(kbd, argv[argIndex + 1]); + else if (argc > (argIndex + 1) && arg == "-p") return utils::loadProfile(kbd, argv[argIndex + 1]); + else if (arg == "-pp") return utils::pipeProfile(kbd); else if (argc > (argIndex + 4) && arg == "-fx") - return setFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3], argv[argIndex + 4]); + return utils::setFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3], argv[argIndex + 4]); else if (argc > (argIndex + 3) && arg == "-fx") - return setFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3]); - else if (argc > (argIndex + 1) && arg == "--startup-mode") return setStartupMode(kbd, argv[argIndex + 1]); + return utils::setFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3]); + else if (argc > (argIndex + 1) && arg == "--startup-mode") return utils::setStartupMode(kbd, argv[argIndex + 1]); else { help::usage(argv[0]); return 1; } } diff --git a/systemd/g810-led-scenarios.service b/systemd/g810-led-scenarios.service new file mode 100644 index 0000000..d639d04 --- /dev/null +++ b/systemd/g810-led-scenarios.service @@ -0,0 +1,11 @@ +[Unit] +Description=Logitech G810 Led Scenarios + +[Service] +#ExecStart=/usr/bin/g810-led --daemon /etc/g810-led/scenario +#ExecSop=kill -2 pid +#Type=oneshot +#RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target