From d4531da71a1bc57fbd1bd1a08af92cf8c7d626b8 Mon Sep 17 00:00:00 2001 From: dokutan <54861821+dokutan@users.noreply.github.com> Date: Sun, 12 Jul 2020 22:02:29 +0200 Subject: [PATCH] Add --model option, add M709 as valid argument --- include/m709/data.cpp | 2 +- include/print_help.cpp | 1 + include/rd_mouse.h | 1 + makefile | 25 ++++++++++++++- mouse_m908.1 | 3 ++ mouse_m908.cpp | 73 +++++++++++++++++++++++++++++++++++++----- 6 files changed, 95 insertions(+), 10 deletions(-) diff --git a/include/m709/data.cpp b/include/m709/data.cpp index 9ecdd0f..737d4eb 100644 --- a/include/m709/data.cpp +++ b/include/m709/data.cpp @@ -24,7 +24,7 @@ // usb device vars const uint16_t mouse_m709::_c_mouse_vid = 0x04d9; -const uint16_t mouse_m709::_c_mouse_pid = 0xfc4d; +const uint16_t mouse_m709::_c_mouse_pid = 0xfc2a; // Names of the physical buttons std::map< int, std::string > mouse_m709::_c_button_names = { diff --git a/include/print_help.cpp b/include/print_help.cpp index eebb24c..5b6ed4f 100644 --- a/include/print_help.cpp +++ b/include/print_help.cpp @@ -36,5 +36,6 @@ void print_help(){ std::cout << "-v --version\n\tPrint version.\n"; std::cout << "-R --read=arg\n\tRead settings from the mouse and print configuration to the specified file (\"-\" = stdout).\n"; std::cout << "-D --dump=arg\n\tRead settings from the mouse and dump the raw data to the specified file (\"-\" = stdout).\n"; + std::cout << "-M --model=arg\n\tSpecifies the mouse model (709, 908).\n"; //std::cout << "-r --repeat\n\tSets number of times the macro will be repeated (1-255).\n"; } diff --git a/include/rd_mouse.h b/include/rd_mouse.h index 90c5541..d126081 100644 --- a/include/rd_mouse.h +++ b/include/rd_mouse.h @@ -95,5 +95,6 @@ class rd_mouse{ // include header files for the individual models TODO! #include "m908/mouse_m908.h" +#include "m709/mouse_m709.h" #endif diff --git a/makefile b/makefile index 5761f8d..ce57113 100644 --- a/makefile +++ b/makefile @@ -13,7 +13,7 @@ LIBS != pkg-config --libs libusb-1.0 VERSION_STRING = "\"2.1\"" # compile -build: m908 data_rd.o load_config.o mouse_m908.o +build: m908 m709 data_rd.o load_config.o mouse_m908.o $(CC) *.o -o mouse_m908 $(LIBS) $(CC_OPTIONS) # copy all files to their correct location @@ -69,6 +69,8 @@ hpkg: # targets for different mice m908: constructor_m908.o data_m908.o getters_m908.o helpers_m908.o setters_m908.o writers_m908.o readers_m908.o +m709: constructor_m709.o data_m709.o getters_m709.o helpers_m709.o setters_m709.o writers_m709.o readers_m709.o + # individual files mouse_m908.o: $(CC) -c mouse_m908.cpp $(CC_OPTIONS) -D VERSION_STRING=$(VERSION_STRING) @@ -99,3 +101,24 @@ writers_m908.o: readers_m908.o: $(CC) -c include/m908/readers.cpp $(CC_OPTIONS) -o readers_m908.o + +constructor_m709.o: + $(CC) -c include/m709/constructor.cpp $(CC_OPTIONS) -o constructor_m709.o + +data_m709.o: + $(CC) -c include/m709/data.cpp $(CC_OPTIONS) -o data_m709.o + +getters_m709.o: + $(CC) -c include/m709/getters.cpp $(CC_OPTIONS) -o getters_m709.o + +helpers_m709.o: + $(CC) -c include/m709/helpers.cpp $(CC_OPTIONS) -o helpers_m709.o + +setters_m709.o: + $(CC) -c include/m709/setters.cpp $(CC_OPTIONS) -o setters_m709.o + +writers_m709.o: + $(CC) -c include/m709/writers.cpp $(CC_OPTIONS) -o writers_m709.o + +readers_m709.o: + $(CC) -c include/m709/readers.cpp $(CC_OPTIONS) -o readers_m709.o diff --git a/mouse_m908.1 b/mouse_m908.1 index 9d10e9d..c803a02 100644 --- a/mouse_m908.1 +++ b/mouse_m908.1 @@ -49,6 +49,9 @@ Read settings from the mouse and print the configuration to the specfied file. U .TP \fB\-D\fR, \fB\-\-dump\fR=\fIFILE\fR Read settings from the mouse and dump the raw data to the specfied file. Uses stdout when \fIFILE\fR is "-". Only useful for debugging and development. +.TP +\fB\-M\fR, \fB\-\-model\fR=\fINAME\fR +Specifies the model of the mouse (709, 908). .SH EXAMPLES To send the configuration from example.ini .PP diff --git a/mouse_m908.cpp b/mouse_m908.cpp index f1e74b2..8559892 100644 --- a/mouse_m908.cpp +++ b/mouse_m908.cpp @@ -39,7 +39,7 @@ // this function checks its arguments and opens the mouse accordingly // (with vid and pid or with bus and device) -int open_mouse_wrapper( mouse_m908 &m, const bool flag_bus, const bool flag_device, +template< typename T >int open_mouse_wrapper( T &m, const bool flag_bus, const bool flag_device, const std::string &string_bus, const std::string &string_device ){ int open_return = 0; // open_mouse() return value @@ -71,6 +71,7 @@ int open_mouse_wrapper( mouse_m908 &m, const bool flag_bus, const bool flag_devi std::cout << "Couldn't open mouse.\n"; std::cout << "- Check hardware and permissions (maybe you need to be root?)\n"; std::cout << "- Try with or without the --kernel-driver option\n"; + std::cout << "- Try with the --model option\n"; std::cout << "- Try with the --bus and --device options\n"; std::cout << "If nothing works please report this as a bug.\n"; return 1; @@ -79,10 +80,17 @@ int open_mouse_wrapper( mouse_m908 &m, const bool flag_bus, const bool flag_devi return 0; } +// function to perform all actions on the mouse +template< typename T > int perform_actions( +bool flag_config, bool flag_profile, bool flag_macro, bool flag_number, +bool flag_bus, bool flag_device, bool flag_kernel_driver, +bool flag_dump_settings, bool flag_read_settings, +std::string string_config, std::string string_profile, std::string string_macro, +std::string string_number, std::string string_bus, std::string string_device, +std::string string_dump, std::string string_read ); + int main( int argc, char **argv ){ - mouse_m908 m; - // if no arguments: print help if( argc == 1 ){ print_help(); @@ -103,6 +111,7 @@ int main( int argc, char **argv ){ {"version", no_argument, 0, 'v'}, {"dump", required_argument, 0, 'D'}, {"read", required_argument, 0, 'R'}, + {"model", required_argument, 0, 'M'}, {0, 0, 0, 0} }; @@ -120,11 +129,11 @@ int main( int argc, char **argv ){ //std::string string_repeat; std::string string_bus, string_device; std::string string_dump, string_read; + std::string string_model = "908"; //parse command line options int c, option_index = 0; - //while( (c = getopt_long( argc, argv, "hc:p:m:n:b:d:kvr:", - while( (c = getopt_long( argc, argv, "hc:p:m:n:b:d:kvD:R:", + while( (c = getopt_long( argc, argv, "hc:p:m:n:b:d:kvD:R:M:", long_options, &option_index ) ) != -1 ){ switch( c ){ @@ -174,6 +183,9 @@ int main( int argc, char **argv ){ flag_read_settings = true; string_read = optarg; break; + case 'M': + string_model = optarg; + break; case '?': break; default: @@ -181,13 +193,58 @@ int main( int argc, char **argv ){ } } - // set whether to detach kernel driver - m.set_detach_kernel_driver( !flag_kernel_driver ); - // print version if requested if( flag_version ) std::cout << "Version: " << VERSION_STRING << "\n"; + // parse model → call perform_actions() + if( string_model == "908" ){ + + return perform_actions< mouse_m908 >( + flag_config, flag_profile, flag_macro, flag_number, + flag_bus, flag_device, flag_kernel_driver, + flag_dump_settings, flag_read_settings, + string_config, string_profile, string_macro, + string_number, string_bus, string_device, + string_dump, string_read ); + + }else if( string_model == "709" ){ + + return perform_actions< mouse_m709 >( + flag_config, flag_profile, flag_macro, flag_number, + flag_bus, flag_device, flag_kernel_driver, + flag_dump_settings, flag_read_settings, + string_config, string_profile, string_macro, + string_number, string_bus, string_device, + string_dump, string_read ); + + }else{ + + std::cout << "Unknown model, valid options are:\n"; + std::cout << "709\n908\n"; + return 1; + + } + + + return 0; +} + + +template< typename T > int perform_actions( +bool flag_config, bool flag_profile, bool flag_macro, bool flag_number, +bool flag_bus, bool flag_device, bool flag_kernel_driver, +bool flag_dump_settings, bool flag_read_settings, +std::string string_config, std::string string_profile, std::string string_macro, +std::string string_number, std::string string_bus, std::string string_device, +std::string string_dump, std::string string_read ){ + + // create mouse object + T m; + + // set whether to detach kernel driver + m.set_detach_kernel_driver( !flag_kernel_driver ); + // read settings and dump raw data if( flag_dump_settings ){