From 4ba501c09394dbd103585429a5e6952c08e65d3f Mon Sep 17 00:00:00 2001 From: dokutan <54861821+dokutan@users.noreply.github.com> Date: Tue, 4 Jan 2022 17:39:16 +0100 Subject: [PATCH] Move M913 and M686 keycodes to a new class --- CMakeLists.txt | 2 ++ include/m686/data.cpp | 16 -------------- include/m686/helpers.cpp | 2 +- include/m686/mouse_m686.h | 6 +++--- include/m686/setters.cpp | 6 +++--- include/m913/data.cpp | 16 -------------- include/m913/helpers.cpp | 2 +- include/m913/mouse_m913.h | 6 +++--- include/m913/setters.cpp | 6 +++--- include/rd_mouse_wireless.cpp | 35 +++++++++++++++++++++++++++++++ include/rd_mouse_wireless.h | 39 +++++++++++++++++++++++++++++++++++ makefile | 5 ++++- 12 files changed, 94 insertions(+), 47 deletions(-) create mode 100644 include/rd_mouse_wireless.cpp create mode 100644 include/rd_mouse_wireless.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 95b690b..05f006c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,8 @@ target_sources(mouse_m908 include/load_config.h include/rd_mouse.cpp include/rd_mouse.h + include/rd_mouse_wireless.cpp + include/rd_mouse_wireless.h include/generic/constructor.cpp include/generic/data.cpp include/generic/getters.cpp diff --git a/include/m686/data.cpp b/include/m686/data.cpp index adad683..c975121 100644 --- a/include/m686/data.cpp +++ b/include/m686/data.cpp @@ -62,22 +62,6 @@ std::map< int, std::array > mouse_m686::_c_keyboard_key_buttons = { { 11, {0x02, 0x60, 0x87} }, // button_dpi_down }; -std::map< std::string, std::array > mouse_m686::_c_keycodes = { - { "left", { 0x01, 0x01, 0x00, 0x53 } }, - { "right", { 0x01, 0x02, 0x00, 0x52 } }, - { "middle", { 0x01, 0x04, 0x00, 0x50 } }, - { "backward", { 0x01, 0x08, 0x00, 0x4c } }, - { "forward", { 0x01, 0x10, 0x00, 0x44 } }, - { "led_toggle", { 0x08, 0x00, 0x00, 0x4d } }, - { "report_rate", { 0x07, 0x00, 0x00, 0x4e } }, - { "dpi-", { 0x02, 0x03, 0x00, 0x50 } }, - { "dpi+", { 0x02, 0x02, 0x00, 0x51 } }, - { "dpi-cycle", { 0x02, 0x01, 0x00, 0x52 } }, - { "default", { 0x05, 0x00, 0x00, 0x50 } }, - { "none", { 0x00, 0x00, 0x00, 0x55 } }, - { "profile_switch", { 0x09, 0x00, 0x00, 0x4c } }, -}; - /* see documentation/m913-key-press.txt for a description of these packets, partially generated with: #!/usr/bin/env julia for i in [0:25;] diff --git a/include/m686/helpers.cpp b/include/m686/helpers.cpp index 760403b..2db9fd1 100644 --- a/include/m686/helpers.cpp +++ b/include/m686/helpers.cpp @@ -302,7 +302,7 @@ int mouse_m686::_i_decode_button_mapping( const std::array& bytes, s std::stringstream mapping_stream; // known keycode ? - for( auto keycode : _c_keycodes ){ + for( auto keycode : rd_mouse_wireless::_c_keycodes ){ if( bytes.at(0) == keycode.second.at(0) && bytes.at(1) == keycode.second.at(1) && diff --git a/include/m686/mouse_m686.h b/include/m686/mouse_m686.h index 9859aac..485d64f 100644 --- a/include/m686/mouse_m686.h +++ b/include/m686/mouse_m686.h @@ -20,6 +20,8 @@ #ifndef MOUSE_M686 #define MOUSE_M686 +#include "../rd_mouse_wireless.h" + #include #include #include @@ -54,7 +56,7 @@ * - \_s\_* for variables that describe the settings on the mouse * - \_c\_* for constants like keycodes, USB data, minimum and maximum values, etc. (these are not neccessarily defined as const) */ -class mouse_m686 : public rd_mouse{ +class mouse_m686 : public rd_mouse, protected rd_mouse_wireless { public: @@ -311,8 +313,6 @@ class mouse_m686 : public rd_mouse{ /// DPI → bytecode static std::map< int, std::array > _c_dpi_codes; - /// Values/keycodes of mouse buttons and special button functions - static std::map< std::string, std::array > _c_keycodes; /// Used to identify buttons when mapping buttons to keyboard keys static std::map< int, std::array > _c_keyboard_key_buttons; diff --git a/include/m686/setters.cpp b/include/m686/setters.cpp index 3324e29..91b561c 100644 --- a/include/m686/setters.cpp +++ b/include/m686/setters.cpp @@ -178,7 +178,7 @@ int mouse_m686::set_key_mapping( rd_profile profile, int key, std::string mappin if( _c_keyboard_key_packets.find(mapping) != _c_keyboard_key_packets.end() ){ // keyboard key // the button gets mapped as "default" - _s_keymap_data[rd_profile_to_m686_profile(profile)][key] = _c_keycodes["default"]; + _s_keymap_data[rd_profile_to_m686_profile(profile)][key] = rd_mouse_wireless::_c_keycodes["default"]; // and additional packets are sent _s_keyboard_key_packets.push_back(_c_keyboard_key_packets[mapping]); @@ -186,9 +186,9 @@ int mouse_m686::set_key_mapping( rd_profile profile, int key, std::string mappin _s_keyboard_key_packets.back()[4] = _c_keyboard_key_buttons[key][1]; _s_keyboard_key_packets.back()[16] = _c_keyboard_key_buttons[key][2]; - }else if( _c_keycodes.find(mapping) != _c_keycodes.end() ){ // mouse buttons, special functions, ... + }else if( rd_mouse_wireless::_c_keycodes.find(mapping) != rd_mouse_wireless::_c_keycodes.end() ){ // mouse buttons, special functions, ... - _s_keymap_data[rd_profile_to_m686_profile(profile)][key] = _c_keycodes[mapping]; + _s_keymap_data[rd_profile_to_m686_profile(profile)][key] = rd_mouse_wireless::_c_keycodes[mapping]; } diff --git a/include/m913/data.cpp b/include/m913/data.cpp index ada09d8..1ef5e5e 100644 --- a/include/m913/data.cpp +++ b/include/m913/data.cpp @@ -70,22 +70,6 @@ std::map< int, std::array > mouse_m913::_c_keyboard_key_buttons = { { 15, {0x02, 0xe0, 0x07} }, // button_12 }; -std::map< std::string, std::array > mouse_m913::_c_keycodes = { - { "left", { 0x01, 0x01, 0x00, 0x53 } }, - { "right", { 0x01, 0x02, 0x00, 0x52 } }, - { "middle", { 0x01, 0x04, 0x00, 0x50 } }, - { "backward", { 0x01, 0x08, 0x00, 0x4c } }, - { "forward", { 0x01, 0x10, 0x00, 0x44 } }, - { "led_toggle", { 0x08, 0x00, 0x00, 0x4d } }, - { "report_rate", { 0x07, 0x00, 0x00, 0x4e } }, - { "dpi-", { 0x02, 0x03, 0x00, 0x50 } }, - { "dpi+", { 0x02, 0x02, 0x00, 0x51 } }, - { "dpi-cycle", { 0x02, 0x01, 0x00, 0x52 } }, - { "default", { 0x05, 0x00, 0x00, 0x50 } }, - { "none", { 0x00, 0x00, 0x00, 0x55 } }, - { "profile_switch", { 0x09, 0x00, 0x00, 0x4c } }, -}; - /* see documentation/m913-key-press.txt for a description of these packets, partially generated with: #!/usr/bin/env julia for i in [0:25;] diff --git a/include/m913/helpers.cpp b/include/m913/helpers.cpp index ff75684..2b1f00a 100644 --- a/include/m913/helpers.cpp +++ b/include/m913/helpers.cpp @@ -302,7 +302,7 @@ int mouse_m913::_i_decode_button_mapping( const std::array& bytes, s std::stringstream mapping_stream; // known keycode ? - for( auto keycode : _c_keycodes ){ + for( auto keycode : rd_mouse_wireless::_c_keycodes ){ if( bytes.at(0) == keycode.second.at(0) && bytes.at(1) == keycode.second.at(1) && diff --git a/include/m913/mouse_m913.h b/include/m913/mouse_m913.h index 00d5e76..b2be261 100644 --- a/include/m913/mouse_m913.h +++ b/include/m913/mouse_m913.h @@ -20,6 +20,8 @@ #ifndef MOUSE_M913 #define MOUSE_M913 +#include "../rd_mouse_wireless.h" + #include #include #include @@ -54,7 +56,7 @@ * - \_s\_* for variables that describe the settings on the mouse * - \_c\_* for constants like keycodes, USB data, minimum and maximum values, etc. (these are not neccessarily defined as const) */ -class mouse_m913 : public rd_mouse{ +class mouse_m913 : public rd_mouse, protected rd_mouse_wireless { public: @@ -311,8 +313,6 @@ class mouse_m913 : public rd_mouse{ /// DPI → bytecode static std::map< int, std::array > _c_dpi_codes; - /// Values/keycodes of mouse buttons and special button functions - static std::map< std::string, std::array > _c_keycodes; /// Used to identify buttons when mapping buttons to keyboard keys static std::map< int, std::array > _c_keyboard_key_buttons; diff --git a/include/m913/setters.cpp b/include/m913/setters.cpp index 0d81196..4d822ea 100644 --- a/include/m913/setters.cpp +++ b/include/m913/setters.cpp @@ -178,7 +178,7 @@ int mouse_m913::set_key_mapping( rd_profile profile, int key, std::string mappin if( _c_keyboard_key_packets.find(mapping) != _c_keyboard_key_packets.end() ){ // keyboard key // the button gets mapped as "default" - _s_keymap_data[rd_profile_to_m913_profile(profile)][key] = _c_keycodes["default"]; + _s_keymap_data[rd_profile_to_m913_profile(profile)][key] = rd_mouse_wireless::_c_keycodes["default"]; // and additional packets are sent _s_keyboard_key_packets.push_back(_c_keyboard_key_packets[mapping]); @@ -186,9 +186,9 @@ int mouse_m913::set_key_mapping( rd_profile profile, int key, std::string mappin _s_keyboard_key_packets.back()[4] = _c_keyboard_key_buttons[key][1]; _s_keyboard_key_packets.back()[16] = _c_keyboard_key_buttons[key][2]; - }else if( _c_keycodes.find(mapping) != _c_keycodes.end() ){ // mouse buttons, special functions, ... + }else if( rd_mouse_wireless::_c_keycodes.find(mapping) != rd_mouse_wireless::_c_keycodes.end() ){ // mouse buttons, special functions, ... - _s_keymap_data[rd_profile_to_m913_profile(profile)][key] = _c_keycodes[mapping]; + _s_keymap_data[rd_profile_to_m913_profile(profile)][key] = rd_mouse_wireless::_c_keycodes[mapping]; } diff --git a/include/rd_mouse_wireless.cpp b/include/rd_mouse_wireless.cpp new file mode 100644 index 0000000..1576665 --- /dev/null +++ b/include/rd_mouse_wireless.cpp @@ -0,0 +1,35 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + +#include "rd_mouse_wireless.h" + +std::map< std::string, std::array > rd_mouse_wireless::_c_keycodes = { + { "left", { 0x01, 0x01, 0x00, 0x53 } }, + { "right", { 0x01, 0x02, 0x00, 0x52 } }, + { "middle", { 0x01, 0x04, 0x00, 0x50 } }, + { "backward", { 0x01, 0x08, 0x00, 0x4c } }, + { "forward", { 0x01, 0x10, 0x00, 0x44 } }, + { "led_toggle", { 0x08, 0x00, 0x00, 0x4d } }, + { "report_rate", { 0x07, 0x00, 0x00, 0x4e } }, + { "dpi-", { 0x02, 0x03, 0x00, 0x50 } }, + { "dpi+", { 0x02, 0x02, 0x00, 0x51 } }, + { "dpi-cycle", { 0x02, 0x01, 0x00, 0x52 } }, + { "default", { 0x05, 0x00, 0x00, 0x50 } }, + { "none", { 0x00, 0x00, 0x00, 0x55 } }, + { "profile_switch", { 0x09, 0x00, 0x00, 0x4c } }, +}; diff --git a/include/rd_mouse_wireless.h b/include/rd_mouse_wireless.h new file mode 100644 index 0000000..0a5631a --- /dev/null +++ b/include/rd_mouse_wireless.h @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + +#ifndef RD_MOUSE_WIRELESS +#define RD_MOUSE_WIRELESS + +#include +#include +#include +#include + +/** + * This class holds data that is shared between the wireless mice. + */ +class rd_mouse_wireless{ + + protected: + + /// Values/keycodes of mouse buttons and special button functions + static std::map< std::string, std::array > _c_keycodes; + +}; + +#endif diff --git a/makefile b/makefile index 1b8bc94..667d7f2 100644 --- a/makefile +++ b/makefile @@ -14,7 +14,7 @@ LIBS != pkg-config --libs libusb-1.0 VERSION_STRING = "\"3.2\"" # compile -build: m607 m686 m908 m709 m711 m715 m719 m721 m913 m990 m990chroma generic data_rd.o rd_mouse.o load_config.o mouse_m908.o +build: m607 m686 m908 m709 m711 m715 m719 m721 m913 m990 m990chroma generic data_rd.o rd_mouse.o rd_mouse_wireless.o load_config.o mouse_m908.o $(CC) *.o -o mouse_m908 $(LIBS) $(CC_OPTIONS) # copy all files to their correct location @@ -110,6 +110,9 @@ data_rd.o: rd_mouse.o: $(CC) -c include/rd_mouse.cpp $(CC_OPTIONS) +rd_mouse_wireless.o: + $(CC) -c include/rd_mouse_wireless.cpp $(CC_OPTIONS) + constructor_m607.o: $(CC) -c include/m607/constructor.cpp $(CC_OPTIONS) -o constructor_m607.o