M913 improvements

This commit is contained in:
dokutan 2021-10-03 00:43:20 +02:00
parent b213752578
commit ad523ea2ad
7 changed files with 294 additions and 87 deletions

View file

@ -1,27 +1,39 @@
# Example configuration for the M913 mouse # Example configuration for the M913 mouse
# If a particular option is not specified a default value will be used # If a particular option is not specified a default value will be used
# Currently only one profile is supported # Two profiles are supported by the mouse, only profile1 is currently supported by this software
[profile1] [profile1]
# LED mode: off, static, breathing, rainbow (only off works)
lightmode=static
# LED color (doesnt' work)
color=00ff00
# LED brightness: 0-255 (doesn't work)
brightness=50
# DPI levels # DPI levels
# valid are 100-16000 in steps of 100 # valid are 100-16000 in steps of 100
dpi1=100 dpi1=100
dpi2=200 dpi2=3000
dpi3=300 dpi3=4000
dpi4=8000 dpi4=6000
dpi5=16000 dpi5=16000
# Enable or disable DPI levels
# On the M913 disabling a level will disable all higher levels as well.
# e.g. to disable dpi4 and dpi5 uncomment the next line
# dpi4_enable=0
# Button mapping # Button mapping
# currently supported: forward, back, left, middle, right, led_toggle, polling_rate, none # currently supported: forward, back, left, middle, right, led_toggle, polling_rate, none
button_left=left button_left=left
button_right=right button_right=right
button_middle=middle button_middle=middle
button_fire=left button_fire=left
button_1=left button_1=back
button_2=forward button_2=forward
button_3=led_toggle button_3=led_toggle
button_4=none button_4=left
button_5=none button_5=none
button_6=none button_6=none
button_7=none button_7=none
@ -30,3 +42,7 @@ button_9=none
button_10=none button_10=none
button_11=none button_11=none
button_12=none button_12=none
#Settings for the second profile (not implemented)
[profile2]

View file

