Preprare M913 backend for multiple profiles
This commit is contained in:
parent
223b33f4cc
commit
b213752578
4 changed files with 42 additions and 29 deletions
|
@ -22,7 +22,7 @@
|
|||
mouse_m913::mouse_m913(){
|
||||
|
||||
//default settings
|
||||
_s_profile = profile_1;
|
||||
_s_profile = rd_mouse::rd_profile::profile_1;
|
||||
_s_scrollspeeds.fill( 0x01 );
|
||||
_s_lightmodes.fill( lightmode_static );
|
||||
_s_colors.fill( {0xff, 0xff, 0xff} );
|
||||
|
|
|
@ -20,6 +20,11 @@
|
|||
|
||||
//helper functions
|
||||
|
||||
// Maps rd_profile to m913_profile
|
||||
mouse_m913::m913_profile mouse_m913::rd_profile_to_m913_profile( rd_profile profile ){
|
||||
return profile == rd_mouse::rd_profile::profile_1 ? mouse_m913::m913_profile::profile_1 : mouse_m913::m913_profile::profile_2;
|
||||
}
|
||||
|
||||
//init libusb and open mouse
|
||||
int mouse_m913::open_mouse(){
|
||||
|
||||
|
|
|
@ -250,6 +250,14 @@ class mouse_m913 : public rd_mouse{
|
|||
std::map< int, std::string >& button_names(){ return _c_button_names; }
|
||||
|
||||
private:
|
||||
/// The M913 has only two profiles.
|
||||
enum m913_profile{
|
||||
profile_1 = 0,
|
||||
profile_2 = 1,
|
||||
};
|
||||
|
||||
/// Maps rd_profile to m913_profile
|
||||
m913_profile rd_profile_to_m913_profile( rd_profile profile );
|
||||
|
||||
/// Names of the physical buttons
|
||||
static std::map< int, std::string > _c_button_names;
|
||||
|
@ -271,15 +279,15 @@ class mouse_m913 : public rd_mouse{
|
|||
|
||||
//setting vars
|
||||
rd_profile _s_profile;
|
||||
std::array<uint8_t, 5> _s_scrollspeeds;
|
||||
std::array<rd_lightmode, 5> _s_lightmodes;
|
||||
std::array<std::array<uint8_t, 3>, 5> _s_colors;
|
||||
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<std::array<uint8_t, 3>, 5>, 5> _s_dpi_levels;
|
||||
std::array<std::array<std::array<uint8_t, 4>, 16>, 5> _s_keymap_data;
|
||||
std::array<rd_report_rate, 5> _s_report_rates;
|
||||
std::array<uint8_t, 2> _s_scrollspeeds;
|
||||
std::array<rd_lightmode, 2> _s_lightmodes;
|
||||
std::array<std::array<uint8_t, 3>, 2> _s_colors;
|
||||
std::array<uint8_t, 2> _s_brightness_levels;
|
||||
std::array<uint8_t, 2> _s_speed_levels;
|
||||
std::array<std::array<bool, 5>, 2> _s_dpi_enabled;
|
||||
std::array<std::array<std::array<uint8_t, 3>, 5>, 2> _s_dpi_levels;
|
||||
std::array<std::array<std::array<uint8_t, 4>, 16>, 2> _s_keymap_data;
|
||||
std::array<rd_report_rate, 2> _s_report_rates;
|
||||
std::array<std::array<uint8_t, 256>, 15> _s_macro_data;
|
||||
|
||||
//usb data packets
|
||||
|
|
|
@ -32,18 +32,18 @@ int mouse_m913::set_scrollspeed( rd_profile profile, uint8_t speed ){
|
|||
return 1;
|
||||
}
|
||||
|
||||
_s_scrollspeeds[profile] = speed;
|
||||
_s_scrollspeeds[rd_profile_to_m913_profile(profile)] = speed;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mouse_m913::set_lightmode( rd_profile profile, rd_lightmode lightmode ){
|
||||
_s_lightmodes[profile] = lightmode;
|
||||
_s_lightmodes[rd_profile_to_m913_profile(profile)] = lightmode;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mouse_m913::set_color( rd_profile profile, std::array<uint8_t, 3> color ){
|
||||
_s_colors[profile] = color;
|
||||
_s_colors[rd_profile_to_m913_profile(profile)] = color;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ int mouse_m913::set_brightness( rd_profile profile, uint8_t brightness ){
|
|||
return 1;
|
||||
}
|
||||
|
||||
_s_brightness_levels[profile] = brightness;
|
||||
_s_brightness_levels[rd_profile_to_m913_profile(profile)] = brightness;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ int mouse_m913::set_speed( rd_profile profile, uint8_t speed ){
|
|||
return 1;
|
||||
}
|
||||
|
||||
_s_speed_levels[profile] = speed;
|
||||
_s_speed_levels[rd_profile_to_m913_profile(profile)] = speed;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -76,19 +76,19 @@ int mouse_m913::set_dpi_enable( rd_profile profile, int level, bool enabled ){
|
|||
return 1;
|
||||
}
|
||||
|
||||
_s_dpi_enabled[profile][level] = enabled;
|
||||
_s_dpi_enabled[rd_profile_to_m913_profile(profile)][level] = enabled;
|
||||
|
||||
// check if at least one level enabled
|
||||
int sum = 0;
|
||||
for( int i = _c_level_min; i <= _c_level_max; i++ ){
|
||||
if( _s_dpi_enabled[profile][i] ){
|
||||
if( _s_dpi_enabled[rd_profile_to_m913_profile(profile)][i] ){
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
|
||||
// if no level enabled: reenable specified level
|
||||
if( sum == 0 ){
|
||||
_s_dpi_enabled[profile][level] = true;
|
||||
_s_dpi_enabled[rd_profile_to_m913_profile(profile)][level] = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ int mouse_m913::set_dpi( rd_profile profile, int level, std::string dpi ){
|
|||
return 1;
|
||||
|
||||
// current assumption: only one profile
|
||||
profile = profile_1;
|
||||
profile = rd_mouse::rd_profile::profile_1;
|
||||
|
||||
// check format: 0xABCD (raw bytes), TODO! enable or remove
|
||||
/*
|
||||
|
@ -128,7 +128,7 @@ int mouse_m913::set_dpi( rd_profile profile, int level, std::string dpi ){
|
|||
|
||||
if( _c_dpi_codes.find( std::stoi(dpi) ) != _c_dpi_codes.end() ){
|
||||
|
||||
_s_dpi_levels[profile][level] = _c_dpi_codes.at( std::stoi(dpi) );
|
||||
_s_dpi_levels[rd_profile_to_m913_profile(profile)][level] = _c_dpi_codes.at( std::stoi(dpi) );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -143,17 +143,17 @@ int mouse_m913::set_dpi( rd_profile profile, int level, std::array<uint8_t, 3> d
|
|||
return 1;
|
||||
|
||||
// current assumption: only one profile
|
||||
profile = profile_1;
|
||||
profile = rd_mouse::rd_profile::profile_1;
|
||||
|
||||
_s_dpi_levels[profile][level] = dpi;
|
||||
_s_dpi_levels[rd_profile_to_m913_profile(profile)][level] = dpi;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mouse_m913::set_key_mapping( rd_profile profile, int key, std::array<uint8_t, 4> mapping ){
|
||||
_s_keymap_data[profile][key][0] = mapping[0];
|
||||
_s_keymap_data[profile][key][1] = mapping[1];
|
||||
_s_keymap_data[profile][key][2] = mapping[2];
|
||||
_s_keymap_data[profile][key][3] = mapping[3];
|
||||
_s_keymap_data[rd_profile_to_m913_profile(profile)][key][0] = mapping[0];
|
||||
_s_keymap_data[rd_profile_to_m913_profile(profile)][key][1] = mapping[1];
|
||||
_s_keymap_data[rd_profile_to_m913_profile(profile)][key][2] = mapping[2];
|
||||
_s_keymap_data[rd_profile_to_m913_profile(profile)][key][3] = mapping[3];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -164,18 +164,18 @@ int mouse_m913::set_key_mapping( rd_profile profile, int key, std::string mappin
|
|||
return 1;
|
||||
|
||||
// current assumption: only one profile
|
||||
profile = profile_1;
|
||||
profile = rd_mouse::rd_profile::profile_1;
|
||||
|
||||
// the M913 uses different keycodes, therefore the decoding is done here
|
||||
if( _c_keycodes.find(mapping) != _c_keycodes.end() ){
|
||||
_s_keymap_data[profile][key] = _c_keycodes[mapping];
|
||||
_s_keymap_data[rd_profile_to_m913_profile(profile)][key] = _c_keycodes[mapping];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mouse_m913::set_report_rate( rd_profile profile, rd_report_rate report_rate ){
|
||||
_s_report_rates[profile] = report_rate;
|
||||
_s_report_rates[rd_profile_to_m913_profile(profile)] = report_rate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue