mirror of
https://github.com/MatMoul/g810-led.git
synced 2025-12-21 22:52:37 +00:00
cmake support and reordering of files
This commit is contained in:
20
app/CMakeLists.txt
Normal file
20
app/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
# utils.h
|
||||
utils.cpp
|
||||
# help.h
|
||||
help.cpp
|
||||
)
|
||||
|
||||
if(CMAKE_EXTRA_GENERATOR OR MSVC_IDE)
|
||||
message(STATUS "Adding header files to project")
|
||||
file(GLOB_RECURSE HEADERS "${INCLUDE_DIR}/*.h")
|
||||
if(MSVC_IDE)
|
||||
source_group("Header Files" FILES ${HEADERS})
|
||||
endif()
|
||||
list(APPEND SOURCES ${HEADERS})
|
||||
endif()
|
||||
|
||||
add_executable(g810-led ${SOURCES})
|
||||
|
||||
target_link_libraries(g810-led PUBLIC libledkeyboard)
|
||||
330
app/help.cpp
Normal file
330
app/help.cpp
Normal file
@@ -0,0 +1,330 @@
|
||||
#include "help.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace help {
|
||||
|
||||
inline KeyboardFeatures operator|(KeyboardFeatures a, KeyboardFeatures b) {
|
||||
return static_cast<KeyboardFeatures>(static_cast<uint16_t>(a) | static_cast<uint16_t>(b));
|
||||
}
|
||||
|
||||
KeyboardFeatures getKeyboardFeatures(string cmdName) {
|
||||
if(cmdName == "g213-led") return KeyboardFeatures::g213;
|
||||
else if(cmdName == "g410-led") return KeyboardFeatures::g410;
|
||||
else if(cmdName == "g413-led") return KeyboardFeatures::g413;
|
||||
else if(cmdName == "g610-led") return KeyboardFeatures::g610;
|
||||
else if(cmdName == "g810-led") return KeyboardFeatures::g810;
|
||||
else if(cmdName == "g910-led") return KeyboardFeatures::g910;
|
||||
else if(cmdName == "gpro-led") return KeyboardFeatures::gpro;
|
||||
return KeyboardFeatures::all;
|
||||
}
|
||||
|
||||
|
||||
void usage(char *arg0) {
|
||||
string cmdName = utils::getCmdName(arg0);
|
||||
KeyboardFeatures features = getKeyboardFeatures(cmdName);
|
||||
cout<<cmdName<<endl;
|
||||
cout<<"--------"<<endl;
|
||||
cout<<"Version : "<<VERSION<<endl;
|
||||
cout<<endl;
|
||||
cout<<"Usage: "<<cmdName<<" [OPTIONS...] [command] (command arguments)"<<endl;
|
||||
cout<<"Commands:"<<endl;
|
||||
if((features | KeyboardFeatures::setall) == features)
|
||||
cout<<" -a {color}\t\t\t\tSet all keys color"<<endl;
|
||||
if((features | KeyboardFeatures::setgroup) == features)
|
||||
cout<<" -g {keygroup} {color}\t\t\tSet key group color"<<endl;
|
||||
if((features | KeyboardFeatures::setkey) == features)
|
||||
cout<<" -k {key} {color}\t\t\tSet key color"<<endl;
|
||||
if((features | KeyboardFeatures::setregion) == features)
|
||||
cout<<" -r {region} {color}\t\t\tSet the color of a region for a region-based keyboard"<<endl;
|
||||
if((features | KeyboardFeatures::gkeys) == features) {
|
||||
cout<<" -mr {value}\t\t\t\tSet MR key (0-1)"<<endl;
|
||||
cout<<" -mn {value}\t\t\t\tSet MN key (0-7) (M1=1, M2=2, M3=4) (M1+M2=3, M1+M3=5, ...)"<<endl;
|
||||
cout<<endl;
|
||||
cout<<" -gkm {value}\t\t\t\tSet GKeys mode (0=Mapped to FKeys, 1=Independent)"<<endl;
|
||||
}
|
||||
cout<<endl;
|
||||
if((features | KeyboardFeatures::commit) == features) {
|
||||
if((features | KeyboardFeatures::setall) == features)
|
||||
cout<<" -an {color}\t\t\t\tSet all keys color without commit"<<endl;
|
||||
if((features | KeyboardFeatures::setgroup) == features)
|
||||
cout<<" -gn {keygroup} {color}\t\tSet key group color without commit"<<endl;
|
||||
if((features | KeyboardFeatures::setkey) == features)
|
||||
cout<<" -kn {key} {color}\t\t\tSet key color without commit"<<endl;
|
||||
cout<<" -c\t\t\t\t\tCommit change"<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
cout<<" -fx ...\t\t\t\tUse --help-effects for more detail"<<endl;
|
||||
cout<<endl;
|
||||
cout<<" < {profile}\t\t\t\tSet a profile from a file (use --help-samples for more detail)"<<endl;
|
||||
cout<<" |\t\t\t\t\tSet a profile from stdin (for scripting) (use --help-samples for more detail)"<<endl;
|
||||
cout<<endl;
|
||||
if((features | KeyboardFeatures::poweronfx) == features) {
|
||||
cout<<" --startup-mode {startup mode}\t\tSet startup mode"<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
cout<<" --list-keyboards \t\t\tList connected keyboards"<<endl;
|
||||
cout<<" --print-device\t\t\tPrint device information for the keyboard"<<endl;
|
||||
cout<<endl;
|
||||
cout<<" --help\t\t\t\tThis help"<<endl;
|
||||
cout<<" --help-keys\t\t\t\tHelp for keys in groups"<<endl;
|
||||
cout<<" --help-effects\t\t\tHelp for native effects"<<endl;
|
||||
cout<<" --help-samples\t\t\tUsage samples"<<endl;
|
||||
cout<<endl;
|
||||
cout<<"Options:"<<endl;
|
||||
cout<<" -dv\t\t\t\t\tDevice vendor ID, such as 046d for Logitech. Can be omitted to match any vendor ID"<<endl;
|
||||
cout<<" -dp\t\t\t\t\tDevice product ID, such as c337 for Logitech G810. Can be omitted to match any product ID"<<endl;
|
||||
cout<<" -ds\t\t\t\t\tDevice serial number, Can be omitted to match the first device found"<<endl;
|
||||
cout<<" -tuk\t\t\t\t\tTest unsuported keyboard with one of supported protocol (1-3) -dv and -dp are required"<<endl;
|
||||
cout<<endl;
|
||||
cout<<"Values:"<<endl;
|
||||
if((features | KeyboardFeatures::rgb) == features)
|
||||
cout<<" color formats :\t\t\tRRGGBB (hex value for red, green and blue)"<<endl;
|
||||
if((features | KeyboardFeatures::intensity) == features)
|
||||
cout<<" color formats :\t\t\tII (hex value for intensity)"<<endl;
|
||||
if((features | KeyboardFeatures::setregion) == features)
|
||||
cout<<" region formats :\t\t\tRN (integer value for region, 1 to 5)"<<endl;
|
||||
cout<<" speed formats :\t\t\tSS (hex value for speed 01 to ff)"<<endl;
|
||||
cout<<endl;
|
||||
if((features | KeyboardFeatures::setkey) == features)
|
||||
cout<<" key values :\t\t\t\tabc... 123... and other (use --help-keys for more detail)"<<endl;
|
||||
if((features | KeyboardFeatures::setgroup) == features)
|
||||
cout<<" group values :\t\t\tlogo, indicators, fkeys, ... (use --help-keys for more detail)"<<endl;
|
||||
cout<<" startup mode :\t\t\twave, color"<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
// Need to check rgb and intesity
|
||||
void keys(char *arg0) {
|
||||
string cmdName = utils::getCmdName(arg0);
|
||||
KeyboardFeatures features = getKeyboardFeatures(cmdName);
|
||||
|
||||
cout<<cmdName<<" Keys"<<endl;
|
||||
cout<<"-------------"<<endl;
|
||||
cout<<endl;
|
||||
cout<<"Group List :"<<endl;
|
||||
|
||||
if((features | KeyboardFeatures::logo1) == features)
|
||||
cout<<" logo"<<endl;
|
||||
if((features | KeyboardFeatures::setindicators) == features)
|
||||
cout<<" indicators"<<endl;
|
||||
if((features | KeyboardFeatures::gkeys) == features)
|
||||
cout<<" gkeys"<<endl;
|
||||
cout<<" fkeys"<<endl;
|
||||
cout<<" modifiers"<<endl;
|
||||
if((features | KeyboardFeatures::multimedia) == features)
|
||||
cout<<" multimedia"<<endl;
|
||||
cout<<" arrows"<<endl;
|
||||
if((features | KeyboardFeatures::numpad) == features)
|
||||
cout<<" numeric"<<endl;
|
||||
cout<<" functions"<<endl;
|
||||
cout<<" keys"<<endl;
|
||||
cout<<endl;
|
||||
cout<<endl;
|
||||
|
||||
if((features | KeyboardFeatures::logo1) == features) {
|
||||
cout<<"Group Logo :"<<endl;
|
||||
cout<<" logo"<<endl;
|
||||
if((features | KeyboardFeatures::logo2) == features)
|
||||
cout<<" logo2"<<endl;
|
||||
cout<<""<<endl;
|
||||
}
|
||||
|
||||
if((features | KeyboardFeatures::setindicators) == features) {
|
||||
cout<<"Group indicators :"<<endl;
|
||||
cout<<" num_indicator, numindicator, num"<<endl;
|
||||
cout<<" caps_indicator, capsindicator, caps"<<endl;
|
||||
cout<<" scroll_indicator, scrollindicator, scroll"<<endl;
|
||||
cout<<" game_mode, gamemode, game"<<endl;
|
||||
cout<<" back_light, backlight, light"<<endl;
|
||||
cout<<""<<endl;
|
||||
}
|
||||
|
||||
if((features | KeyboardFeatures::gkeys) == features) {
|
||||
cout<<"Group gkeys :"<<endl;
|
||||
cout<<" g1 - g9"<<endl;
|
||||
cout<<""<<endl;
|
||||
}
|
||||
|
||||
cout<<"Group fkeys :"<<endl;
|
||||
cout<<" f1 - f12"<<endl;
|
||||
cout<<""<<endl;
|
||||
|
||||
cout<<"Group modifiers :"<<endl;
|
||||
cout<<" shift_left, shiftleft, shiftl"<<endl;
|
||||
cout<<" ctrl_left, ctrlleft, ctrll"<<endl;
|
||||
cout<<" win_left, winleft, win_left"<<endl;
|
||||
cout<<" alt_left, altleft, altl"<<endl;
|
||||
cout<<" alt_right, altright, altr, altgr"<<endl;
|
||||
cout<<" win_right, winright, winr"<<endl;
|
||||
cout<<" menu"<<endl;
|
||||
cout<<" ctrl_right, ctrlright, ctrlr"<<endl;
|
||||
cout<<" shift_right, shiftright, shiftr"<<endl;
|
||||
cout<<""<<endl;
|
||||
|
||||
if((features | KeyboardFeatures::multimedia) == features) {
|
||||
cout<<"Group multimedia :"<<endl;
|
||||
cout<<" mute"<<endl;
|
||||
cout<<" play_pause, playpause, play"<<endl;
|
||||
cout<<" stop"<<endl;
|
||||
cout<<" previous, prev"<<endl;
|
||||
cout<<" next"<<endl;
|
||||
cout<<""<<endl;
|
||||
}
|
||||
|
||||
cout<<"Group arrows :"<<endl;
|
||||
cout<<" arrow_top, arrowtop, top"<<endl;
|
||||
cout<<" arrow_left, arrowleft, left"<<endl;
|
||||
cout<<" arrow_bottom, arrowbottom, bottom"<<endl;
|
||||
cout<<" arrow_right, arrowright, right"<<endl;
|
||||
cout<<""<<endl;
|
||||
|
||||
if((features | KeyboardFeatures::numpad) == features) {
|
||||
cout<<"Group numeric :"<<endl;
|
||||
cout<<" num_lock, numlock"<<endl;
|
||||
cout<<" num_slash, numslash, num/"<<endl;
|
||||
cout<<" num_asterisk, numasterisk, num*"<<endl;
|
||||
cout<<" num_minus, numminus, num-"<<endl;
|
||||
cout<<" num_plus, numplus, num+"<<endl;
|
||||
cout<<" numenter"<<endl;
|
||||
cout<<" num0 - num9"<<endl;
|
||||
cout<<" num_dot, numdot, num."<<endl;
|
||||
cout<<""<<endl;
|
||||
}
|
||||
|
||||
cout<<"Group functions :"<<endl;
|
||||
cout<<" escape, esc"<<endl;
|
||||
cout<<" print_screen, printscreen, printscr"<<endl;
|
||||
cout<<" scroll_lock, scrolllock"<<endl;
|
||||
cout<<" pause_break, pausebreak"<<endl;
|
||||
cout<<" insert, ins"<<endl;
|
||||
cout<<" home"<<endl;
|
||||
cout<<" page_up, pageup"<<endl;
|
||||
cout<<" delete, del"<<endl;
|
||||
cout<<" end"<<endl;
|
||||
cout<<" page_down, pagedown"<<endl;
|
||||
cout<<""<<endl;
|
||||
|
||||
if((features | KeyboardFeatures::setkey) == features) {
|
||||
cout<<"Group keys :"<<endl;
|
||||
cout<<" 0 - 9"<<endl;
|
||||
cout<<" a - z"<<endl;
|
||||
cout<<" tab"<<endl;
|
||||
cout<<" caps_lock, capslock"<<endl;
|
||||
cout<<" space"<<endl;
|
||||
cout<<" backspace, back"<<endl;
|
||||
cout<<" enter"<<endl;
|
||||
cout<<" tilde"<<endl;
|
||||
cout<<" minus"<<endl;
|
||||
cout<<" equal"<<endl;
|
||||
cout<<" open_bracket"<<endl;
|
||||
cout<<" close_bracket"<<endl;
|
||||
cout<<" backslash"<<endl;
|
||||
cout<<" semicolon"<<endl;
|
||||
cout<<" dollar"<<endl;
|
||||
cout<<" quote"<<endl;
|
||||
cout<<" intl_backslash"<<endl;
|
||||
cout<<" comma"<<endl;
|
||||
cout<<" period"<<endl;
|
||||
cout<<" slash"<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
void effects(char *arg0) {
|
||||
string cmdName = utils::getCmdName(arg0);
|
||||
KeyboardFeatures features = getKeyboardFeatures(cmdName);
|
||||
cout<<cmdName<<" Effects"<<endl;
|
||||
cout<<"----------------"<<endl;
|
||||
cout<<endl;
|
||||
cout<<"At this time, FX are only tested on g810 !"<<endl;
|
||||
cout<<endl;
|
||||
cout<<" -fx {effect} {target}"<<endl;
|
||||
cout<<endl;
|
||||
cout<<" -fx color {target} {color}"<<endl;
|
||||
cout<<" -fx breathing {target} {color} {speed}"<<endl;
|
||||
cout<<" -fx cycle {target} {speed}"<<endl;
|
||||
cout<<" -fx hwave {target} {speed}"<<endl;
|
||||
cout<<" -fx vwave {target} {speed}"<<endl;
|
||||
cout<<" -fx cwave {target} {speed}"<<endl;
|
||||
cout<<endl;
|
||||
if((features | KeyboardFeatures::logo1) == features)
|
||||
cout<<"target value :\t\t\t\tall, keys, logo"<<endl;
|
||||
else
|
||||
cout<<"target value :\t\t\t\tall, keys (all is for compatibility with other keyboard models)"<<endl;
|
||||
if((features | KeyboardFeatures::rgb) == features)
|
||||
cout<<"color formats :\t\t\t\tRRGGBB (hex value for red, green and blue)"<<endl;
|
||||
else if((features | KeyboardFeatures::rgb) == features)
|
||||
cout<<"color formats :\t\t\t\tII (hex value for intensity)"<<endl;
|
||||
cout<<"speed formats :\t\t\t\tSS (hex value for speed 01 to ff)"<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
// Need to check rgb and intesity
|
||||
void samples(char *arg0) {
|
||||
string cmdName = utils::getCmdName(arg0);
|
||||
KeyboardFeatures features = getKeyboardFeatures(cmdName);
|
||||
cout<<cmdName<<" Samples"<<endl;
|
||||
cout<<"----------------"<<endl;
|
||||
cout<<endl;
|
||||
cout<<"Samples :"<<endl;
|
||||
cout<<cmdName<<" -p /etc/g810/profile # Load a profile"<<endl;
|
||||
if((features | KeyboardFeatures::setkey) == features)
|
||||
cout<<cmdName<<" -k logo ff0000 # Set color of a key"<<endl;
|
||||
if((features | KeyboardFeatures::setall) == features)
|
||||
cout<<cmdName<<" -a 00ff00 # Set color of all keys"<<endl;
|
||||
if((features | KeyboardFeatures::setgroup) == features)
|
||||
cout<<cmdName<<" -g fkeys ff00ff # Set color of a group of keys"<<endl;
|
||||
if((features | KeyboardFeatures::setregion) == features)
|
||||
cout<<cmdName<<" -r 1 ff0000 # Set region 1 red"<<endl;
|
||||
cout<<cmdName<<" -fx color keys 00ff00 # Set fixed color effect"<<endl;
|
||||
cout<<cmdName<<" -fx breathing logo 00ff00 0a # Set breathing effect"<<endl;
|
||||
cout<<cmdName<<" -fx cycle all 0a # Set color cycle effect"<<endl;
|
||||
cout<<cmdName<<" -fx hwave keys 0a # Set horizontal wave effect"<<endl;
|
||||
cout<<cmdName<<" -fx vwave keys 0a # Set vertical wave effect"<<endl;
|
||||
cout<<cmdName<<" -fx cwave keys 0a # Set center wave effect"<<endl;
|
||||
if((features | KeyboardFeatures::poweronfx) == features)
|
||||
cout<<cmdName<<" --startup-mode color # Set keyboard power on effect"<<endl;
|
||||
cout<<endl;
|
||||
if((features | KeyboardFeatures::commit) == features) {
|
||||
cout<<"Samples with no commit :"<<endl;
|
||||
if((features | KeyboardFeatures::setall) == features)
|
||||
cout<<cmdName<<" -an 000000 # Set color of all key with no action"<<endl;
|
||||
if((features | KeyboardFeatures::setgroup) == features)
|
||||
cout<<cmdName<<" -gn modifiers ff0000 # Set color of a group with no action"<<endl;
|
||||
if((features | KeyboardFeatures::setkey) == features) {
|
||||
cout<<cmdName<<" -kn w ff0000 # Set color of a key with no action"<<endl;
|
||||
cout<<cmdName<<" -kn a ff0000 # Set color of a key with no action"<<endl;
|
||||
cout<<cmdName<<" -kn s ff0000 # Set color of a key with no action"<<endl;
|
||||
cout<<cmdName<<" -kn d ff0000 # Set color of a key with no action"<<endl;
|
||||
}
|
||||
cout<<cmdName<<" -c # Commit all changes"<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
// Need to be merged with Samples
|
||||
if((features | KeyboardFeatures::intensity) == features) {
|
||||
cout<<"Samples with intensity :"<<endl;
|
||||
cout<<cmdName<<" -a 60 # Set intensity of all keys"<<endl;
|
||||
cout<<cmdName<<" -k logo ff # Set intensity of a key"<<endl;
|
||||
cout<<cmdName<<" -g fkeys aa # Set intensity of a group of keys"<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
if((features | KeyboardFeatures::setkey) == features) {
|
||||
cout<<"Samples with pipe (for effects) :"<<endl;
|
||||
cout<<cmdName<<" -pp < profilefile # Load a profile"<<endl;
|
||||
cout<<"echo -e \"k w ff0000\\nk a ff0000\\nk s ff0000\\nk d ff0000\\nc\" | g810-led -pp # Set multiple keys"<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
cout<<"Testing an unsuported keyboard :"<<endl;
|
||||
cout<<"lsusb"<<endl;
|
||||
cout<<"#Sample result of lsusb : ID 046d:c331 Logitech, Inc. (dv=046d and dp=c331)"<<endl;
|
||||
cout<<cmdName<<" -dv 046d -dp c331 -tuk 1 -a 000000"<<endl;
|
||||
cout<<cmdName<<" -dv 046d -dp c331 -tuk 2 -a 000000"<<endl;
|
||||
cout<<cmdName<<" -dv 046d -dp c331 -tuk 3 -a 000000"<<endl;
|
||||
cout<<""<<endl;
|
||||
}
|
||||
|
||||
}
|
||||
52
app/help.h
Normal file
52
app/help.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef HELP_HELPER
|
||||
#define HELP_HELPER
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace help {
|
||||
|
||||
enum class KeyboardFeatures : uint16_t {
|
||||
none = 0,
|
||||
rgb = 1,
|
||||
intensity = 2,
|
||||
commit = 4,
|
||||
logo1 = 8,
|
||||
logo2 = 16,
|
||||
numpad = 32,
|
||||
multimedia = 64,
|
||||
gkeys = 128,
|
||||
setall = 256,
|
||||
setgroup = 512,
|
||||
setkey = 1024,
|
||||
setregion = 2048,
|
||||
setindicators = 4096,
|
||||
poweronfx = 8192,
|
||||
// fx features
|
||||
|
||||
all = rgb | intensity | commit | logo1 | logo2 | numpad | multimedia | gkeys |
|
||||
setall | setgroup | setkey | setregion | setindicators | poweronfx,
|
||||
|
||||
g213 = rgb | logo1 | numpad | multimedia | setall | setregion | setindicators | poweronfx,
|
||||
g410 = rgb | commit | setall | setgroup | setkey | poweronfx,
|
||||
g413 = intensity | setall,
|
||||
g610 = intensity | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx,
|
||||
g810 = rgb | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx,
|
||||
g910 = rgb | commit | logo1 | logo2 | numpad | multimedia | gkeys | setall | setgroup | setkey | setindicators | poweronfx,
|
||||
gpro = rgb | commit | logo1 | multimedia | setall | setgroup | setkey | setindicators | poweronfx
|
||||
};
|
||||
inline KeyboardFeatures operator|(KeyboardFeatures a, KeyboardFeatures b);
|
||||
|
||||
KeyboardFeatures getKeyboardFeatures(std::string cmdName);
|
||||
|
||||
void usage(char *arg0);
|
||||
void keys(char *arg0);
|
||||
void effects(char *arg0);
|
||||
void samples(char *arg0);
|
||||
|
||||
}
|
||||
|
||||
#ifndef VERSION
|
||||
#define VERSION "unspecified"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
310
app/main.cpp
Normal file
310
app/main.cpp
Normal file
@@ -0,0 +1,310 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
#include "help.h"
|
||||
#include "utils.h"
|
||||
#include "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: "<<device.manufacturer<<" - "<<device.product<<std::endl;
|
||||
std::cout<<"\tVendor ID: "<<std::hex<<std::setw(4)<<std::setfill('0')<<device.vendorID<<std::endl;
|
||||
std::cout<<"\tProduct ID: "<<std::hex<<std::setw(4)<<std::setfill('0')<<device.productID<<std::endl;
|
||||
std::cout<<"\tSerial Number: "<<device.serialNumber<<std::endl;
|
||||
}
|
||||
|
||||
int listKeyboards(LedKeyboard &kbd) {
|
||||
std::vector<LedKeyboard::DeviceInfo> deviceList = kbd.listKeyboards();
|
||||
if (deviceList.empty()) {
|
||||
std::cout<<"Matching or compatible device not found !"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<LedKeyboard::DeviceInfo>::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;
|
||||
|
||||
if (! kbd.setNativeEffect(effect, effectPart, speed, color)) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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<std::string, std::string> vars;
|
||||
LedKeyboard::KeyValueArray keys = {};
|
||||
int retval = 0;
|
||||
while (!stream.eof()) {
|
||||
getline(stream, line);
|
||||
if (line.size() > 0 && line.substr(0, 1) != "#") {
|
||||
std::vector<std::string> 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]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
LedKeyboard kbd;
|
||||
std::string serial;
|
||||
uint16_t vendorID = 0x0;
|
||||
uint16_t productID = 0x0;
|
||||
|
||||
int argIndex = 1;
|
||||
while (argIndex < argc)
|
||||
{
|
||||
std::string arg = argv[argIndex];
|
||||
|
||||
// Non-Command arguments
|
||||
if (argc > (argIndex + 1) && arg == "-ds") {
|
||||
serial = argv[argIndex + 1];
|
||||
argIndex += 2;
|
||||
continue;
|
||||
} else if (argc > (argIndex + 1) && arg == "-dv"){
|
||||
if (! utils::parseUInt16(argv[argIndex + 1], vendorID)) return 1;
|
||||
argIndex += 2;
|
||||
continue;
|
||||
} else if (argc > (argIndex + 1) && arg == "-dp"){
|
||||
if (! utils::parseUInt16(argv[argIndex + 1], productID)) return 1;
|
||||
argIndex += 2;
|
||||
continue;
|
||||
} else if (argc > (argIndex + 1) && arg == "-tuk"){
|
||||
uint8_t kbdProtocol = 0;
|
||||
if (! utils::parseUInt8(argv[argIndex + 1], kbdProtocol)) return 1;
|
||||
switch(kbdProtocol) {
|
||||
case 1:
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, (u_int16_t)LedKeyboard::KeyboardModel::g810 } };
|
||||
break;
|
||||
case 2:
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, (u_int16_t)LedKeyboard::KeyboardModel::g910 } };
|
||||
break;
|
||||
case 3:
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, (u_int16_t)LedKeyboard::KeyboardModel::g213 } };
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
argIndex += 2;
|
||||
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 == "--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;}
|
||||
|
||||
//Initialize the device for use
|
||||
if (!kbd.open(vendorID, productID, serial)) {
|
||||
std::cout << "Matching or compatible device not found !" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// 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);
|
||||
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);
|
||||
else if (argc > (argIndex + 4) && arg == "-fx")
|
||||
return 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]);
|
||||
else { help::usage(argv[0]); return 1; }
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
228
app/utils.cpp
Normal file
228
app/utils.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
#include "utils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Keyboard.h"
|
||||
|
||||
|
||||
namespace utils {
|
||||
|
||||
std::string getCmdName(std::string cmd) {
|
||||
return cmd.substr(cmd.find_last_of("/\\") + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool parseStartupMode(std::string val, LedKeyboard::StartupMode &startupMode) {
|
||||
if (val == "wave") startupMode = LedKeyboard::StartupMode::wave;
|
||||
else if (val == "color") startupMode = LedKeyboard::StartupMode::color;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseNativeEffect(std::string val, LedKeyboard::NativeEffect &nativeEffect) {
|
||||
if (val == "color") nativeEffect = LedKeyboard::NativeEffect::color;
|
||||
else if (val == "cycle") nativeEffect = LedKeyboard::NativeEffect::cycle;
|
||||
else if (val == "breathing") nativeEffect = LedKeyboard::NativeEffect::breathing;
|
||||
else if (val == "hwave") nativeEffect = LedKeyboard::NativeEffect::hwave;
|
||||
else if (val == "vwave") nativeEffect = LedKeyboard::NativeEffect::vwave;
|
||||
else if (val == "cwave") nativeEffect = LedKeyboard::NativeEffect::cwave;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseNativeEffectPart(std::string val, LedKeyboard::NativeEffectPart &nativeEffectPart) {
|
||||
if (val == "all") nativeEffectPart = LedKeyboard::NativeEffectPart::all;
|
||||
else if (val == "keys") nativeEffectPart = LedKeyboard::NativeEffectPart::keys;
|
||||
else if (val == "logo") nativeEffectPart = LedKeyboard::NativeEffectPart::logo;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseKey(std::string val, LedKeyboard::Key &key) {
|
||||
std::transform(val.begin(), val.end(), val.begin(), ::tolower);
|
||||
if (val == "logo") key = LedKeyboard::Key::logo;
|
||||
else if (val == "logo2") key = LedKeyboard::Key::logo2;
|
||||
else if (val == "back_light" || val == "backlight" || val == "light") key = LedKeyboard::Key::backlight;
|
||||
else if (val == "game_mode" || val == "gamemode" || val == "game") key = LedKeyboard::Key::game;
|
||||
else if (val == "caps_indicator" || val == "capsindicator" || val == "caps") key = LedKeyboard::Key::caps;
|
||||
else if (val == "scroll_indicator" || val == "scrollindicator" || val == "scroll") key = LedKeyboard::Key::scroll;
|
||||
else if (val == "num_indicator" || val == "numindicator" || val == "num") key = LedKeyboard::Key::num;
|
||||
else if (val == "next") key = LedKeyboard::Key::next;
|
||||
else if (val == "prev" || val == "previous") key = LedKeyboard::Key::prev;
|
||||
else if (val == "stop") key = LedKeyboard::Key::stop;
|
||||
else if (val == "play_pause" || val == "playpause" || val == "play") key = LedKeyboard::Key::play;
|
||||
else if (val == "mute") key = LedKeyboard::Key::mute;
|
||||
else if (val == "a") key = LedKeyboard::Key::a;
|
||||
else if (val == "b") key = LedKeyboard::Key::b;
|
||||
else if (val == "c") key = LedKeyboard::Key::c;
|
||||
else if (val == "d") key = LedKeyboard::Key::d;
|
||||
else if (val == "e") key = LedKeyboard::Key::e;
|
||||
else if (val == "f") key = LedKeyboard::Key::f;
|
||||
else if (val == "g") key = LedKeyboard::Key::g;
|
||||
else if (val == "h") key = LedKeyboard::Key::h;
|
||||
else if (val == "i") key = LedKeyboard::Key::i;
|
||||
else if (val == "j") key = LedKeyboard::Key::j;
|
||||
else if (val == "k") key = LedKeyboard::Key::k;
|
||||
else if (val == "l") key = LedKeyboard::Key::l;
|
||||
else if (val == "m") key = LedKeyboard::Key::m;
|
||||
else if (val == "n") key = LedKeyboard::Key::n;
|
||||
else if (val == "o") key = LedKeyboard::Key::o;
|
||||
else if (val == "p") key = LedKeyboard::Key::p;
|
||||
else if (val == "q") key = LedKeyboard::Key::q;
|
||||
else if (val == "r") key = LedKeyboard::Key::r;
|
||||
else if (val == "s") key = LedKeyboard::Key::s;
|
||||
else if (val == "t") key = LedKeyboard::Key::t;
|
||||
else if (val == "u") key = LedKeyboard::Key::u;
|
||||
else if (val == "v") key = LedKeyboard::Key::v;
|
||||
else if (val == "w") key = LedKeyboard::Key::w;
|
||||
else if (val == "x") key = LedKeyboard::Key::x;
|
||||
else if (val == "z") key = LedKeyboard::Key::z;
|
||||
else if (val == "y") key = LedKeyboard::Key::y;
|
||||
else if (val == "1" || val == "one") key = LedKeyboard::Key::n1;
|
||||
else if (val == "2" || val == "two") key = LedKeyboard::Key::n2;
|
||||
else if (val == "3" || val == "three") key = LedKeyboard::Key::n3;
|
||||
else if (val == "4" || val == "four") key = LedKeyboard::Key::n4;
|
||||
else if (val == "5" || val == "five") key = LedKeyboard::Key::n5;
|
||||
else if (val == "6" || val == "six") key = LedKeyboard::Key::n6;
|
||||
else if (val == "7" || val == "seven") key = LedKeyboard::Key::n7;
|
||||
else if (val == "8" || val == "eight") key = LedKeyboard::Key::n8;
|
||||
else if (val == "9" || val == "nine") key = LedKeyboard::Key::n9;
|
||||
else if (val == "0" || val == "zero") key = LedKeyboard::Key::n0;
|
||||
else if (val == "enter") key = LedKeyboard::Key::enter;
|
||||
else if (val == "esc" || val == "escape") key = LedKeyboard::Key::esc;
|
||||
else if (val == "back" || val == "backspace") key = LedKeyboard::Key::backspace;
|
||||
else if (val == "tab") key = LedKeyboard::Key::tab;
|
||||
else if (val == "space") key = LedKeyboard::Key::space;
|
||||
else if (val == "tilde" || val == "~") key = LedKeyboard::Key::tilde;
|
||||
else if (val == "minus" || val == "-") key = LedKeyboard::Key::minus;
|
||||
else if (val == "equal" || val == "=") key = LedKeyboard::Key::equal;
|
||||
else if (val == "open_bracket" || val == "[") key = LedKeyboard::Key::open_bracket;
|
||||
else if (val == "close_bracket" || val == "]") key = LedKeyboard::Key::close_bracket;
|
||||
else if (val == "backslash" || val == "\\") key = LedKeyboard::Key::backslash;
|
||||
else if (val == "semicolon" || val == ";") key = LedKeyboard::Key::semicolon;
|
||||
else if (val == "quote" || val == "\"") key = LedKeyboard::Key::quote;
|
||||
else if (val == "dollar" || val == "$") key = LedKeyboard::Key::dollar;
|
||||
else if (val == "comma" || val == ",") key = LedKeyboard::Key::comma;
|
||||
else if (val == "period" || val == ".") key = LedKeyboard::Key::period;
|
||||
else if (val == "slash" || val == "/") key = LedKeyboard::Key::slash;
|
||||
else if (val == "caps_lock" || val == "capslock") key = LedKeyboard::Key::caps_lock;
|
||||
else if (val == "f1") key = LedKeyboard::Key::f1;
|
||||
else if (val == "f2") key = LedKeyboard::Key::f2;
|
||||
else if (val == "f3") key = LedKeyboard::Key::f3;
|
||||
else if (val == "f4") key = LedKeyboard::Key::f4;
|
||||
else if (val == "f5") key = LedKeyboard::Key::f5;
|
||||
else if (val == "f6") key = LedKeyboard::Key::f6;
|
||||
else if (val == "f7") key = LedKeyboard::Key::f7;
|
||||
else if (val == "f8") key = LedKeyboard::Key::f8;
|
||||
else if (val == "f9") key = LedKeyboard::Key::f9;
|
||||
else if (val == "f10") key = LedKeyboard::Key::f10;
|
||||
else if (val == "f11") key = LedKeyboard::Key::f11;
|
||||
else if (val == "f12") key = LedKeyboard::Key::f12;
|
||||
else if (val == "print_screen" || val == "printscreen" || val == "printscr" || val == "print")
|
||||
key = LedKeyboard::Key::print_screen;
|
||||
else if (val == "scroll_lock" || val == "scrolllock") key = LedKeyboard::Key::scroll_lock;
|
||||
else if (val == "pause_break" || val == "pausebreak" || val == "pause" || val == "break")
|
||||
key = LedKeyboard::Key::pause_break;
|
||||
else if (val == "insert" || val == "ins") key = LedKeyboard::Key::insert;
|
||||
else if (val == "home") key = LedKeyboard::Key::home;
|
||||
else if (val == "page_up" || val == "pageup") key = LedKeyboard::Key::page_up;
|
||||
else if (val == "delete" || val == "del") key = LedKeyboard::Key::del;
|
||||
else if (val == "end") key = LedKeyboard::Key::end;
|
||||
else if (val == "page_down" || val == "pagedown") key = LedKeyboard::Key::page_down;
|
||||
else if (val == "arrow_right" || val == "arrowright" || val == "right") key = LedKeyboard::Key::arrow_right;
|
||||
else if (val == "arrow_left" || val == "arrowleft" || val == "left") key = LedKeyboard::Key::arrow_left;
|
||||
else if (val == "arrow_bottom" || val == "arrowbottom" || val == "bottom") key = LedKeyboard::Key::arrow_bottom;
|
||||
else if (val == "arrow_top" || val == "arrowtop" || val == "top") key = LedKeyboard::Key::arrow_top;
|
||||
else if (val == "num_lock" || val == "numlock") key = LedKeyboard::Key::num_lock;
|
||||
else if (val == "num/" || val == "num_slash" || val == "numslash") key = LedKeyboard::Key::num_slash;
|
||||
else if (val == "num*" || val == "num_asterisk" || val == "numasterisk") key = LedKeyboard::Key::num_asterisk;
|
||||
else if (val == "num-" || val == "num_minus" || val == "numminus") key = LedKeyboard::Key::num_minus;
|
||||
else if (val == "num+" || val == "num_plus" || val == "numplus") key = LedKeyboard::Key::num_plus;
|
||||
else if (val == "numenter") key = LedKeyboard::Key::num_enter;
|
||||
else if (val == "num1") key = LedKeyboard::Key::num_1;
|
||||
else if (val == "num2") key = LedKeyboard::Key::num_2;
|
||||
else if (val == "num3") key = LedKeyboard::Key::num_3;
|
||||
else if (val == "num4") key = LedKeyboard::Key::num_4;
|
||||
else if (val == "num5") key = LedKeyboard::Key::num_5;
|
||||
else if (val == "num6") key = LedKeyboard::Key::num_6;
|
||||
else if (val == "num7") key = LedKeyboard::Key::num_7;
|
||||
else if (val == "num8") key = LedKeyboard::Key::num_8;
|
||||
else if (val == "num9") key = LedKeyboard::Key::num_9;
|
||||
else if (val == "num0") key = LedKeyboard::Key::num_0;
|
||||
else if (val == "num." || val == "num_period" || val == "numperiod") key = LedKeyboard::Key::num_dot;
|
||||
else if (val == "intl_backslash" || val == "<") key = LedKeyboard::Key::intl_backslash;
|
||||
else if (val == "menu") key = LedKeyboard::Key::menu;
|
||||
else if (val == "ctrl_left" || val == "ctrlleft" || val == "ctrll") key = LedKeyboard::Key::ctrl_left;
|
||||
else if (val == "shift_left" || val == "shiftleft" || val == "shiftl") key = LedKeyboard::Key::shift_left;
|
||||
else if (val == "alt_left" || val == "altleft" || val == "altl") key = LedKeyboard::Key::alt_left;
|
||||
else if (val == "win_left" || val == "winleft" || val == "winl") key = LedKeyboard::Key::win_left;
|
||||
else if (val == "meta_left" || val == "metaleft" || val == "metal") key = LedKeyboard::Key::win_left;
|
||||
else if (val == "ctrl_right" || val == "ctrlright" || val == "ctrlr") key = LedKeyboard::Key::ctrl_right;
|
||||
else if (val == "shift_right" || val == "shiftright" || val == "shiftr") key = LedKeyboard::Key::shift_right;
|
||||
else if (val == "alt_right" || val == "altright" || val == "altr" || val == "altgr")
|
||||
key = LedKeyboard::Key::alt_right;
|
||||
else if (val == "win_right" || val == "winright" || val == "winr") key = LedKeyboard::Key::win_right;
|
||||
else if (val == "meta_right" || val == "metaright" || val == "metar") key = LedKeyboard::Key::win_right;
|
||||
else if (val == "g1") key = LedKeyboard::Key::g1;
|
||||
else if (val == "g2") key = LedKeyboard::Key::g2;
|
||||
else if (val == "g3") key = LedKeyboard::Key::g3;
|
||||
else if (val == "g4") key = LedKeyboard::Key::g4;
|
||||
else if (val == "g5") key = LedKeyboard::Key::g5;
|
||||
else if (val == "g6") key = LedKeyboard::Key::g6;
|
||||
else if (val == "g7") key = LedKeyboard::Key::g7;
|
||||
else if (val == "g8") key = LedKeyboard::Key::g8;
|
||||
else if (val == "g9") key = LedKeyboard::Key::g9;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseKeyGroup(std::string val, LedKeyboard::KeyGroup &keyGroup) {
|
||||
if (val == "logo") keyGroup = LedKeyboard::KeyGroup::logo;
|
||||
else if (val == "indicators") keyGroup = LedKeyboard::KeyGroup::indicators;
|
||||
else if (val == "multimedia") keyGroup = LedKeyboard::KeyGroup::multimedia;
|
||||
else if (val == "fkeys") keyGroup = LedKeyboard::KeyGroup::fkeys;
|
||||
else if (val == "modifiers") keyGroup = LedKeyboard::KeyGroup::modifiers;
|
||||
else if (val == "arrows") keyGroup = LedKeyboard::KeyGroup::arrows;
|
||||
else if (val == "numeric") keyGroup = LedKeyboard::KeyGroup::numeric;
|
||||
else if (val == "functions") keyGroup = LedKeyboard::KeyGroup::functions;
|
||||
else if (val == "keys") keyGroup = LedKeyboard::KeyGroup::keys;
|
||||
else if (val == "gkeys") keyGroup = LedKeyboard::KeyGroup::gkeys;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseColor(std::string val, LedKeyboard::Color &color) {
|
||||
if (val.length() == 2) val = val + "0000"; // For G610
|
||||
if (val.length() != 6) return false;
|
||||
color.red = std::stoul("0x"+val.substr(0,2), nullptr, 16);
|
||||
color.green = std::stoul("0x"+val.substr(2,2), nullptr, 16);
|
||||
color.blue = std::stoul("0x"+val.substr(4,2), nullptr, 16);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseSpeed(std::string val, uint8_t &speed) {
|
||||
if (val.length() == 1) val = "0" + val;
|
||||
if (val.length() != 2) return false;
|
||||
speed = std::stoul("0x" + val, nullptr, 16);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseUInt8(std::string val, uint8_t &uint8) {
|
||||
if (val.length() == 1) val = "0" + val;
|
||||
if (val.length() != 2) return false;
|
||||
uint8 = std::stoul("0x" + val, nullptr, 16);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseUInt16(std::string val, uint16_t &uint16) {
|
||||
if (val.length() == 1) val = "0" + val;
|
||||
if (val.length() == 2) val = "0" + val;
|
||||
if (val.length() == 3) val = "0" + val;
|
||||
if (val.length() != 4) return false;
|
||||
uint16 = std::stoul("0x" + val, nullptr, 16);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
23
app/utils.h
Normal file
23
app/utils.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef UTILS_HELPER
|
||||
#define UTILS_HELPER
|
||||
|
||||
#include <iostream>
|
||||
#include "Keyboard.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
std::string getCmdName(std::string cmd);
|
||||
|
||||
bool parseStartupMode(std::string val, LedKeyboard::StartupMode &startupMode);
|
||||
bool parseNativeEffect(std::string val, LedKeyboard::NativeEffect &nativeEffect);
|
||||
bool parseNativeEffectPart(std::string val, LedKeyboard::NativeEffectPart &nativeEffectPart);
|
||||
bool parseKey(std::string val, LedKeyboard::Key &key);
|
||||
bool parseKeyGroup(std::string val, LedKeyboard::KeyGroup &keyGroup);
|
||||
bool parseColor(std::string val, LedKeyboard::Color &color);
|
||||
bool parseSpeed(std::string val, uint8_t &speed);
|
||||
bool parseUInt8(std::string val, uint8_t &uint8);
|
||||
bool parseUInt16(std::string val, uint16_t &uint16);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user