From 4ec98be4d0c365dbd3c58c6b177dfcdfccafb63e Mon Sep 17 00:00:00 2001 From: dokutan <54861821+dokutan@users.noreply.github.com> Date: Fri, 8 May 2020 23:17:44 +0200 Subject: [PATCH] Clean up code, improve documentation --- Doxyfile | 2 +- documentation/README.md | 12 ++- include/constructor.cpp | 205 +--------------------------------------- include/data.cpp | 204 ++++++++++++++++++++++++++++++++++++++- include/mouse_m908.h | 118 ++++++++++++++++++++--- 5 files changed, 321 insertions(+), 220 deletions(-) diff --git a/Doxyfile b/Doxyfile index 656c3c9..9420ecb 100644 --- a/Doxyfile +++ b/Doxyfile @@ -467,7 +467,7 @@ EXTRACT_ALL = YES # be included in the documentation. # The default value is: NO. -EXTRACT_PRIVATE = NO +EXTRACT_PRIVATE = YES # If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual # methods of a class will be included in the documentation. diff --git a/documentation/README.md b/documentation/README.md index 3057d4c..dd24c1c 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -1,8 +1,16 @@ -# USB Protocol description +# Documentation + +## Source documentation +Doxygen is used in places for source code documentation. To build the documentation install doxygen and run +``` +doxygen Doxyfile +``` + +## USB Protocol description This directory contains captured usb data (when sending the default settings). For further details look at the write functions in the source code. default.txt and default-annotated.pdf contain the extracted usb data when sending the default settings. This was obtained by exporting packet dissections as plain text from wireshark (select only bytes) and running ``grep "00[4-9]0"`` on the exported files. -## Button mapping +### Button mapping The function of each button is described by 4 bytes. In case of the fire button all 4 bytes are used, in all other cases the last byte is 0x00. Look at ``set_key_mapping()`` (setters.cpp) and constructor.cpp for the meaning of these bytes. diff --git a/include/constructor.cpp b/include/constructor.cpp index 8cfe992..cd88458 100644 --- a/include/constructor.cpp +++ b/include/constructor.cpp @@ -18,24 +18,9 @@ #include "mouse_m908.h" -//constructor +// Constructor, set the default settings mouse_m908::mouse_m908(){ - _mouse_vid = 0x04d9; - _mouse_pid = 0xfc4d; - - //min and max settings - _scrollspeed_min = 0x01; - _scrollspeed_max = 0x3f; - _brightness_min = 0x01; - _brightness_max = 0x03; - _speed_min = 0x01; - _speed_max = 0x08; - _level_min = 0; - _level_max = 4; - _dpi_min = 0x04; - _dpi_max = 0x8c; - //default settings _profile = profile_1; _scrollspeeds.fill( 0x01 ); @@ -63,192 +48,4 @@ mouse_m908::mouse_m908(){ } _macro_repeat.fill( 0x01 ); - //name → keycode - _keycodes = { - { "forward", { 0x85, 0x00, 0x00 } }, - { "backward", { 0x84, 0x00, 0x00 } }, - { "dpi+", { 0x8a, 0x00, 0x00 } }, - { "dpi-", { 0x89, 0x00, 0x00 } }, - { "dpi-cycle", { 0x88, 0x00, 0x00 } }, - { "report_rate+", { 0x97, 0x00, 0x00 } }, - { "report_rate-", { 0x98, 0x00, 0x00 } }, - { "scroll_up", { 0x8b, 0x00, 0x00 } }, - { "scroll_down", { 0x8c, 0x00, 0x00 } }, - { "left", { 0x81, 0x00, 0x00 } }, - { "right", { 0x82, 0x00, 0x00 } }, - { "middle", { 0x83, 0x00, 0x00 } }, - { "profile_switch", { 0x8d, 0x00, 0x00 } }, - { "led_mode_switch", { 0x9b, 0x04, 0x00 } }, - { "macro1", { 0x91, 0x00, 0x01 } }, - { "macro2", { 0x91, 0x01, 0x01 } }, - { "macro3", { 0x91, 0x02, 0x01 } }, - { "macro4", { 0x91, 0x03, 0x01 } }, - { "macro5", { 0x91, 0x04, 0x01 } }, - { "macro6", { 0x91, 0x05, 0x01 } }, - { "macro7", { 0x91, 0x06, 0x01 } }, - { "macro8", { 0x91, 0x07, 0x01 } }, - { "macro9", { 0x91, 0x08, 0x01 } }, - { "macro10", { 0x91, 0x09, 0x01 } }, - { "macro11", { 0x91, 0x0a, 0x01 } }, - { "macro12", { 0x91, 0x0b, 0x01 } }, - { "macro13", { 0x91, 0x0c, 0x01 } }, - { "macro14", { 0x91, 0x0d, 0x01 } }, - { "macro15", { 0x91, 0x0e, 0x01 } }, - { "none", { 0x00, 0x00, 0x00 } }, - { "media_play", { 0x8e, 0x01, 0xcd } }, - { "media_stop", { 0x8e, 0x01, 0xb7 } }, - { "media_previous", { 0x8e, 0x01, 0xb6 } }, - { "media_next", { 0x8e, 0x01, 0xb5 } }, - { "media_volume_up", { 0x8e, 0x01, 0xe9 } }, - { "media_volume_down", { 0x8e, 0x01, 0xea } }, - { "media_mute", { 0x8e, 0x01, 0xe2 } } }; - - //modifier name → value - _keyboard_modifier_values = { - { "ctrl_l+", 1 }, - { "shift_l+", 2 }, - { "alt_l+", 4 }, - { "super_l+", 8 }, - { "ctrl_r+", 16 }, - { "shift_r+", 32 }, - { "alt_r+", 64 }, - { "super_r+", 128 } }; - - //keyboard key name → value - //top row - _keyboard_key_values["Esc"] = 0x29; - _keyboard_key_values["F1"] = 0x3a; - _keyboard_key_values["F2"] = 0x3b; - _keyboard_key_values["F3"] = 0x3c; - _keyboard_key_values["F4"] = 0x3d; - _keyboard_key_values["F5"] = 0x3e; - _keyboard_key_values["F6"] = 0x3f; - _keyboard_key_values["F7"] = 0x40; - _keyboard_key_values["F8"] = 0x41; - _keyboard_key_values["F9"] = 0x42; - _keyboard_key_values["F10"] = 0x43; - _keyboard_key_values["F11"] = 0x44; - _keyboard_key_values["F12"] = 0x45; - _keyboard_key_values["PrtSc"] = 0x46; - _keyboard_key_values["ScrLk"] = 0x47; - _keyboard_key_values["Pause"] = 0x48; - //alphanumeric - _keyboard_key_values["a"] = 0x04; - _keyboard_key_values["b"] = 0x05; - _keyboard_key_values["c"] = 0x06; - _keyboard_key_values["d"] = 0x07; - _keyboard_key_values["e"] = 0x08; - _keyboard_key_values["f"] = 0x09; - _keyboard_key_values["g"] = 0x0a; - _keyboard_key_values["h"] = 0x0b; - _keyboard_key_values["i"] = 0x0c; - _keyboard_key_values["j"] = 0x0d; - _keyboard_key_values["k"] = 0x0e; - _keyboard_key_values["l"] = 0x0f; - _keyboard_key_values["m"] = 0x10; - _keyboard_key_values["n"] = 0x11; - _keyboard_key_values["o"] = 0x12; - _keyboard_key_values["p"] = 0x13; - _keyboard_key_values["q"] = 0x14; - _keyboard_key_values["r"] = 0x15; - _keyboard_key_values["s"] = 0x16; - _keyboard_key_values["t"] = 0x17; - _keyboard_key_values["u"] = 0x18; - _keyboard_key_values["v"] = 0x19; - _keyboard_key_values["w"] = 0x1a; - _keyboard_key_values["x"] = 0x1b; - _keyboard_key_values["y"] = 0x1c; - _keyboard_key_values["z"] = 0x1d; - _keyboard_key_values["1"] = 0x1e; - _keyboard_key_values["2"] = 0x1f; - _keyboard_key_values["3"] = 0x20; - _keyboard_key_values["4"] = 0x21; - _keyboard_key_values["5"] = 0x22; - _keyboard_key_values["6"] = 0x23; - _keyboard_key_values["7"] = 0x24; - _keyboard_key_values["8"] = 0x25; - _keyboard_key_values["9"] = 0x26; - _keyboard_key_values["0"] = 0x27; - //modifiers - _keyboard_key_values["Tab"] = 0x2b; - _keyboard_key_values["Caps_Lock"] = 0x39; - _keyboard_key_values["Shift_l"] = 0xe1; - _keyboard_key_values["Ctrl_l"] = 0xe0; - _keyboard_key_values["Alt_l"] = 0xe2; - _keyboard_key_values["Super_l"] = 0xe3; - _keyboard_key_values["Super_r"] = 0xe7; - _keyboard_key_values["Alt_r"] = 0xe6; - _keyboard_key_values["Menu"] = 0x65; - _keyboard_key_values["Ctrl_r"] = 0xe4; - _keyboard_key_values["Shift_r"] = 0xe5; - _keyboard_key_values["Return"] = 0x28; - _keyboard_key_values["Backspace"] = 0x2a; - _keyboard_key_values["Caps_Lock"] = 0x39; - //special characters - _keyboard_key_values["Space"] = 0x2b; - _keyboard_key_values["Tilde"] = 0x35; - _keyboard_key_values["Minus"] = 0x2d; - _keyboard_key_values["Equals"] = 0x2e; - _keyboard_key_values["Bracket_l"] = 0x2f; - _keyboard_key_values["Bracket_r"] = 0x30; - _keyboard_key_values["Backslash"] = 0x31; - _keyboard_key_values["Semicolon"] = 0x33; - _keyboard_key_values["Apostrophe"] = 0x34; - _keyboard_key_values["Comma"] = 0x36; - _keyboard_key_values["Period"] = 0x37; - _keyboard_key_values["Slash"] = 0x38; - _keyboard_key_values["Int_Key"] = 0x64; - //navigation - _keyboard_key_values["Right"] = 0x4f; - _keyboard_key_values["Left"] = 0x50; - _keyboard_key_values["Down"] = 0x51; - _keyboard_key_values["Up"] = 0x52; - _keyboard_key_values["Insert"] = 0x49; - _keyboard_key_values["Home"] = 0x4a; - _keyboard_key_values["PgUp"] = 0x4b; - _keyboard_key_values["Delete"] = 0x4c; - _keyboard_key_values["End"] = 0x4d; - _keyboard_key_values["PgDown"] = 0x4e; - //numpad - _keyboard_key_values["Num_Slash"] = 0x54; - _keyboard_key_values["Num_Asterisk"] = 0x55; - _keyboard_key_values["Num_Minus"] = 0x56; - _keyboard_key_values["Num_Plus"] = 0x57; - _keyboard_key_values["Num_Return"] = 0x58; - _keyboard_key_values["Num_1"] = 0x59; - _keyboard_key_values["Num_2"] = 0x5a; - _keyboard_key_values["Num_3"] = 0x5b; - _keyboard_key_values["Num_4"] = 0x5c; - _keyboard_key_values["Num_5"] = 0x5d; - _keyboard_key_values["Num_6"] = 0x5e; - _keyboard_key_values["Num_7"] = 0x5f; - _keyboard_key_values["Num_8"] = 0x60; - _keyboard_key_values["Num_9"] = 0x61; - _keyboard_key_values["Num_0"] = 0x62; - _keyboard_key_values["Num_Period"] = 0x63; - _keyboard_key_values["Num_Lock"] = 0x53; - //media controls, etc. TODO - //special keys - _keyboard_key_values["Lang1"] = 0x90; - _keyboard_key_values["Lang2"] = 0x91; - _keyboard_key_values["Lang3"] = 0x92; - _keyboard_key_values["Lang4"] = 0x93; - _keyboard_key_values["Lang5"] = 0x94; - _keyboard_key_values["Lang6"] = 0x95; - _keyboard_key_values["Lang7"] = 0x96; - _keyboard_key_values["Lang8"] = 0x97; - _keyboard_key_values["Lang9"] = 0x98; - _keyboard_key_values["F13"] = 0x68; - _keyboard_key_values["F14"] = 0x69; - _keyboard_key_values["F15"] = 0x6a; - _keyboard_key_values["F16"] = 0x6b; - _keyboard_key_values["F17"] = 0x6c; - _keyboard_key_values["F18"] = 0x6d; - _keyboard_key_values["F19"] = 0x6e; - _keyboard_key_values["F20"] = 0x6f; - _keyboard_key_values["F21"] = 0x70; - _keyboard_key_values["F22"] = 0x71; - _keyboard_key_values["F23"] = 0x72; - _keyboard_key_values["F24"] = 0x73; - } diff --git a/include/data.cpp b/include/data.cpp index 8934b46..3352a16 100644 --- a/include/data.cpp +++ b/include/data.cpp @@ -16,10 +16,212 @@ * */ +/* + * This file contains internal constants and lookup tables + */ + #include "mouse_m908.h" -//usb data packets +// usb device vars +const uint16_t mouse_m908::_mouse_vid = 0x04d9; +const uint16_t mouse_m908::_mouse_pid = 0xfc4d; +//setting min and max values +const uint8_t mouse_m908::_scrollspeed_min = 0x01, mouse_m908::_scrollspeed_max = 0x3f; +const uint8_t mouse_m908::_brightness_min = 0x01, mouse_m908::_brightness_max = 0x03; +const uint8_t mouse_m908::_speed_min = 0x01, mouse_m908::_speed_max = 0x08; +const uint8_t mouse_m908::_level_min = 0, mouse_m908::_level_max = 4; +const uint8_t mouse_m908::_dpi_min = 0x04, mouse_m908::_dpi_max = 0x8c; + +//name → keycode +std::map< std::string, std::array > mouse_m908::_keycodes = { + { "forward", { 0x85, 0x00, 0x00 } }, + { "backward", { 0x84, 0x00, 0x00 } }, + { "dpi+", { 0x8a, 0x00, 0x00 } }, + { "dpi-", { 0x89, 0x00, 0x00 } }, + { "dpi-cycle", { 0x88, 0x00, 0x00 } }, + { "report_rate+", { 0x97, 0x00, 0x00 } }, + { "report_rate-", { 0x98, 0x00, 0x00 } }, + { "scroll_up", { 0x8b, 0x00, 0x00 } }, + { "scroll_down", { 0x8c, 0x00, 0x00 } }, + { "left", { 0x81, 0x00, 0x00 } }, + { "right", { 0x82, 0x00, 0x00 } }, + { "middle", { 0x83, 0x00, 0x00 } }, + { "profile_switch", { 0x8d, 0x00, 0x00 } }, + { "led_mode_switch", { 0x9b, 0x04, 0x00 } }, + { "macro1", { 0x91, 0x00, 0x01 } }, + { "macro2", { 0x91, 0x01, 0x01 } }, + { "macro3", { 0x91, 0x02, 0x01 } }, + { "macro4", { 0x91, 0x03, 0x01 } }, + { "macro5", { 0x91, 0x04, 0x01 } }, + { "macro6", { 0x91, 0x05, 0x01 } }, + { "macro7", { 0x91, 0x06, 0x01 } }, + { "macro8", { 0x91, 0x07, 0x01 } }, + { "macro9", { 0x91, 0x08, 0x01 } }, + { "macro10", { 0x91, 0x09, 0x01 } }, + { "macro11", { 0x91, 0x0a, 0x01 } }, + { "macro12", { 0x91, 0x0b, 0x01 } }, + { "macro13", { 0x91, 0x0c, 0x01 } }, + { "macro14", { 0x91, 0x0d, 0x01 } }, + { "macro15", { 0x91, 0x0e, 0x01 } }, + { "none", { 0x00, 0x00, 0x00 } }, + { "media_play", { 0x8e, 0x01, 0xcd } }, + { "media_stop", { 0x8e, 0x01, 0xb7 } }, + { "media_previous", { 0x8e, 0x01, 0xb6 } }, + { "media_next", { 0x8e, 0x01, 0xb5 } }, + { "media_volume_up", { 0x8e, 0x01, 0xe9 } }, + { "media_volume_down", { 0x8e, 0x01, 0xea } }, + { "media_mute", { 0x8e, 0x01, 0xe2 } } }; + +//modifier name → value +const std::map< std::string, uint8_t > mouse_m908::_keyboard_modifier_values = { + { "ctrl_l+", 1 }, + { "shift_l+", 2 }, + { "alt_l+", 4 }, + { "super_l+", 8 }, + { "ctrl_r+", 16 }, + { "shift_r+", 32 }, + { "alt_r+", 64 }, + { "super_r+", 128 } }; + +//keyboard key name → value +std::map< std::string, uint8_t > mouse_m908::_keyboard_key_values = { + //top row + { "Esc", 0x29 }, + { "F1", 0x3a }, + { "F2", 0x3b }, + { "F3", 0x3c }, + { "F4", 0x3d }, + { "F5", 0x3e }, + { "F6", 0x3f }, + { "F7", 0x40 }, + { "F8", 0x41 }, + { "F9", 0x42 }, + { "F10", 0x43 }, + { "F11", 0x44 }, + { "F12", 0x45 }, + { "PrtSc", 0x46 }, + { "ScrLk", 0x47 }, + { "Pause", 0x48 }, + //alphanumeric + { "a", 0x04 }, + { "b", 0x05 }, + { "c", 0x06 }, + { "d", 0x07 }, + { "e", 0x08 }, + { "f", 0x09 }, + { "g", 0x0a }, + { "h", 0x0b }, + { "i", 0x0c }, + { "j", 0x0d }, + { "k", 0x0e }, + { "l", 0x0f }, + { "m", 0x10 }, + { "n", 0x11 }, + { "o", 0x12 }, + { "p", 0x13 }, + { "q", 0x14 }, + { "r", 0x15 }, + { "s", 0x16 }, + { "t", 0x17 }, + { "u", 0x18 }, + { "v", 0x19 }, + { "w", 0x1a }, + { "x", 0x1b }, + { "y", 0x1c }, + { "z", 0x1d }, + { "1", 0x1e }, + { "2", 0x1f }, + { "3", 0x20 }, + { "4", 0x21 }, + { "5", 0x22 }, + { "6", 0x23 }, + { "7", 0x24 }, + { "8", 0x25 }, + { "9", 0x26 }, + { "0", 0x27 }, + //modifiers + { "Tab", 0x2b }, + { "Caps_Lock", 0x39 }, + { "Shift_l", 0xe1 }, + { "Ctrl_l", 0xe0 }, + { "Alt_l", 0xe2 }, + { "Super_l", 0xe3 }, + { "Super_r", 0xe7 }, + { "Alt_r", 0xe6 }, + { "Menu", 0x65 }, + { "Ctrl_r", 0xe4 }, + { "Shift_r", 0xe5 }, + { "Return", 0x28 }, + { "Backspace", 0x2a }, + { "Caps_Lock", 0x39 }, + //special characters + { "Space", 0x2b }, + { "Tilde", 0x35 }, + { "Minus", 0x2d }, + { "Equals", 0x2e }, + { "Bracket_l", 0x2f }, + { "Bracket_r", 0x30 }, + { "Backslash", 0x31 }, + { "Semicolon", 0x33 }, + { "Apostrophe", 0x34 }, + { "Comma", 0x36 }, + { "Period", 0x37 }, + { "Slash", 0x38 }, + { "Int_Key", 0x64 }, + //navigation + { "Right", 0x4f }, + { "Left", 0x50 }, + { "Down", 0x51 }, + { "Up", 0x52 }, + { "Insert", 0x49 }, + { "Home", 0x4a }, + { "PgUp", 0x4b }, + { "Delete", 0x4c }, + { "End", 0x4d }, + { "PgDown", 0x4e }, + //numpad + { "Num_Slash", 0x54 }, + { "Num_Asterisk", 0x55 }, + { "Num_Minus", 0x56 }, + { "Num_Plus", 0x57 }, + { "Num_Return", 0x58 }, + { "Num_1", 0x59 }, + { "Num_2", 0x5a }, + { "Num_3", 0x5b }, + { "Num_4", 0x5c }, + { "Num_5", 0x5d }, + { "Num_6", 0x5e }, + { "Num_7", 0x5f }, + { "Num_8", 0x60 }, + { "Num_9", 0x61 }, + { "Num_0", 0x62 }, + { "Num_Period", 0x63 }, + { "Num_Lock", 0x53 }, + //special keys + { "Lang1", 0x90 }, + { "Lang2", 0x91 }, + { "Lang3", 0x92 }, + { "Lang4", 0x93 }, + { "Lang5", 0x94 }, + { "Lang6", 0x95 }, + { "Lang7", 0x96 }, + { "Lang8", 0x97 }, + { "Lang9", 0x98 }, + { "F13", 0x68 }, + { "F14", 0x69 }, + { "F15", 0x6a }, + { "F16", 0x6b }, + { "F17", 0x6c }, + { "F18", 0x6d }, + { "F19", 0x6e }, + { "F20", 0x6f }, + { "F21", 0x70 }, + { "F22", 0x71 }, + { "F23", 0x72 }, + { "F24", 0x73 } }; + +//usb data packets uint8_t mouse_m908::_data_profile[6][16] = { {0x02, 0xf3, 0x2c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x02, 0xf1, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, diff --git a/include/mouse_m908.h b/include/mouse_m908.h index f54615b..c5057d8 100644 --- a/include/mouse_m908.h +++ b/include/mouse_m908.h @@ -53,6 +53,8 @@ class mouse_m908{ // constructor mouse_m908(); + + // enums /// The available profiles enum m908_profile{ @@ -83,22 +85,98 @@ class mouse_m908{ r_1000Hz }; + + //setter functions + /** Set the currently active profile + */ int set_profile( m908_profile profile ); + + /** Set the scrollspeed for the specified profile + * \see _scrollspeed_min + * \see _scrollspeed_max + * \return 0 if successful, 1 if out of bounds + */ int set_scrollspeed( m908_profile profile, uint8_t speed ); + + /** Set the led mode for the specified profile + * \see m908_lightmode + * \return 0 if successful + */ int set_lightmode( m908_profile profile, m908_lightmode lightmode ); + + /** Set the led color for the specified profile + * \param color color as {r, g, b} + * \return 0 if successful + */ int set_color( m908_profile profile, std::array color ); + + /** Set the led brightness for the specified profile + * \see _brightness_min + * \see _brightness_max + * \return 0 if successful, 1 if out of bounds + */ int set_brightness( m908_profile profile, uint8_t brightness ); + + /** Set the led animation speed for the specified profile + * \see _speed_min + * \see _speed_max + * \return 0 if successful, 1 if out of bounds + */ int set_speed( m908_profile profile, uint8_t speed ); + + /** Enables/Disables a dpi level for the specified profile + * \see _level_min + * \see _level_max + * \return 0 if successful, 1 if out of bounds + */ int set_dpi_enable( m908_profile profile, int level, bool enabled ); + + /** Set the value of a dpi level for the specified profile + * \see _dpi_min + * \see _dpi_max + * \see _level_min + * \see _level_max + * \return 0 if successful, 1 if out of bounds + */ int set_dpi( m908_profile profile, int level, uint8_t dpi ); + + /** Set a mapping for a button for the specified profile + * \param mapping 4 bytes for the usb data packets + * \return 0 if successful + */ int set_key_mapping( m908_profile profile, int key, std::array mapping ); + + /** Set a mapping for a button for the specified profile + * \param mapping button name (see keymap.md) + * \return 0 if successful, 1 if mapping is invalid + */ int set_key_mapping( m908_profile profile, int key, std::string mapping ); + + /** Set the USB poll rate for the specified profile + * \see m908_report_rate + * \return 0 if successful + */ int set_report_rate( m908_profile profile, m908_report_rate report_rate ); + + /** Load the macro from the specified file into the specified slot + * \param macro_number macro slot (1-15) + * \return 0 if successful + */ int set_macro( int macro_number, std::string file ); + + /** Set how many times the specified macro should be repeated + * \param macro_number macro slot (1-15) + * \return 0 if successful + */ int set_macro_repeat( int macro_number, uint8_t repeat ); + + /** Set whether to try to detach the kernel driver when opening the mouse + */ int set_detach_kernel_driver( bool detach_kernel_driver ); + + //getter functions m908_profile get_profile(); uint8_t get_scrollspeed( m908_profile profile ); @@ -111,6 +189,8 @@ class mouse_m908{ m908_report_rate get_report_rate( m908_profile profile ); uint8_t get_macro_repeat( int macro_number ); + + //writer functions (apply settings to mouse) /** Write the currently active profile to the mouse * \return 0 if successful @@ -132,6 +212,8 @@ class mouse_m908{ */ int write_macro_repeat( int macro_number ); + + //helper functions /** Init libusb and open the mouse by its USB VID and PID * \return 0 if successful @@ -154,13 +236,20 @@ class mouse_m908{ bool _detach_kernel_driver = true; //usb device vars - uint16_t _mouse_vid; - uint16_t _mouse_pid; + static const uint16_t _mouse_vid; + static const uint16_t _mouse_pid; libusb_device_handle* _handle; bool _detached_driver_0 = false; bool _detached_driver_1 = false; bool _detached_driver_2 = false; + //setting min and max values + static const uint8_t _scrollspeed_min, _scrollspeed_max; + static const uint8_t _brightness_min, _brightness_max; + static const uint8_t _speed_min, _speed_max; + static const uint8_t _level_min, _level_max; + static const uint8_t _dpi_min, _dpi_max; + //setting vars m908_profile _profile; std::array _scrollspeeds; @@ -175,27 +264,32 @@ class mouse_m908{ std::array, 15> _macro_data; std::array _macro_repeat; - //setting min and max values - uint8_t _scrollspeed_min, _scrollspeed_max; - uint8_t _brightness_min, _brightness_max; - uint8_t _speed_min, _speed_max; - uint8_t _level_min, _level_max; - uint8_t _dpi_min, _dpi_max; - //mapping of button names to values - std::map< std::string, std::array > _keycodes; - std::map< std::string, uint8_t > _keyboard_modifier_values; - std::map< std::string, uint8_t > _keyboard_key_values; + /// Values/keycodes of mouse buttons and special button functions + static std::map< std::string, std::array > _keycodes; + /// Values of keyboard modifiers + static const std::map< std::string, uint8_t > _keyboard_modifier_values; + /// Values/keycodes of keyboard keys + static std::map< std::string, uint8_t > _keyboard_key_values; //usb data packets + /// Used for changing the active profile static uint8_t _data_profile[6][16]; + /// Used for sending the settings, part 1/3 static uint8_t _data_settings_1[15][16]; + /// Used for sending the settings, part 2/3 static uint8_t _data_settings_2[64]; + /// Used for sending the settings, part 3/3 static uint8_t _data_settings_3[140][16]; + /// Used for sending a macro, part 1/3 static uint8_t _data_macros_1[16]; + /// Used for sending a macro, part 2/3 static uint8_t _data_macros_2[256]; + /// Used for sending a macro, part 3/3 static uint8_t _data_macros_3[16]; + /// Lookup table for used when specifying which slot to send a macro to static uint8_t _data_macros_codes[15][2]; + /// Used to send the number repeats for a macro static uint8_t _data_macros_repeat[16]; };