From f4c415887bc9e4d2613ea19ba7f112c09454dcd1 Mon Sep 17 00:00:00 2001 From: dokutan <54861821+dokutan@users.noreply.github.com> Date: Wed, 20 Jan 2021 18:39:39 +0100 Subject: [PATCH] Move generic dpi_bytes_to_string() to rd_mouse --- include/generic/helpers.cpp | 14 ---- include/generic/mouse_generic.h | 7 +- include/m709/helpers.cpp | 14 ---- include/m709/mouse_m709.h | 5 -- include/m711/helpers.cpp | 14 ---- include/m711/mouse_m711.h | 5 -- include/m715/helpers.cpp | 14 ---- include/m715/mouse_m715.h | 5 -- include/m908/mouse_m908.h | 1 + include/m990/data.cpp | 95 +-------------------------- include/m990/helpers.cpp | 25 ------- include/m990/mouse_m990.h | 5 -- include/m990chroma/helpers.cpp | 14 ---- include/m990chroma/mouse_m990chroma.h | 5 -- include/rd_mouse.cpp | 14 ++++ include/rd_mouse.h | 7 +- 16 files changed, 23 insertions(+), 221 deletions(-) diff --git a/include/generic/helpers.cpp b/include/generic/helpers.cpp index 7a8403c..c770ccf 100644 --- a/include/generic/helpers.cpp +++ b/include/generic/helpers.cpp @@ -157,17 +157,3 @@ int mouse_generic::print_settings( std::ostream& output ){ return 0; } - -int mouse_generic::dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ){ - - std::stringstream conversion_stream; - - conversion_stream << std::setfill('0') << std::hex; - conversion_stream << "0x"; - conversion_stream << std::setw(2) << (int)dpi_bytes[0] << std::setw(2) << (int)dpi_bytes[1]; - conversion_stream << std::setfill(' ') << std::setw(0) << std::dec; - - dpi_string = conversion_stream.str(); - - return 0; -} diff --git a/include/generic/mouse_generic.h b/include/generic/mouse_generic.h index 275cd14..8e2edea 100644 --- a/include/generic/mouse_generic.h +++ b/include/generic/mouse_generic.h @@ -235,12 +235,7 @@ class mouse_generic : public rd_mouse{ /// Print the current configuration in .ini format to output int print_settings( std::ostream& output ); - /** Convert raw dpi bytes to a string representation (doesn't validate dpi value) - * \return 0 if no error - */ - int dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ); - - + //reader functions (get settings from the mouse) /// Read the settings and print the raw data to output diff --git a/include/m709/helpers.cpp b/include/m709/helpers.cpp index 2b30cdc..e781d80 100644 --- a/include/m709/helpers.cpp +++ b/include/m709/helpers.cpp @@ -157,17 +157,3 @@ int mouse_m709::print_settings( std::ostream& output ){ return 0; } - -int mouse_m709::dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ){ - - std::stringstream conversion_stream; - - conversion_stream << std::setfill('0') << std::hex; - conversion_stream << "0x"; - conversion_stream << std::setw(2) << (int)dpi_bytes[0] << std::setw(2) << (int)dpi_bytes[1]; - conversion_stream << std::setfill(' ') << std::setw(0) << std::dec; - - dpi_string = conversion_stream.str(); - - return 0; -} diff --git a/include/m709/mouse_m709.h b/include/m709/mouse_m709.h index 586c29b..4eee63c 100644 --- a/include/m709/mouse_m709.h +++ b/include/m709/mouse_m709.h @@ -228,11 +228,6 @@ class mouse_m709 : public rd_mouse{ /// Print the current configuration in .ini format to output int print_settings( std::ostream& output ); - /** Convert raw dpi bytes to a string representation (doesn't validate dpi value) - * \return 0 if no error - */ - int dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ); - //reader functions (get settings from the mouse) diff --git a/include/m711/helpers.cpp b/include/m711/helpers.cpp index 4a5502a..66080a8 100644 --- a/include/m711/helpers.cpp +++ b/include/m711/helpers.cpp @@ -156,17 +156,3 @@ int mouse_m711::print_settings( std::ostream& output ){ return 0; } - -int mouse_m711::dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ){ - - std::stringstream conversion_stream; - - conversion_stream << std::setfill('0') << std::hex; - conversion_stream << "0x"; - conversion_stream << std::setw(2) << (int)dpi_bytes[0] << std::setw(2) << (int)dpi_bytes[1]; - conversion_stream << std::setfill(' ') << std::setw(0) << std::dec; - - dpi_string = conversion_stream.str(); - - return 0; -} diff --git a/include/m711/mouse_m711.h b/include/m711/mouse_m711.h index 4455725..bc8ce16 100644 --- a/include/m711/mouse_m711.h +++ b/include/m711/mouse_m711.h @@ -235,11 +235,6 @@ class mouse_m711 : public rd_mouse{ /// Print the current configuration in .ini format to output int print_settings( std::ostream& output ); - /** Convert raw dpi bytes to a string representation (doesn't validate dpi value) - * \return 0 if no error - */ - int dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ); - //reader functions (get settings from the mouse) diff --git a/include/m715/helpers.cpp b/include/m715/helpers.cpp index 15440fe..05d2a51 100644 --- a/include/m715/helpers.cpp +++ b/include/m715/helpers.cpp @@ -156,17 +156,3 @@ int mouse_m715::print_settings( std::ostream& output ){ return 0; } - -int mouse_m715::dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ){ - - std::stringstream conversion_stream; - - conversion_stream << std::setfill('0') << std::hex; - conversion_stream << "0x"; - conversion_stream << std::setw(2) << (int)dpi_bytes[0] << std::setw(2) << (int)dpi_bytes[1]; - conversion_stream << std::setfill(' ') << std::setw(0) << std::dec; - - dpi_string = conversion_stream.str(); - - return 0; -} diff --git a/include/m715/mouse_m715.h b/include/m715/mouse_m715.h index 75eb152..c34a2b9 100644 --- a/include/m715/mouse_m715.h +++ b/include/m715/mouse_m715.h @@ -235,11 +235,6 @@ class mouse_m715 : public rd_mouse{ /// Print the current configuration in .ini format to output int print_settings( std::ostream& output ); - /** Convert raw dpi bytes to a string representation (doesn't validate dpi value) - * \return 0 if no error - */ - int dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ); - //reader functions (get settings from the mouse) diff --git a/include/m908/mouse_m908.h b/include/m908/mouse_m908.h index 91cbc70..9a3feea 100644 --- a/include/m908/mouse_m908.h +++ b/include/m908/mouse_m908.h @@ -229,6 +229,7 @@ class mouse_m908 : public rd_mouse{ int print_settings( std::ostream& output ); /** Convert raw dpi bytes to a string representation (doesn't validate dpi value) + * This function overloads the implementation from rd_mouse and supports actual DPI values. * \return 0 if no error */ int dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ); diff --git a/include/m990/data.cpp b/include/m990/data.cpp index 70e5f53..f397999 100644 --- a/include/m990/data.cpp +++ b/include/m990/data.cpp @@ -56,102 +56,9 @@ std::map< int, std::string > mouse_m990::_c_button_names = { { 25, "scroll_down" } }; // Mapping of real DPI values to bytecode TODO! +// Take a look the M908 implementation for details. // Min. 50, Max. 16400 std::map< unsigned int, std::array > mouse_m990::_c_dpi_codes = { - /* - { 200, {0x4, 0x00} }, - { 300, {0x6, 0x00} }, - { 400, {0x9, 0x00} }, - { 500, {0xb, 0x00} }, - { 600, {0xd, 0x00} }, - { 700, {0xf, 0x00} }, - { 800, {0x12, 0x00} }, - { 900, {0x14, 0x00} }, - { 1000, {0x16, 0x00} }, - { 1100, {0x18, 0x00} }, - { 1200, {0x1b, 0x00} }, - { 1300, {0x1d, 0x00} }, - { 1400, {0x1f, 0x00} }, - { 1500, {0x21, 0x00} }, - { 1600, {0x24, 0x00} }, - { 1700, {0x26, 0x00} }, - { 1800, {0x28, 0x00} }, - { 1900, {0x2b, 0x00} }, - { 2000, {0x2d, 0x00} }, - { 2100, {0x2f, 0x00} }, - { 2200, {0x31, 0x00} }, - { 2300, {0x34, 0x00} }, - { 2400, {0x36, 0x00} }, - { 2500, {0x38, 0x00} }, - { 2600, {0x3a, 0x00} }, - { 2700, {0x3d, 0x00} }, - { 2800, {0x3f, 0x00} }, - { 2900, {0x41, 0x00} }, - { 3000, {0x43, 0x00} }, - { 3100, {0x46, 0x00} }, - { 3200, {0x48, 0x00} }, - { 3300, {0x4a, 0x00} }, - { 3400, {0x4d, 0x00} }, - { 3500, {0x4f, 0x00} }, - { 3600, {0x51, 0x00} }, - { 3700, {0x53, 0x00} }, - { 3800, {0x56, 0x00} }, - { 3900, {0x58, 0x00} }, - { 4000, {0x5a, 0x00} }, - { 4100, {0x5c, 0x00} }, - { 4200, {0x5f, 0x00} }, - { 4300, {0x61, 0x00} }, - { 4400, {0x63, 0x00} }, - { 4500, {0x66, 0x00} }, - { 4600, {0x68, 0x00} }, - { 4700, {0x6a, 0x00} }, - { 4800, {0x6c, 0x00} }, - { 4900, {0x6f, 0x00} }, - { 5000, {0x71, 0x00} }, - { 5100, {0x73, 0x00} }, - { 5200, {0x75, 0x00} }, - { 5300, {0x78, 0x00} }, - { 5400, {0x7a, 0x00} }, - { 5500, {0x7c, 0x00} }, - { 5600, {0x7f, 0x00} }, - { 5700, {0x81, 0x00} }, - { 5800, {0x83, 0x00} }, - { 5900, {0x85, 0x00} }, - { 6000, {0x87, 0x00} }, - { 6100, {0x8a, 0x00} }, - { 6200, {0x8c, 0x00} }, - { 6400, {0x48, 0x01} }, - { 6600, {0x4a, 0x01} }, - { 6800, {0x4d, 0x01} }, - { 7000, {0x4f, 0x01} }, - { 7200, {0x51, 0x01} }, - { 7400, {0x53, 0x01} }, - { 7600, {0x56, 0x01} }, - { 7800, {0x58, 0x01} }, - { 8000, {0x5a, 0x01} }, - { 8200, {0x5c, 0x01} }, - { 8400, {0x5f, 0x01} }, - { 8600, {0x61, 0x01} }, - { 8800, {0x63, 0x01} }, - { 9000, {0x66, 0x01} }, - { 9200, {0x68, 0x01} }, - { 9400, {0x6a, 0x01} }, - { 9600, {0x6c, 0x01} }, - { 9800, {0x6f, 0x01} }, - { 10000, {0x71, 0x01} }, - { 10200, {0x73, 0x01} }, - { 10400, {0x75, 0x01} }, - { 10600, {0x78, 0x01} }, - { 10800, {0x7a, 0x01} }, - { 11000, {0x7c, 0x01} }, - { 11200, {0x7f, 0x01} }, - { 11400, {0x81, 0x01} }, - { 11600, {0x83, 0x01} }, - { 11800, {0x85, 0x01} }, - { 12000, {0x87, 0x01} }, - { 12200, {0x8a, 0x01} }, - { 12400, {0x8c, 0x01} } - */ }; //usb data packets diff --git a/include/m990/helpers.cpp b/include/m990/helpers.cpp index 9333131..2180b67 100644 --- a/include/m990/helpers.cpp +++ b/include/m990/helpers.cpp @@ -157,28 +157,3 @@ int mouse_m990::print_settings( std::ostream& output ){ return 0; } - -int mouse_m990::dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ){ - - // is dpi value known? - for( auto dpi_value : _c_dpi_codes ){ - - if( dpi_value.second[0] == dpi_bytes[0] && dpi_value.second[1] == dpi_bytes[1] ){ - dpi_string = std::to_string( dpi_value.first ); - return 0; - } - - } - - // unknown dpi value - std::stringstream conversion_stream; - - conversion_stream << std::setfill('0') << std::hex; - conversion_stream << "0x"; - conversion_stream << std::setw(2) << (int)dpi_bytes[0] << std::setw(2) << (int)dpi_bytes[1]; - conversion_stream << std::setfill(' ') << std::setw(0) << std::dec; - - dpi_string = conversion_stream.str(); - - return 0; -} diff --git a/include/m990/mouse_m990.h b/include/m990/mouse_m990.h index 0709a84..9d055e1 100644 --- a/include/m990/mouse_m990.h +++ b/include/m990/mouse_m990.h @@ -230,11 +230,6 @@ class mouse_m990 : public rd_mouse{ /// Print the current configuration in .ini format to output int print_settings( std::ostream& output ); - /** Convert raw dpi bytes to a string representation (doesn't validate dpi value) - * \return 0 if no error - */ - int dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ); - //reader functions (get settings from the mouse) diff --git a/include/m990chroma/helpers.cpp b/include/m990chroma/helpers.cpp index 4b57bf3..cb2f47c 100644 --- a/include/m990chroma/helpers.cpp +++ b/include/m990chroma/helpers.cpp @@ -157,17 +157,3 @@ int mouse_m990chroma::print_settings( std::ostream& output ){ return 0; } - -int mouse_m990chroma::dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ){ - - std::stringstream conversion_stream; - - conversion_stream << std::setfill('0') << std::hex; - conversion_stream << "0x"; - conversion_stream << std::setw(2) << (int)dpi_bytes[0] << std::setw(2) << (int)dpi_bytes[1]; - conversion_stream << std::setfill(' ') << std::setw(0) << std::dec; - - dpi_string = conversion_stream.str(); - - return 0; -} diff --git a/include/m990chroma/mouse_m990chroma.h b/include/m990chroma/mouse_m990chroma.h index 91e5578..55e271e 100644 --- a/include/m990chroma/mouse_m990chroma.h +++ b/include/m990chroma/mouse_m990chroma.h @@ -228,11 +228,6 @@ class mouse_m990chroma : public rd_mouse{ /// Print the current configuration in .ini format to output int print_settings( std::ostream& output ); - /** Convert raw dpi bytes to a string representation (doesn't validate dpi value) - * \return 0 if no error - */ - int dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ); - //reader functions (get settings from the mouse) diff --git a/include/rd_mouse.cpp b/include/rd_mouse.cpp index e23ab81..5ed6a2b 100644 --- a/include/rd_mouse.cpp +++ b/include/rd_mouse.cpp @@ -884,3 +884,17 @@ int rd_mouse::_i_encode_button_mapping( std::string& mapping, std::array& dpi_bytes, std::string& dpi_string ){ + + std::stringstream conversion_stream; + + conversion_stream << std::setfill('0') << std::hex; + conversion_stream << "0x"; + conversion_stream << std::setw(2) << (int)dpi_bytes[0] << std::setw(2) << (int)dpi_bytes[1]; + conversion_stream << std::setfill(' ') << std::setw(0) << std::dec; + + dpi_string = conversion_stream.str(); + + return 0; +} diff --git a/include/rd_mouse.h b/include/rd_mouse.h index cb528f6..c59417c 100644 --- a/include/rd_mouse.h +++ b/include/rd_mouse.h @@ -92,7 +92,12 @@ class rd_mouse{ /// Get _i_detach_kernel_driver bool get_detach_kernel_driver(){ return _i_detach_kernel_driver; } - + /** Convert raw dpi bytes to a string representation (doesn't validate dpi value) + * This implementation always outputs the raw bytes as a hexdump, + * to support actual DPI values this function needs to be overloaded in the model specific classes. + * \return 0 if no error occured + */ + int dpi_bytes_to_string( std::array& dpi_bytes, std::string& dpi_string ); protected: