Skip to content

Commit

Permalink
Improved reading the settings from the M913
Browse files Browse the repository at this point in the history
  • Loading branch information
dokutan committed Oct 10, 2021
1 parent c2172dc commit dfedf80
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 20 deletions.
4 changes: 2 additions & 2 deletions examples/example_m913.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ button_fire=left
button_1=backward
button_2=forward
button_3=led_toggle
button_4=left
button_4=none
button_5=none
button_6=none
button_7=none
button_8=none
button_9=none
button_10=dpi+
button_10=none
button_11=none
button_12=none
27 changes: 26 additions & 1 deletion include/m913/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int mouse_m913::print_settings( std::ostream& output ){
output << "dpi" << j << "_enable=0\n";

// DPI value
std::array<uint8_t, 2> dpi_bytes = {_s_dpi_levels[i-1][j-1][0], _s_dpi_levels[i-1][j-1][1]};
std::array<uint8_t, 3> dpi_bytes = {_s_dpi_levels[i-1][j-1][0], _s_dpi_levels[i-1][j-1][1], _s_dpi_levels[i-1][j-1][2]};
std::string dpi_string = "";

if( _i_decode_dpi( dpi_bytes, dpi_string ) == 0 )
Expand Down Expand Up @@ -327,4 +327,29 @@ int mouse_m913::_i_decode_button_mapping( const std::array<uint8_t, 4>& bytes, s

mapping = mapping_stream.str();
return ret;
}

int mouse_m913::_i_decode_dpi( const std::array<uint8_t, 3>& 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_value.second[2] == dpi_bytes[2] ){
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] << std::setw(2) << (int)dpi_bytes[2];
conversion_stream << std::setfill(' ') << std::setw(0) << std::dec;

dpi_string = conversion_stream.str();

return 0;
}
6 changes: 6 additions & 0 deletions include/m913/mouse_m913.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ class mouse_m913 : public rd_mouse{
* \see _i_encode_button_mapping
*/
static int _i_decode_button_mapping( const std::array<uint8_t, 4>& bytes, std::string& mapping );

/** 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
*/
static int _i_decode_dpi( const std::array<uint8_t, 3>& dpi_bytes, std::string& dpi_string );

/// Names of the physical buttons
static std::map< int, std::string > _c_button_names;
Expand Down
51 changes: 34 additions & 17 deletions include/m913/readers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,37 @@ int mouse_m913::read_and_print_settings( std::ostream& output ){
<< "# This configuration can be send to the mouse with mouse_m908 -c.\n"
<< "# Note: this feature is incomplete for the M913.\n\n";

output << "# Currently active DPI level: " << (int)(buffer_in[2][6] + 1) << "\n";

output << "# USB polling rate: ";
output
<< "# The M913 has two profiles that can be switched using the 'mode switch' button on the bottom of the mouse.\n"
<< "# Reading the settings can only be done for the active profile, therefore only profile1 is used in this config.\n"
<< "[profile1]\n\n";

output << "report_rate=";
switch(buffer_in[4][6]){
case 0x1: output << "1000 Hz\n"; break;
case 0x2: output << "500 Hz\n"; break;
case 0x4: output << "250 Hz\n"; break;
case 0x8: output << "125 Hz\n"; break;
case 0x1: output << "1000\n"; break;
case 0x2: output << "500\n"; break;
case 0x4: output << "250\n"; break;
case 0x8: output << "125\n"; break;
default: output << "unknown\n"; break;
}

output << "\n[profile1]\n\n";
// DPI
output << "\n# DPI settings\n";
output << "# Currently active DPI level: " << (int)(buffer_in[2][6] + 1) << "\n";
std::string dpi = "";
_i_decode_dpi({buffer_in[5][8], buffer_in[5][9], buffer_in[5][11]}, dpi);
output << "dpi1=" << dpi << "\n";
_i_decode_dpi({buffer_in[5][12], buffer_in[5][13], buffer_in[5][15]}, dpi);
output << "dpi2=" << dpi << "\n";
_i_decode_dpi({buffer_in[6][6], buffer_in[6][7], buffer_in[6][9]}, dpi);
output << "dpi3=" << dpi << "\n";
_i_decode_dpi({buffer_in[6][10], buffer_in[6][11], buffer_in[6][13]}, dpi);
output << "dpi4=" << dpi << "\n";
_i_decode_dpi({buffer_in[6][14], buffer_in[6][15], buffer_in[7][7]}, dpi);
output << "dpi5=" << dpi << "\n";

// button mapping
output << "\n# Button mapping\n";
std::string mapping = "";

_i_decode_button_mapping({buffer_in[16][10], buffer_in[16][11], buffer_in[16][12], buffer_in[16][13]}, mapping);
Expand All @@ -86,20 +103,20 @@ int mouse_m913::read_and_print_settings( std::ostream& output ){
output << "button_2=" << mapping << "\n";
_i_decode_button_mapping({buffer_in[14][10], buffer_in[14][11], buffer_in[14][12], buffer_in[14][13]}, mapping);
output << "button_3=" << mapping << "\n";
mapping = "not yet implemented";
output << "button_4=" << mapping << "\n"; // ?

_i_decode_button_mapping({buffer_in[14][14], buffer_in[14][15], buffer_in[15][6], buffer_in[15][7]}, mapping);
output << "button_4=" << mapping << "\n";
_i_decode_button_mapping({buffer_in[15][8], buffer_in[15][9], buffer_in[15][10], buffer_in[15][11]}, mapping);
output << "button_5=" << mapping << "\n";

_i_decode_button_mapping({buffer_in[15][12], buffer_in[15][13], buffer_in[15][14], buffer_in[15][15]}, mapping);
output << "button_6=" << mapping << "\n";

_i_decode_button_mapping({buffer_in[16][14], buffer_in[16][15], buffer_in[17][6], buffer_in[17][7]}, mapping);
output << "button_7=" << mapping << "\n";

_i_decode_button_mapping({buffer_in[17][8], buffer_in[17][9], buffer_in[17][10], buffer_in[17][11]}, mapping);
output << "button_8=" << mapping << "\n";

_i_decode_button_mapping({buffer_in[18][10], buffer_in[18][11], buffer_in[18][12], buffer_in[18][13]}, mapping);
output << "button_9=" << mapping << "\n";

output << "button_10=" << mapping << "\n"; // ?
_i_decode_button_mapping({buffer_in[18][14], buffer_in[18][15], buffer_in[19][6], buffer_in[19][7]}, mapping);
output << "button_10=" << mapping << "\n";
_i_decode_button_mapping({buffer_in[19][8], buffer_in[19][9], buffer_in[19][10], buffer_in[19][11]}, mapping);
output << "button_11=" << mapping << "\n";
_i_decode_button_mapping({buffer_in[19][12], buffer_in[19][13], buffer_in[19][14], buffer_in[19][15]}, mapping);
Expand Down

0 comments on commit dfedf80

Please sign in to comment.