From f1e8ac1af7c02e4904a1a5b557f3b93e8bf56dd7 Mon Sep 17 00:00:00 2001 From: dokutan <54861821+dokutan@users.noreply.github.com> Date: Mon, 29 Mar 2021 00:29:34 +0200 Subject: [PATCH] Add more button mapping options --- include/data.cpp | 22 +++++++++++++--------- include/rd_mouse.cpp | 10 +++++++++- keymap.md | 6 ++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/include/data.cpp b/include/data.cpp index 631ac4c..106bec8 100644 --- a/include/data.cpp +++ b/include/data.cpp @@ -33,19 +33,23 @@ const uint8_t rd_mouse::_c_dpi_2_min = 0x00, rd_mouse::_c_dpi_2_max = 0x01; //name → keycode std::map< std::string, std::array > rd_mouse::_c_keycodes = { - { "forward", { 0x85, 0x00, 0x00, 0x00 } }, - { "backward", { 0x84, 0x00, 0x00, 0x00 } }, - { "dpi+", { 0x8a, 0x00, 0x00, 0x00 } }, - { "dpi-", { 0x89, 0x00, 0x00, 0x00 } }, - { "dpi-cycle", { 0x88, 0x00, 0x00, 0x00 } }, - { "report_rate+", { 0x97, 0x00, 0x00, 0x00 } }, - { "report_rate-", { 0x98, 0x00, 0x00, 0x00 } }, - { "scroll_up", { 0x8b, 0x00, 0x00, 0x00 } }, - { "scroll_down", { 0x8c, 0x00, 0x00, 0x00 } }, { "left", { 0x81, 0x00, 0x00, 0x00 } }, { "right", { 0x82, 0x00, 0x00, 0x00 } }, { "middle", { 0x83, 0x00, 0x00, 0x00 } }, + { "backward", { 0x84, 0x00, 0x00, 0x00 } }, + { "forward", { 0x85, 0x00, 0x00, 0x00 } }, + { "dpi-cycle", { 0x88, 0x00, 0x00, 0x00 } }, + { "dpi-", { 0x89, 0x00, 0x00, 0x00 } }, + { "dpi+", { 0x8a, 0x00, 0x00, 0x00 } }, + { "scroll_up", { 0x8b, 0x00, 0x00, 0x00 } }, + { "scroll_down", { 0x8c, 0x00, 0x00, 0x00 } }, { "profile_switch", { 0x8d, 0x00, 0x00, 0x00 } }, + { "profile+", { 0x94, 0x00, 0x00, 0x00 } }, + { "profile-", { 0x95, 0x00, 0x00, 0x00 } }, + { "report_rate+", { 0x97, 0x00, 0x00, 0x00 } }, + { "report_rate-", { 0x98, 0x00, 0x00, 0x00 } }, + { "dpi_led_toggle", { 0x9b, 0x01, 0x00, 0x00 } }, + { "reset_settings", { 0x9b, 0x02, 0x00, 0x00 } }, { "led_mode_switch", { 0x9b, 0x04, 0x00, 0x00 } }, { "none", { 0x00, 0x00, 0x00, 0x00 } }, { "media_play", { 0x8e, 0x01, 0xcd, 0x00 } }, diff --git a/include/rd_mouse.cpp b/include/rd_mouse.cpp index 5f37271..aea6bef 100644 --- a/include/rd_mouse.cpp +++ b/include/rd_mouse.cpp @@ -778,8 +778,16 @@ int rd_mouse::_i_decode_button_mapping( std::array& bytes, std::stri int rd_mouse::_i_encode_button_mapping( std::string& mapping, std::array& bytes ){ + // raw byte values + if( std::regex_match( mapping, std::regex("0x[0-9a-fA-F]{8}") ) ){ + + bytes[0] = std::stoi( mapping.substr(2, 2) , 0, 16 ); + bytes[1] = std::stoi( mapping.substr(4, 2) , 0, 16 ); + bytes[2] = std::stoi( mapping.substr(6, 2) , 0, 16 ); + bytes[3] = std::stoi( mapping.substr(8, 2) , 0, 16 ); + // is string in _c_keycodes? mousebuttons/special functions and media controls - if( _c_keycodes.find(mapping) != _c_keycodes.end() ){ + } else if( _c_keycodes.find(mapping) != _c_keycodes.end() ){ bytes[0] = _c_keycodes[mapping][0]; bytes[1] = _c_keycodes[mapping][1]; diff --git a/keymap.md b/keymap.md index d810e68..1472540 100644 --- a/keymap.md +++ b/keymap.md @@ -19,6 +19,8 @@ A button on the mouse can be mapped to one function out of the following categor - Media controls (only available for compatibility, use the Media_* keyboard keys if possible) - Example: ``media_play`` +Additionally it is possible to specify the raw bytes of the mapping, this is intended for debugging and testing. Example: ``0x11aa22bb`` + The following sections list all valid button mappings. ## Media controls @@ -61,7 +63,11 @@ left right middle profile_switch +profile+ +profile- led_mode_switch +dpi_led_toggle +reset_settings none ## Compatibility functions (these are only handled by the official software and are mostly redundant)