Skip to content

Commit

Permalink
Implement profile switching for the M601
Browse files Browse the repository at this point in the history
  • Loading branch information
dokutan committed Dec 14, 2023
1 parent 3a2675f commit 1ff258e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
8 changes: 0 additions & 8 deletions include/m601/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,3 @@ std::map< unsigned int, std::array<uint8_t, 2> > mouse_m601::_c_dpi_codes = {
};

//usb data packets
uint8_t mouse_m601::_c_data_s_profile[6][16] = {
{0x02, 0xf3, 0x2c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x02, 0xf1, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x02, 0xf1, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x02, 0xf1, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x02, 0xf1, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x02, 0xf1, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
};
4 changes: 1 addition & 3 deletions include/m601/mouse_m601.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ class mouse_m601 : public rd_mouse{
std::array<std::array<uint8_t, 256>, 15> _s_macro_data;
std::array<uint8_t, 15> _s_macro_repeat;

//usb data packets
/// Used for changing the active profile
static uint8_t _c_data_s_profile[6][16];
//usb data packets, TODO

/** 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.
Expand Down
9 changes: 7 additions & 2 deletions include/m601/setters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
//setter functions

int mouse_m601::set_profile( rd_profile profile ){
_s_profile = profile;
return 0;
if( profile == profile_1 || profile == profile_2 ){
_s_profile = profile;
return 0;
}else{
// The M601 has only two profiles
return 1;
}
}

// These setters do nothing and exist only for compatibility. Use load_settings() instead.
Expand Down
17 changes: 9 additions & 8 deletions include/m601/writers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,25 @@
int mouse_m601::write_profile(){

//prepare data
uint8_t buffer[6][16];
for( int i = 0; i < 6; i++ ){
std::copy(std::begin(_c_data_s_profile[i]), std::end(_c_data_s_profile[i]), std::begin(buffer[i]));
uint8_t buffer[6] = {0x05, 0x02, 0x01, 0x00, 0x00, 0x00};

//modify buffer to include specified profile
if( _s_profile == profile_1 ){
buffer[2] = 0x01;
}else if( _s_profile == profile_2 ){
buffer[2] = 0x02;
}

//modify buffer from default to include specified profile
buffer[0][8] = _s_profile;

//send data
for( int i = 0; i < 6; i++ ){
libusb_control_transfer( _i_handle, 0x21, 0x09, 0x0302, 0x0002, buffer[i], 16, 1000 );
libusb_control_transfer( _i_handle, 0x21, 0x09, 0x0305, 0x0001, buffer, 6, 1000 );
}

return 0;
}

int mouse_m601::write_settings(){

// TODO implement
return 0;
}

Expand Down

0 comments on commit 1ff258e

Please sign in to comment.