Support actual DPI values for the M719

This commit is contained in:
dokutan 2021-04-04 22:08:52 +02:00
parent 6450bee328
commit 62e157280d
5 changed files with 135 additions and 9 deletions

View file

@ -25,15 +25,15 @@ dpi2_enable=1
dpi3_enable=1
dpi4_enable=1
dpi5_enable=0
# There is only one implemented format to specify the DPI:
# 1. raw bytecode: 0x[04-8c][00-01]
# Note: specifying the actual DPI is unsupported due to a lack of information
# There are two formats to specify the DPI:
# 1. actual DPI: 100-10000 (resolution is 100 (100-5000) or 200 (5200-10000))
# 2. raw bytecode: 0x[04-8c][00-01]
# Note: the older DPI format (04-8c) is no longer supported.
dpi1=0x0400
dpi2=0x1600
dpi3=0x2d00
dpi4=0x4300
dpi5=0x8c00
dpi1=200
dpi2=1000
dpi3=2000
dpi4=3000
dpi5=5000
# usb report rate (125, 250, 500, 1000) Hz
report_rate=500

View file

@ -41,6 +41,85 @@ std::map< int, std::string > mouse_m719::_c_button_names = {
{ 8, "scroll_up" },
{ 9, "scroll_down" } };
// Mapping of real DPI values to bytecode
std::map< unsigned int, std::array<uint8_t, 2> > mouse_m719::_c_dpi_codes = {
{ 100, {0x02, 0x00} },
{ 200, {0x04, 0x00} },
{ 300, {0x06, 0x00} },
{ 400, {0x08, 0x00} },
{ 500, {0x0b, 0x00} },
{ 600, {0x0d, 0x00} },
{ 700, {0x0f, 0x00} },
{ 800, {0x12, 0x00} },
{ 900, {0x14, 0x00} },
{ 1000, {0x16, 0x00} },
{ 1100, {0x19, 0x00} },
{ 1200, {0x1b, 0x00} },
{ 1300, {0x1d, 0x00} },
{ 1400, {0x20, 0x00} },
{ 1500, {0x22, 0x00} },
{ 1600, {0x24, 0x00} },
{ 1700, {0x27, 0x00} },
{ 1800, {0x29, 0x00} },
{ 1900, {0x2b, 0x00} },
{ 2000, {0x2e, 0x00} },
{ 2100, {0x30, 0x00} },
{ 2200, {0x32, 0x00} },
{ 2300, {0x34, 0x00} },
{ 2400, {0x37, 0x00} },
{ 2500, {0x39, 0x00} },
{ 2600, {0x3b, 0x00} },
{ 2700, {0x3e, 0x00} },
{ 2800, {0x40, 0x00} },
{ 2900, {0x42, 0x00} },
{ 3000, {0x45, 0x00} },
{ 3100, {0x47, 0x00} },
{ 3200, {0x49, 0x00} },
{ 3300, {0x4c, 0x00} },
{ 3400, {0x4e, 0x00} },
{ 3500, {0x50, 0x00} },
{ 3600, {0x53, 0x00} },
{ 3700, {0x55, 0x00} },
{ 3800, {0x57, 0x00} },
{ 3900, {0x5a, 0x00} },
{ 4000, {0x5c, 0x00} },
{ 4100, {0x5e, 0x00} },
{ 4200, {0x61, 0x00} },
{ 4300, {0x63, 0x00} },
{ 4400, {0x65, 0x00} },
{ 4500, {0x68, 0x00} },
{ 4600, {0x6a, 0x00} },
{ 4700, {0x6c, 0x00} },
{ 4800, {0x6f, 0x00} },
{ 4900, {0x71, 0x00} },
{ 5000, {0x73, 0x00} },
{ 5200, {0x3b, 0x01} },
{ 5400, {0x3e, 0x01} },
{ 5600, {0x40, 0x01} },
{ 5800, {0x42, 0x01} },
{ 6000, {0x45, 0x01} },
{ 6200, {0x47, 0x01} },
{ 6400, {0x49, 0x01} },
{ 6600, {0x4c, 0x01} },
{ 6800, {0x4e, 0x01} },
{ 7000, {0x50, 0x01} },
{ 7200, {0x53, 0x01} },
{ 7400, {0x55, 0x01} },
{ 7600, {0x57, 0x01} },
{ 7800, {0x5a, 0x01} },
{ 8000, {0x5c, 0x01} },
{ 8200, {0x5e, 0x01} },
{ 8400, {0x61, 0x01} },
{ 8600, {0x63, 0x01} },
{ 8800, {0x65, 0x01} },
{ 9000, {0x68, 0x01} },
{ 9200, {0x6a, 0x01} },
{ 9400, {0x6c, 0x01} },
{ 9600, {0x6f, 0x01} },
{ 9800, {0x71, 0x01} },
{ 10000, {0x73, 0x01} }
};
//usb data packets
uint8_t mouse_m719::_c_data_s_profile[6][16] = {
{0x02, 0xf3, 0x2c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},

View file

@ -156,3 +156,28 @@ int mouse_m719::print_settings( std::ostream& output ){
return 0;
}
int mouse_m719::_i_decode_dpi( std::array<uint8_t, 2>& 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_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];
conversion_stream << std::setfill(' ') << std::setw(0) << std::dec;
dpi_string = conversion_stream.str();
return 0;
}

View file

@ -259,6 +259,9 @@ class mouse_m719 : public rd_mouse{
/// Names of the physical buttons
static std::map< int, std::string > _c_button_names;
/// Mapping of real DPI values to bytecode
static std::map< unsigned int, std::array<uint8_t, 2> > _c_dpi_codes;
/// The model name
static const std::string _c_name;
@ -307,6 +310,12 @@ class mouse_m719 : public rd_mouse{
static uint8_t _c_data_read_2[85][64];
/// Used to read the settings, part 3/3
static uint8_t _c_data_read_3[46][16];
/** 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( std::array<uint8_t, 2>& dpi_bytes, std::string& dpi_string );
};
#endif

View file

@ -118,6 +118,19 @@ int mouse_m719::set_dpi( rd_profile profile, int level, std::string dpi ){
}
// check format: 1234 (real DPI)
else if( std::regex_match( dpi, std::regex("[[:digit:]]+") ) ){
if( _c_dpi_codes.find( std::stoi(dpi) ) != _c_dpi_codes.end() ){
_s_dpi_levels[profile][level][0] = _c_dpi_codes.at( std::stoi(dpi) )[0];
_s_dpi_levels[profile][level][1] = _c_dpi_codes.at( std::stoi(dpi) )[1];
return 0;
}
}
return 1;
}