Change internal DPI format for the M908
This commit is contained in:
parent
eb46cdfcf9
commit
63b5d8a9a6
10 changed files with 56 additions and 22 deletions
|
@ -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<uint8_t, 3> > rd_mouse::_c_keycodes = {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<uint8_t, 5> _s_brightness_levels;
|
||||
std::array<uint8_t, 5> _s_speed_levels;
|
||||
std::array<std::array<bool, 5>, 5> _s_dpi_enabled;
|
||||
std::array<std::array<uint8_t, 5>, 5> _s_dpi_levels;
|
||||
//std::array<std::array<uint8_t, 5>, 5> _s_dpi_levels; //TODO! remove
|
||||
std::array<std::array<std::array<uint8_t, 2>, 5>, 5> _s_dpi_levels;
|
||||
std::array<std::array<std::array<uint8_t, 4>, 20>, 5> _s_keymap_data;
|
||||
std::array<rd_report_rate, 5> _s_report_rates;
|
||||
std::array<std::array<uint8_t, 256>, 15> _s_macro_data;
|
||||
|
|
|
@ -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)];
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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<uint8_t, 4> mapping ){
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ); }
|
||||
|
|
Loading…
Reference in a new issue