@ -227,7 +227,7 @@ std::map< int, std::array<uint8_t,3> > mouse_m913::_c_dpi_codes = {
}; };
//usb data packets //usb data packets
uint8_t mouse_m913::_c_data_settings[29][17] = { uint8_t mouse_m913::_c_data_unknown_1[11][17] = {
{0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49}, {0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49},
{0x08, 0x07, 0x00, 0x01, 0x20, 0x08, 0x02, 0x80, 0x04, 0x00, 0x40, 0x04, 0x00, 0x8b, 0x00, 0x00, 0xc8}, {0x08, 0x07, 0x00, 0x01, 0x20, 0x08, 0x02, 0x80, 0x04, 0x00, 0x40, 0x04, 0x00, 0x8b, 0x00, 0x00, 0xc8},
{0x08, 0x07, 0x00, 0x01, 0x40, 0x08, 0x02, 0x81, 0x20, 0x00, 0x41, 0x20, 0x00, 0x51, 0x00, 0x00, 0xa8}, {0x08, 0x07, 0x00, 0x01, 0x40, 0x08, 0x02, 0x81, 0x20, 0x00, 0x41, 0x20, 0x00, 0x51, 0x00, 0x00, 0xa8},
@ -239,6 +239,9 @@ uint8_t mouse_m913::_c_data_settings[29][17] = {
{0x08, 0x07, 0x00, 0x02, 0xa0, 0x08, 0x02, 0x81, 0x27, 0x00, 0x41, 0x27, 0x00, 0x43, 0x00, 0x00, 0x47}, {0x08, 0x07, 0x00, 0x02, 0xa0, 0x08, 0x02, 0x81, 0x27, 0x00, 0x41, 0x27, 0x00, 0x43, 0x00, 0x00, 0x47},
{0x08, 0x07, 0x00, 0x02, 0xc0, 0x08, 0x02, 0x81, 0x57, 0x00, 0x41, 0x57, 0x00, 0xe3, 0x00, 0x00, 0x27}, {0x08, 0x07, 0x00, 0x02, 0xc0, 0x08, 0x02, 0x81, 0x57, 0x00, 0x41, 0x57, 0x00, 0xe3, 0x00, 0x00, 0x27},
{0x08, 0x07, 0x00, 0x02, 0xe0, 0x08, 0x02, 0x81, 0x56, 0x00, 0x41, 0x56, 0x00, 0xe5, 0x00, 0x00, 0x07}, {0x08, 0x07, 0x00, 0x02, 0xe0, 0x08, 0x02, 0x81, 0x56, 0x00, 0x41, 0x56, 0x00, 0xe5, 0x00, 0x00, 0x07},
};
uint8_t mouse_m913::_c_data_button_mapping[8][17] = {
{0x08, 0x07, 0x00, 0x00, 0x60, 0x08, 0x00, 0x00, 0x00, 0x55, 0x05, 0x00, 0x00, 0x50, 0x00, 0x00, 0x34}, {0x08, 0x07, 0x00, 0x00, 0x60, 0x08, 0x00, 0x00, 0x00, 0x55, 0x05, 0x00, 0x00, 0x50, 0x00, 0x00, 0x34},
{0x08, 0x07, 0x00, 0x00, 0x68, 0x08, 0x05, 0x00, 0x00, 0x50, 0x01, 0x08, 0x00, 0x4c, 0x00, 0x00, 0x2c}, {0x08, 0x07, 0x00, 0x00, 0x68, 0x08, 0x05, 0x00, 0x00, 0x50, 0x01, 0x08, 0x00, 0x4c, 0x00, 0x00, 0x2c},
{0x08, 0x07, 0x00, 0x00, 0x70, 0x08, 0x05, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x50, 0x00, 0x00, 0x24}, {0x08, 0x07, 0x00, 0x00, 0x70, 0x08, 0x05, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x50, 0x00, 0x00, 0x24},
@ -247,14 +250,39 @@ uint8_t mouse_m913::_c_data_settings[29][17] = {
{0x08, 0x07, 0x00, 0x00, 0x88, 0x08, 0x01, 0x04, 0x00, 0x50, 0x04, 0x14, 0x03, 0x3a, 0x00, 0x00, 0x0c}, {0x08, 0x07, 0x00, 0x00, 0x88, 0x08, 0x01, 0x04, 0x00, 0x50, 0x04, 0x14, 0x03, 0x3a, 0x00, 0x00, 0x0c},
{0x08, 0x07, 0x00, 0x00, 0x90, 0x08, 0x05, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x50, 0x00, 0x00, 0x04}, {0x08, 0x07, 0x00, 0x00, 0x90, 0x08, 0x05, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x50, 0x00, 0x00, 0x04},
{0x08, 0x07, 0x00, 0x00, 0x98, 0x08, 0x05, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x50, 0x00, 0x00, 0xfc}, {0x08, 0x07, 0x00, 0x00, 0x98, 0x08, 0x05, 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x50, 0x00, 0x00, 0xfc},
};
uint8_t mouse_m913::_c_data_dpi[4][17]= {
{0x08, 0x07, 0x00, 0x00, 0x0c, 0x08, 0x00, 0x00, 0x00, 0x55, 0x02, 0x02, 0x00, 0x51, 0x00, 0x00, 0x88}, {0x08, 0x07, 0x00, 0x00, 0x0c, 0x08, 0x00, 0x00, 0x00, 0x55, 0x02, 0x02, 0x00, 0x51, 0x00, 0x00, 0x88},
{0x08, 0x07, 0x00, 0x00, 0x14, 0x08, 0x03, 0x03, 0x00, 0x4f, 0x04, 0x04, 0x00, 0x4d, 0x00, 0x00, 0x80}, {0x08, 0x07, 0x00, 0x00, 0x14, 0x08, 0x03, 0x03, 0x00, 0x4f, 0x04, 0x04, 0x00, 0x4d, 0x00, 0x00, 0x80},
{0x08, 0x07, 0x00, 0x00, 0x1c, 0x04, 0x05, 0x05, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd1}, {0x08, 0x07, 0x00, 0x00, 0x1c, 0x04, 0x05, 0x05, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd1},
{0x08, 0x07, 0x00, 0x00, 0x02, 0x02, 0x05, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xed}, {0x08, 0x07, 0x00, 0x00, 0x02, 0x02, 0x05, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xed},
};
uint8_t mouse_m913::_c_data_unknown_2[3][17] = {
{0x08, 0x07, 0x00, 0x00, 0x2c, 0x08, 0xff, 0x00, 0x00, 0x56, 0x00, 0x00, 0xff, 0x56, 0x00, 0x00, 0x68}, {0x08, 0x07, 0x00, 0x00, 0x2c, 0x08, 0xff, 0x00, 0x00, 0x56, 0x00, 0x00, 0xff, 0x56, 0x00, 0x00, 0x68},
{0x08, 0x07, 0x00, 0x00, 0x34, 0x08, 0x00, 0xff, 0x00, 0x56, 0xff, 0xff, 0x00, 0x57, 0x00, 0x00, 0x60}, {0x08, 0x07, 0x00, 0x00, 0x34, 0x08, 0x00, 0xff, 0x00, 0x56, 0xff, 0xff, 0x00, 0x57, 0x00, 0x00, 0x60},
{0x08, 0x07, 0x00, 0x00, 0x3c, 0x04, 0xff, 0x55, 0x7d, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1}, {0x08, 0x07, 0x00, 0x00, 0x3c, 0x04, 0xff, 0x55, 0x7d, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1},
{0x08, 0x07, 0x00, 0x00, 0x54, 0x08, 0xff, 0x00, 0xff, 0x57, 0x03, 0x52, 0x80, 0xd5, 0x00, 0x00, 0xeb},
{0x08, 0x07, 0x00, 0x00, 0x5c, 0x02, 0x03, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93},
{0x08, 0x07, 0x00, 0x00, 0x00, 0x02, 0x02, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef}
}; };
uint8_t mouse_m913::_c_data_led_static[3][17] = {
{0x08, 0x07, 0x00, 0x00, 0x54, 0x08, 0xff, 0x00, 0x00, 0x57, 0x01, 0x54, 0xff, 0x56, 0x00, 0x00, 0xeb},
{0x08, 0x07, 0x00, 0x00, 0x00, 0x02, 0x02, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef},
{0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49},
};
uint8_t mouse_m913::_c_data_led_breathing[3][17] = {
{0x08, 0x07, 0x00, 0x00, 0x54, 0x08, 0xff, 0x00, 0x00, 0x57, 0x01, 0x54, 0xff, 0x56, 0x00, 0x00, 0xeb},
{0x08, 0x07, 0x00, 0x00, 0x5c, 0x02, 0x03, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93},
{0x08, 0x07, 0x00, 0x00, 0x00, 0x02, 0x01, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef},
};
uint8_t mouse_m913::_c_data_led_off[2][17] = {
{0x08, 0x07, 0x00, 0x00, 0x58, 0x02, 0x00, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97},
{0x08, 0x07, 0x00, 0x00, 0x00, 0x02, 0x01, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef},
};
uint8_t mouse_m913::_c_data_unknown_3[1][17] = {
//{0x08, 0x07, 0x00, 0x00, 0x5c, 0x02, 0x03, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93},
{0x08, 0x07, 0x00, 0x00, 0x00, 0x02, 0x02, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef},
};

View file

@ -27,7 +27,15 @@ uint8_t mouse_m913::get_scrollspeed( rd_profile profile ){
} }
mouse_m913::rd_lightmode mouse_m913::get_lightmode( rd_profile profile ){ mouse_m913::rd_lightmode mouse_m913::get_lightmode( rd_profile profile ){
return _s_lightmodes[profile]; mouse_m913::rd_lightmode l = mouse_m913::rd_lightmode::lightmode_static;
switch(_s_lightmodes[profile]){
case mouse_m913::m913_lightmode::lightmode_off: l = mouse_m913::rd_lightmode::lightmode_off; break;
case mouse_m913::m913_lightmode::lightmode_breathing: l = mouse_m913::rd_lightmode::lightmode_breathing; break;
case mouse_m913::m913_lightmode::lightmode_rainbow: l = mouse_m913::rd_lightmode::lightmode_rainbow; break;
default: l = mouse_m913::rd_lightmode::lightmode_static; break;
}
return l;
} }
void mouse_m913::get_color( rd_profile profile, std::array<uint8_t, 3> &color ){ void mouse_m913::get_color( rd_profile profile, std::array<uint8_t, 3> &color ){

View file

@ -188,7 +188,7 @@ int mouse_m913::print_settings( std::ostream& output ){
output << "# Configuration created by mouse_m913::print_settings().\n"; output << "# Configuration created by mouse_m913::print_settings().\n";
output << "# Currently active profile: " << _s_profile << "\n"; output << "# Currently active profile: " << _s_profile << "\n";
for( int i = 1; i < 6; i++ ){ for( int i = 1; i < 3; i++ ){
// section header // section header
output << "\n[profile" << i << "]\n"; output << "\n[profile" << i << "]\n";
@ -218,14 +218,6 @@ int mouse_m913::print_settings( std::ostream& output ){
output << "rainbow\n"; output << "rainbow\n";
else if( _s_lightmodes[i-1] == lightmode_static ) else if( _s_lightmodes[i-1] == lightmode_static )
output << "static\n"; output << "static\n";
else if( _s_lightmodes[i-1] == lightmode_wave )
output << "wave\n";
else if( _s_lightmodes[i-1] == lightmode_alternating )
output << "alternating\n";
else if( _s_lightmodes[i-1] == lightmode_reactive )
output << "reactive\n";
else if( _s_lightmodes[i-1] == lightmode_flashing )
output << "flashing\n";
else{ else{
output << "unknown, please report as bug\n"; output << "unknown, please report as bug\n";
} }

View file

@ -256,8 +256,31 @@ class mouse_m913 : public rd_mouse{
profile_2 = 1, profile_2 = 1,
}; };
/// The M913 has different light modes from the other mice
enum m913_lightmode{
lightmode_off,
lightmode_static,
lightmode_breathing,
lightmode_rainbow
};
uint8_t _c_brightness_min = 0x00;
uint8_t _c_brightness_max = 0xff;
/// Maps rd_profile to m913_profile /// Maps rd_profile to m913_profile
m913_profile rd_profile_to_m913_profile( rd_profile profile ); m913_profile rd_profile_to_m913_profile( rd_profile profile );
/// Write raw data
int write_data(uint8_t data[][17], size_t rows);
/// Write the button mapping to the mouse
int write_button_mapping( m913_profile profile );
/// Write the DPI settings to the mouse
int write_dpi_settings( m913_profile profile );
/// Write the LED settings to the mouse
int write_led_settings( m913_profile profile );
/// Names of the physical buttons /// Names of the physical buttons
static std::map< int, std::string > _c_button_names; static std::map< int, std::string > _c_button_names;
@ -280,7 +303,7 @@ class mouse_m913 : public rd_mouse{
//setting vars //setting vars
rd_profile _s_profile; rd_profile _s_profile;
std::array<uint8_t, 2> _s_scrollspeeds; std::array<uint8_t, 2> _s_scrollspeeds;
std::array<rd_lightmode, 2> _s_lightmodes; std::array<m913_lightmode, 2> _s_lightmodes;
std::array<std::array<uint8_t, 3>, 2> _s_colors; std::array<std::array<uint8_t, 3>, 2> _s_colors;
std::array<uint8_t, 2> _s_brightness_levels; std::array<uint8_t, 2> _s_brightness_levels;
std::array<uint8_t, 2> _s_speed_levels; std::array<uint8_t, 2> _s_speed_levels;
@ -291,8 +314,23 @@ class mouse_m913 : public rd_mouse{
std::array<std::array<uint8_t, 256>, 15> _s_macro_data; std::array<std::array<uint8_t, 256>, 15> _s_macro_data;
//usb data packets //usb data packets
/// Used for sending the settings /// Unknown function
static uint8_t _c_data_settings[29][17]; static uint8_t _c_data_unknown_1[11][17];
/// button mapping
static uint8_t _c_data_button_mapping[8][17];
/// DPI values
static uint8_t _c_data_dpi[4][17];
/// Unknown function
static uint8_t _c_data_unknown_2[3][17];
/// LED settings
static uint8_t _c_data_led_static[3][17];
/// LED settings
static uint8_t _c_data_led_breathing[3][17];
/// LED settings
static uint8_t _c_data_led_off[2][17];
/// Unknown function
static uint8_t _c_data_unknown_3[1][17];
}; };
#endif #endif

View file

@ -38,7 +38,15 @@ int mouse_m913::set_scrollspeed( rd_profile profile, uint8_t speed ){
} }
int mouse_m913::set_lightmode( rd_profile profile, rd_lightmode lightmode ){ int mouse_m913::set_lightmode( rd_profile profile, rd_lightmode lightmode ){
_s_lightmodes[rd_profile_to_m913_profile(profile)] = lightmode; mouse_m913::m913_lightmode l = mouse_m913::m913_lightmode::lightmode_static;
switch(lightmode){
case rd_mouse::rd_lightmode::lightmode_off: l = mouse_m913::m913_lightmode::lightmode_off; break;
case rd_mouse::rd_lightmode::lightmode_breathing: l = mouse_m913::m913_lightmode::lightmode_breathing; break;
case rd_mouse::rd_lightmode::lightmode_rainbow: l = mouse_m913::m913_lightmode::lightmode_rainbow; break;
default: l = mouse_m913::m913_lightmode::lightmode_static; break;
}
_s_lightmodes[rd_profile_to_m913_profile(profile)] = l;
return 0; return 0;
} }

View file

@ -20,80 +20,197 @@
//writer functions (apply changes to mouse) //writer functions (apply changes to mouse)
int mouse_m913::write_profile(){ int mouse_m913::write_profile(){
// missing data // missing data
throw std::string( "Profiles are not supported for the M913." ); throw std::string( "Changing profiles is not support for the M913, use the 'mode switch' button on the mouse instead." );
return 0; return 0;
} }
int mouse_m913::write_data(uint8_t data[][17], size_t rows){
int ret = 0;
uint8_t buffer_in[17];
for( size_t i = 0; i < rows; i++ ){
ret += libusb_control_transfer( _i_handle, 0x21, 0x09, 0x0308, 0x0001, data[i], 17, 1000 );
ret += libusb_interrupt_transfer( _i_handle, 0x82, buffer_in, 17, NULL, 1000 );
}
return ret;
}
int mouse_m913::write_button_mapping( m913_profile profile ){
int ret = 0;
// part 1 (unknown function)
size_t rows_1 = sizeof(_c_data_unknown_1) / sizeof(_c_data_unknown_1[0]);
uint8_t buffer_1[rows_1][17];
for( size_t i = 0; i < rows_1; i++ ){
std::copy(std::begin(_c_data_unknown_1[i]), std::end(_c_data_unknown_1[i]), std::begin(buffer_1[i]));
}
ret += write_data(buffer_1, rows_1);
// part 2 (button mapping)
size_t rows_2 = sizeof(_c_data_button_mapping) / sizeof(_c_data_button_mapping[0]);
uint8_t buffer_2[rows_2][17];
for( size_t i = 0; i < rows_2; i++ ){
std::copy(std::begin(_c_data_button_mapping[i]), std::end(_c_data_button_mapping[i]), std::begin(buffer_2[i]));
}
// two buttons per packet
for( int i=0; i<16; i+=2 ){
int j = i/2;
buffer_2[j][6] = _s_keymap_data[profile][i][0];
buffer_2[j][7] = _s_keymap_data[profile][i][1];
buffer_2[j][8] = _s_keymap_data[profile][i][2];
buffer_2[j][9] = _s_keymap_data[profile][i][3];
buffer_2[j][10] = _s_keymap_data[profile][i+1][0];
buffer_2[j][11] = _s_keymap_data[profile][i+1][1];
buffer_2[j][12] = _s_keymap_data[profile][i+1][2];
buffer_2[j][13] = _s_keymap_data[profile][i+1][3];
}
ret += write_data(buffer_2, rows_2);
return ret;
}
int mouse_m913::write_dpi_settings( m913_profile profile ){
int ret = 0;
// part 1 (DPI)
size_t rows_1 = sizeof(_c_data_dpi) / sizeof(_c_data_dpi[0]);
uint8_t buffer_1[rows_1][17];
for( size_t i = 0; i < rows_1; i++ ){
std::copy(std::begin(_c_data_dpi[i]), std::end(_c_data_dpi[i]), std::begin(buffer_1[i]));
}
// DPI level 1
buffer_1[0][6] = _s_dpi_levels[profile][0][0];
buffer_1[0][7] = _s_dpi_levels[profile][0][1];
buffer_1[0][9] = _s_dpi_levels[profile][0][2];
// DPI level 2
buffer_1[0][10] = _s_dpi_levels[profile][1][0];
buffer_1[0][11] = _s_dpi_levels[profile][1][1];
buffer_1[0][13] = _s_dpi_levels[profile][1][2];
// DPI level 3
buffer_1[1][6] = _s_dpi_levels[profile][2][0];
buffer_1[1][7] = _s_dpi_levels[profile][2][1];
buffer_1[1][9] = _s_dpi_levels[profile][2][2];
// DPI level 4
buffer_1[1][10] = _s_dpi_levels[profile][3][0];
buffer_1[1][11] = _s_dpi_levels[profile][3][1];
buffer_1[1][13] = _s_dpi_levels[profile][3][2];
// DPI level 5
buffer_1[2][6] = _s_dpi_levels[profile][4][0];
buffer_1[2][7] = _s_dpi_levels[profile][4][1];
buffer_1[2][9] = _s_dpi_levels[profile][4][2];
// enabled DPI levels
uint8_t enabled_dpi_levels_1 = 0x05;
uint8_t enabled_dpi_levels_2 = 0x50;
if(!_s_dpi_enabled.at(profile).at(4)){
enabled_dpi_levels_1 = 0x04;
enabled_dpi_levels_2 = 0x51;
}
if(!_s_dpi_enabled.at(profile).at(3)){
enabled_dpi_levels_1 = 0x03;
enabled_dpi_levels_2 = 0x52;
}
if(!_s_dpi_enabled.at(profile).at(2)){
enabled_dpi_levels_1 = 0x02;
enabled_dpi_levels_2 = 0x53;
}
if(!_s_dpi_enabled.at(profile).at(1)){
enabled_dpi_levels_1 = 0x01;
enabled_dpi_levels_2 = 0x54;
}
buffer_1[3][6] = enabled_dpi_levels_1;
buffer_1[3][7] = enabled_dpi_levels_2;
ret += write_data(buffer_1, rows_1);
// part 2 (unknown function)
size_t rows_2 = sizeof(_c_data_unknown_2) / sizeof(_c_data_unknown_2[0]);
uint8_t buffer_2[rows_2][17];
for( size_t i = 0; i < rows_2; i++ ){
std::copy(std::begin(_c_data_unknown_2[i]), std::end(_c_data_unknown_2[i]), std::begin(buffer_2[i]));
}
ret += write_data(buffer_2, rows_2);
return ret;
}
int mouse_m913::write_led_settings( m913_profile profile ){
int ret = 0;
if(_s_lightmodes.at(profile) == mouse_m913::m913_lightmode::lightmode_off){
// part 1 (LED settings)
size_t rows_1 = sizeof(_c_data_led_off) / sizeof(_c_data_led_off[0]);
uint8_t buffer_1[rows_1][17];
for( size_t i = 0; i < rows_1; i++ ){
std::copy(std::begin(_c_data_led_off[i]), std::end(_c_data_led_off[i]), std::begin(buffer_1[i]));
}
ret += write_data(buffer_1, rows_1);
}else if(_s_lightmodes.at(profile) == mouse_m913::m913_lightmode::lightmode_breathing){
// part 1 (LED settings)
size_t rows_1 = sizeof(_c_data_led_breathing) / sizeof(_c_data_led_breathing[0]);
uint8_t buffer_1[rows_1][17];
for( size_t i = 0; i < rows_1; i++ ){
std::copy(std::begin(_c_data_led_breathing[i]), std::end(_c_data_led_breathing[i]), std::begin(buffer_1[i]));
}
ret += write_data(buffer_1, rows_1);
}else{ // lightmode_static
// part 1 (LED settings)
size_t rows_1 = sizeof(_c_data_led_static) / sizeof(_c_data_led_static[0]);
uint8_t buffer_1[rows_1][17];
for( size_t i = 0; i < rows_1; i++ ){
std::copy(std::begin(_c_data_led_static[i]), std::end(_c_data_led_static[i]), std::begin(buffer_1[i]));
}
// TODO! fix
buffer_1[0][6] = _s_colors.at(profile).at(0);
buffer_1[0][7] = _s_colors.at(profile).at(1);
buffer_1[0][8] = _s_colors.at(profile).at(2);
buffer_1[0][12] = _s_brightness_levels[profile];
ret += write_data(buffer_1, rows_1);
}
/*
// part 2 (unknown function)
size_t rows_2 = sizeof(_c_data_unknown_3) / sizeof(_c_data_unknown_3[0]);
uint8_t buffer_2[rows_2][17];
for( size_t i = 0; i < rows_2; i++ ){
std::copy(std::begin(_c_data_unknown_3[i]), std::end(_c_data_unknown_3[i]), std::begin(buffer_2[i]));
}
ret += write_data(buffer_2, rows_2);
*/
return ret;
}
int mouse_m913::write_settings(){ int mouse_m913::write_settings(){
// return value // return value
int ret = 0; int ret = 0;
// prepare data ret += write_button_mapping(mouse_m913::m913_profile::profile_1);
int rows = sizeof(_c_data_settings) / sizeof(_c_data_settings[0]); ret += write_dpi_settings(mouse_m913::m913_profile::profile_1);
uint8_t buffer[rows][17]; ret += write_led_settings(mouse_m913::m913_profile::profile_1);
for( int i = 0; i < rows; i++ ){
std::copy(std::begin(_c_data_settings[i]), std::end(_c_data_settings[i]), std::begin(buffer[i]));
}
// TODO! modify buffer to include the actual settings // TODO! profile 2
// DPI level 1
buffer[19][6] = _s_dpi_levels[profile_1][0][0];
buffer[19][7] = _s_dpi_levels[profile_1][0][1];
buffer[19][9] = _s_dpi_levels[profile_1][0][2];
// DPI level 2
buffer[19][10] = _s_dpi_levels[profile_1][1][0];
buffer[19][11] = _s_dpi_levels[profile_1][1][1];
buffer[19][13] = _s_dpi_levels[profile_1][1][2];
// DPI level 3
buffer[20][6] = _s_dpi_levels[profile_1][2][0];
buffer[20][7] = _s_dpi_levels[profile_1][2][1];
buffer[20][9] = _s_dpi_levels[profile_1][2][2];
// DPI level 4
buffer[20][10] = _s_dpi_levels[profile_1][3][0];
buffer[20][11] = _s_dpi_levels[profile_1][3][1];
buffer[20][12] = _s_dpi_levels[profile_1][3][2];
// DPI level 5
buffer[21][6] = _s_dpi_levels[profile_1][4][0];
buffer[21][7] = _s_dpi_levels[profile_1][4][1];
buffer[21][9] = _s_dpi_levels[profile_1][4][2];
// button mapping, two buttons per packet
for( int i=0; i<16; i+=2 ){
int j = 11+(i/2);
buffer[j][6] = _s_keymap_data[profile_1][i][0];
buffer[j][7] = _s_keymap_data[profile_1][i][1];
buffer[j][8] = _s_keymap_data[profile_1][i][2];
buffer[j][9] = _s_keymap_data[profile_1][i][3];
buffer[j][10] = _s_keymap_data[profile_1][i+1][0];
buffer[j][11] = _s_keymap_data[profile_1][i+1][1];
buffer[j][12] = _s_keymap_data[profile_1][i+1][2];
buffer[j][13] = _s_keymap_data[profile_1][i+1][3];
}
// TODO! remove, print hexdump of buffer
/*
for( int i = 0; i < rows; i++ ){
std::cout << i << "\t: ";
for( int j=0; j < 17; j++ ){
std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)buffer[i][j] << " ";
}
std::cout << "\n";
}
*/
// send data
uint8_t buffer_in[17]; // holds the received data
int received; // how many bytes were actually received
for( int i = 0; i < rows; i++ ){
ret += libusb_control_transfer( _i_handle, 0x21, 0x09, 0x0308, 0x0001, buffer[i], 17, 1000 );
ret += libusb_interrupt_transfer( _i_handle, 0x82, buffer_in, 17, &received, 1000 );
}
return ret; return ret;
} }