From 63b5d8a9a6c5eac1d0879bca04e1119487b0f4bb Mon Sep 17 00:00:00 2001 From: dokutan <54861821+dokutan@users.noreply.github.com> Date: Mon, 21 Sep 2020 21:16:14 +0200 Subject: [PATCH] Change internal DPI format for the M908 --- include/data.cpp | 1 + include/m908/constructor.cpp | 11 +++++++++-- include/m908/getters.cpp | 4 ++-- include/m908/helpers.cpp | 6 ++++-- include/m908/mouse_m908.h | 14 ++++++++------ include/m908/readers.cpp | 10 ++++++++-- include/m908/setters.cpp | 25 +++++++++++++++++++------ include/m908/writers.cpp | 4 ++-- include/rd_mouse.h | 1 + mouse_m908.cpp | 2 ++ 10 files changed, 56 insertions(+), 22 deletions(-) diff --git a/include/data.cpp b/include/data.cpp index b6a2ae8..7f93dc6 100644 --- a/include/data.cpp +++ b/include/data.cpp @@ -29,6 +29,7 @@ const uint8_t rd_mouse::_c_brightness_min = 0x01, rd_mouse::_c_brightness_max = const uint8_t rd_mouse::_c_speed_min = 0x01, rd_mouse::_c_speed_max = 0x08; const uint8_t rd_mouse::_c_level_min = 0, rd_mouse::_c_level_max = 4; const uint8_t rd_mouse::_c_dpi_min = 0x04, rd_mouse::_c_dpi_max = 0x8c; +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 = { diff --git a/include/m908/constructor.cpp b/include/m908/constructor.cpp index 56169b2..6071963 100644 --- a/include/m908/constructor.cpp +++ b/include/m908/constructor.cpp @@ -21,15 +21,19 @@ // Constructor, set the default settings mouse_m908::mouse_m908(){ - //default settings + // default settings _s_profile = profile_1; _s_scrollspeeds.fill( 0x01 ); _s_lightmodes.fill( lightmode_static ); _s_colors.fill( {0xff, 0xff, 0xff} ); _s_brightness_levels.fill( 0x03 ); _s_speed_levels.fill( 0x08 ); + + // dpi _s_dpi_enabled.fill( {true, true, true, true, true} ); - _s_dpi_levels.fill( {0x04, 0x16, 0x2d, 0x43, 0x8c} ); + _s_dpi_levels.fill( {{ {0x04, 0x00}, {0x16, 0x00}, {0x2d, 0x00}, {0x43, 0x00}, {0x8c, 0x00} }} ); + + // button mapping for( int i = 0; i < 5; i++ ){ for( int j = 0; j < 20; j++ ){ _s_keymap_data[i][j][0] = _c_data_settings_3[35+(20*i)+j][8]; @@ -38,7 +42,10 @@ mouse_m908::mouse_m908(){ _s_keymap_data[i][j][3] = _c_data_settings_3[35+(20*i)+j][11]; } } + _s_report_rates.fill( r_125Hz ); + + // macros int count = 0; for( auto &i : _s_macro_data ){ std::copy(std::begin(_c_data_macros_2), std::end(_c_data_macros_2), std::begin(i)); diff --git a/include/m908/getters.cpp b/include/m908/getters.cpp index 748eed0..9732163 100644 --- a/include/m908/getters.cpp +++ b/include/m908/getters.cpp @@ -46,9 +46,9 @@ bool mouse_m908::get_dpi_enable( rd_profile profile, int level ){ return _s_dpi_enabled[profile][level]; } -uint8_t mouse_m908::get_dpi( rd_profile profile, int level ){ +/*uint8_t mouse_m908::get_dpi( rd_profile profile, int level ){ TODO! rewrite return _s_dpi_levels[profile][level]; -} +}*/ mouse_m908::rd_report_rate mouse_m908::get_report_rate( rd_profile profile ){ return _s_report_rates[profile]; diff --git a/include/m908/helpers.cpp b/include/m908/helpers.cpp index a4bbe6f..8d04156 100644 --- a/include/m908/helpers.cpp +++ b/include/m908/helpers.cpp @@ -105,13 +105,15 @@ int mouse_m908::print_settings( std::ostream& output ){ output << "\n# DPI settings\n"; for( int j = 1; j < 6; j++ ){ - if( _s_dpi_enabled[i-1][j] ) + if( _s_dpi_enabled[i-1][j] ) // TODO! check if [j] → [j-1] output << "dpi" << j << "_enable=1\n"; else output << "dpi" << j << "_enable=0\n"; + // DPI value, TODO! lookup real value output << std::setfill('0') << std::setw(2) << std::hex; - output << "dpi" << j << "=" << (int)_s_dpi_levels[i-1][j-1] << "\n"; + output << "dpi" << j << "=0x"; + output << std::setw(2) << (int)_s_dpi_levels[i-1][j-1][0] << std::setw(2) << (int)_s_dpi_levels[i-1][j-1][1] << "\n"; output << std::setfill(' ') << std::setw(0) << std::dec; } diff --git a/include/m908/mouse_m908.h b/include/m908/mouse_m908.h index c74b372..1245359 100644 --- a/include/m908/mouse_m908.h +++ b/include/m908/mouse_m908.h @@ -112,9 +112,10 @@ class mouse_m908 : public rd_mouse{ * \see _c_dpi_max * \see _c_level_min * \see _c_level_max - * \return 0 if successful, 1 if out of bounds + * \return 0 if successful, 1 if out of bounds or invalid dpi */ - int set_dpi( rd_profile profile, int level, uint8_t dpi ); + int set_dpi( rd_profile profile, int level, std::string dpi ); + //int set_dpi( rd_profile profile, int level, uint8_t dpi ); //TODO! rewrite /** \brief Set a mapping for a button for the specified profile * \param mapping 4 bytes for the usb data packets @@ -168,7 +169,7 @@ class mouse_m908 : public rd_mouse{ /// Get dpi level enabled/disabled status of specified profile bool get_dpi_enable( rd_profile profile, int level ); /// Get dpi value of specified level and profile - uint8_t get_dpi( rd_profile profile, int level ); + //uint8_t get_dpi( rd_profile profile, int level ); //TODO! rewrite /// Get USB poll rate of specified profile rd_report_rate get_report_rate( rd_profile profile ); /// Get macro repeat number of specified profile @@ -201,7 +202,7 @@ class mouse_m908 : public rd_mouse{ /** \brief Write the settings (leds, button mapping, dpi, etc.) to the mouse * \return 0 if successful */ - int write_settings(); + int write_settings(); //TODO! /** \brief Write a macro to the mouse * \return 0 if successful @@ -232,7 +233,7 @@ class mouse_m908 : public rd_mouse{ int close_mouse(); /// Print the current configuration in .ini format to output - int print_settings( std::ostream& output ); + int print_settings( std::ostream& output ); //TODO! @@ -274,7 +275,8 @@ class mouse_m908 : public rd_mouse{ std::array _s_brightness_levels; std::array _s_speed_levels; std::array, 5> _s_dpi_enabled; - std::array, 5> _s_dpi_levels; + //std::array, 5> _s_dpi_levels; //TODO! remove + std::array, 5>, 5> _s_dpi_levels; std::array, 20>, 5> _s_keymap_data; std::array _s_report_rates; std::array, 15> _s_macro_data; diff --git a/include/m908/readers.cpp b/include/m908/readers.cpp index ee02b9f..5d79166 100644 --- a/include/m908/readers.cpp +++ b/include/m908/readers.cpp @@ -264,9 +264,14 @@ int mouse_m908::read_and_print_settings( std::ostream& output ){ output << "\n# DPI settings\n"; output << "# Active dpi level for this profile: " << (int)buffer_in2[i-1][8]+1 << "\n"; for( int j = 1; j < 6; j++ ){ + + // DPI enable output << "dpi" << j << "_enable=" << (int)buffer_in2[i-1][4+(6*j)] << "\n"; + + // DPI value, TODO! lookup real value output << std::setfill('0') << std::setw(2) << std::hex; - output << "dpi" << j << "=" << (int)buffer_in2[i-1][5+(6*j)] << "\n"; + output << "dpi" << j << "=0x"; + output << std::setw(2) << (int)buffer_in2[i-1][5+(6*j)] << std::setw(2) << (int)buffer_in2[i-1][6+(6*j)] << "\n"; output << std::setfill(' ') << std::setw(0) << std::dec; } @@ -572,7 +577,8 @@ int mouse_m908::read_settings(){ else _s_dpi_enabled[i-1][j-1] = false; - _s_dpi_levels[i-1][j-1] = buffer_in2[i-1][5+(6*j)]; + _s_dpi_levels[i-1][j-1][0] = buffer_in2[i-1][5+(6*j)]; + _s_dpi_levels[i-1][j-1][1] = buffer_in2[i-1][6+(6*j)]; } diff --git a/include/m908/setters.cpp b/include/m908/setters.cpp index 20e1d53..6fbea08 100644 --- a/include/m908/setters.cpp +++ b/include/m908/setters.cpp @@ -95,15 +95,28 @@ int mouse_m908::set_dpi_enable( rd_profile profile, int level, bool enabled ){ return 0; } -int mouse_m908::set_dpi( rd_profile profile, int level, uint8_t dpi ){ +int mouse_m908::set_dpi( rd_profile profile, int level, std::string dpi ){ - //check bounds - if( dpi < _c_dpi_min || dpi > _c_dpi_max ){ - return 1; + // check format: 0xABCD (raw bytes) + if( std::regex_match( dpi, std::regex("0x[[:xdigit:]]{4}") ) ){ + + uint8_t b0 = (uint8_t)stoi( dpi.substr(2,2), 0, 16 ); + uint8_t b1 = (uint8_t)stoi( dpi.substr(4,2), 0, 16 ); + + //check bounds + if( b0 < _c_dpi_min || b0 > _c_dpi_max || b1 < _c_dpi_2_min || b1 > _c_dpi_2_max ) + return 1; + + _s_dpi_levels[profile][level][0] = b0; + _s_dpi_levels[profile][level][1] = b1; + + return 0; + } - _s_dpi_levels[profile][level] = dpi; - return 0; + // TODO! format: real dpi values + + return 1; } int mouse_m908::set_key_mapping( rd_profile profile, int key, std::array mapping ){ diff --git a/include/m908/writers.cpp b/include/m908/writers.cpp index 5ed72c4..efc569b 100644 --- a/include/m908/writers.cpp +++ b/include/m908/writers.cpp @@ -120,7 +120,8 @@ int mouse_m908::write_settings(){ for( int i = 0; i < 5; i++ ){ for( int j = 0; j < 5; j++ ){ buffer3[7+(5*i)+j][8] = _s_dpi_enabled[j][i]; - buffer3[7+(5*i)+j][9] = _s_dpi_levels[j][i]; + buffer3[7+(5*i)+j][9] = _s_dpi_levels[j][i][0]; + buffer3[7+(5*i)+j][10] = _s_dpi_levels[j][i][1]; } } //key mapping @@ -130,7 +131,6 @@ int mouse_m908::write_settings(){ buffer3[35+(20*i)+j][9] = _s_keymap_data[i][j][1]; buffer3[35+(20*i)+j][10] = _s_keymap_data[i][j][2]; buffer3[35+(20*i)+j][11] = _s_keymap_data[i][j][3]; - //std::cout << (int)_s_keymap_data[i][j][0] << " " << (int)_s_keymap_data[i][j][1] << " " << (int)_s_keymap_data[i][j][2] << " " << (int)_s_keymap_data[i][j][3] << "\n"; } } //usb report rate diff --git a/include/rd_mouse.h b/include/rd_mouse.h index 5b5494f..89bf2bb 100644 --- a/include/rd_mouse.h +++ b/include/rd_mouse.h @@ -96,6 +96,7 @@ class rd_mouse{ static const uint8_t _c_speed_min, _c_speed_max; static const uint8_t _c_level_min, _c_level_max; static const uint8_t _c_dpi_min, _c_dpi_max; + static const uint8_t _c_dpi_2_min, _c_dpi_2_max; //mapping of button names to values /// Values/keycodes of mouse buttons and special button functions diff --git a/mouse_m908.cpp b/mouse_m908.cpp index 0475742..5908fdf 100644 --- a/mouse_m908.cpp +++ b/mouse_m908.cpp @@ -360,11 +360,13 @@ std::string string_dump, std::string string_read ){ if( pt.get("profile"+std::to_string(i)+".dpi4_enable", "") == "0" ){ m.set_dpi_enable( profile_lut[i-1], 3, false ); } if( pt.get("profile"+std::to_string(i)+".dpi5_enable", "") == "0" ){ m.set_dpi_enable( profile_lut[i-1], 4, false ); } + /* TODO! parse config if( pt.get("profile"+std::to_string(i)+".dpi1", "").length() != 0 ){ m.set_dpi( profile_lut[i-1], 0, (uint8_t)stoi( pt.get("profile"+std::to_string(i)+".dpi1", ""), 0, 16) ); } if( pt.get("profile"+std::to_string(i)+".dpi2", "").length() != 0 ){ m.set_dpi( profile_lut[i-1], 1, (uint8_t)stoi( pt.get("profile"+std::to_string(i)+".dpi2", ""), 0, 16) ); } if( pt.get("profile"+std::to_string(i)+".dpi3", "").length() != 0 ){ m.set_dpi( profile_lut[i-1], 2, (uint8_t)stoi( pt.get("profile"+std::to_string(i)+".dpi3", ""), 0, 16) ); } if( pt.get("profile"+std::to_string(i)+".dpi4", "").length() != 0 ){ m.set_dpi( profile_lut[i-1], 3, (uint8_t)stoi( pt.get("profile"+std::to_string(i)+".dpi4", ""), 0, 16) ); } if( pt.get("profile"+std::to_string(i)+".dpi5", "").length() != 0 ){ m.set_dpi( profile_lut[i-1], 4, (uint8_t)stoi( pt.get("profile"+std::to_string(i)+".dpi5", ""), 0, 16) ); } + */ if( pt.get("profile"+std::to_string(i)+".report_rate", "") == "125" ){ m.set_report_rate( profile_lut[i-1], mouse_m908::r_125Hz ); } if( pt.get("profile"+std::to_string(i)+".report_rate", "") == "250" ){ m.set_report_rate( profile_lut[i-1], mouse_m908::r_250Hz ); }