M913: Preparations for mapping buttons as keyboard keys

This commit is contained in:
dokutan 2022-01-03 04:47:47 +01:00
parent 6904db4595
commit a1fac5dba1
5 changed files with 49 additions and 9 deletions

View file

@ -51,6 +51,25 @@ std::map< int, std::string > mouse_m913::_c_button_names = {
{ 15, "button_12" }
};
std::map< int, std::array<uint8_t, 3> > mouse_m913::_c_keyboard_key_buttons = {
{ 0, {0xff, 0xff, 0xff} }, // button_1 TODO!
{ 1, {0xff, 0xff, 0xff} }, // button_2 TODO!
{ 2, {0xff, 0xff, 0xff} }, // button_3 TODO!
{ 3, {0xff, 0xff, 0xff} }, // button_4 TODO!
{ 4, {0xff, 0xff, 0xff} }, // button_5 TODO!
{ 5, {0x01, 0xa0, 0x48} }, // button_6
{ 6, {0xff, 0xff, 0xff} }, // button_right TODO!
{ 7, {0xff, 0xff, 0xff} }, // button_left TODO!
{ 8, {0x02, 0x00, 0xe7} }, // button_7
{ 9, {0xff, 0xff, 0xff} }, // button_8 TODO!
{ 10, {0xff, 0xff, 0xff} }, // button_middle TODO!
{ 11, {0xff, 0xff, 0xff} }, // button_fire TODO!
{ 12, {0xff, 0xff, 0xff} }, // button_9 TODO!
{ 13, {0xff, 0xff, 0xff} }, // button_10 TODO!
{ 14, {0xff, 0xff, 0xff} }, // button_11 TODO!
{ 15, {0xff, 0xff, 0xff} }, // button_12 TODO!
};
std::map< std::string, std::array<uint8_t, 4> > mouse_m913::_c_keycodes = {
{ "left", { 0x01, 0x01, 0x00, 0x53 } },
{ "right", { 0x01, 0x02, 0x00, 0x52 } },
@ -67,6 +86,12 @@ std::map< std::string, std::array<uint8_t, 4> > mouse_m913::_c_keycodes = {
{ "profile_switch", { 0x09, 0x00, 0x00, 0x4c } },
};
// see documentation/m913-key-press.txt for a description of these packets
std::map< std::string, std::array<uint8_t, 17> > mouse_m913::_c_keyboard_key_packets = {
{ "a", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x04, 0x00, 0x41, 0x04, 0x00, 0x89, 0x00, 0x00, 0x48} },
{ "b", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x05, 0x00, 0x41, 0x05, 0x00, 0x87, 0x00, 0x00, 0x48} },
};
// DPI → bytecode
std::map< int, std::array<uint8_t,3> > mouse_m913::_c_dpi_codes = {
{ 100, { 0x00, 0x00, 0x55 } }, // minimum DPI

View file

@ -313,6 +313,8 @@ class mouse_m913 : public rd_mouse{
static std::map< int, std::array<uint8_t,3> > _c_dpi_codes;
/// Values/keycodes of mouse buttons and special button functions
static std::map< std::string, std::array<uint8_t, 4> > _c_keycodes;
/// Used to identify buttons when mapping buttons to keyboard keys
static std::map< int, std::array<uint8_t, 3> > _c_keyboard_key_buttons;
//setting vars
rd_profile _s_profile;
@ -326,9 +328,12 @@ class mouse_m913 : public rd_mouse{
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;
std::vector<std::array<uint8_t, 17>> _s_keyboard_key_packets;
//usb data packets
/// Unknown function
/// Packets to map buttons to keyboard keys
static std::map< std::string, std::array<uint8_t, 17> > _c_keyboard_key_packets;
/// mapping buttons to keyboard keys TODO!: replace and remove
static uint8_t _c_data_unknown_1[9][17];
/// button mapping
static uint8_t _c_data_button_mapping[8][17];

View file

@ -175,8 +175,21 @@ int mouse_m913::set_key_mapping( rd_profile profile, int key, std::string mappin
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() ){
if( _c_keyboard_key_packets.find(mapping) != _c_keyboard_key_packets.end() ){ // keyboard key
// the button gets mapped as "default"
_s_keymap_data[rd_profile_to_m913_profile(profile)][key] = _c_keycodes["default"];
// and additional packets are sent
_s_keyboard_key_packets.push_back(_c_keyboard_key_packets[mapping]);
_s_keyboard_key_packets.back()[3] = _c_keyboard_key_buttons[key][0];
_s_keyboard_key_packets.back()[4] = _c_keyboard_key_buttons[key][1];
_s_keyboard_key_packets.back()[16] = _c_keyboard_key_buttons[key][2];
}else if( _c_keycodes.find(mapping) != _c_keycodes.end() ){ // mouse buttons, special functions, ...
_s_keymap_data[rd_profile_to_m913_profile(profile)][key] = _c_keycodes[mapping];
}
return 0;

View file

@ -43,13 +43,10 @@ int mouse_m913::write_data(uint8_t data[][17], size_t rows){
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]));
// part 1 (buttons mapped as keyboard keys)
for(size_t i = 0; i < _s_keyboard_key_packets.size(); i++){
ret += write_data((uint8_t (*)[17])_s_keyboard_key_packets[i].data(), 1);
}
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]);

View file

@ -98,7 +98,7 @@ rd_mouse::mouse_variant rd_mouse::detect( const std::string& mouse_name ){
if( m.has_vid_pid(vid, pid) && mouse_name == m.get_name() ){
// setting the vid/pid is required for mice woth multiple ids and is ignored by all other backends
// setting the vid/pid is required for mice with multiple ids and is ignored by all other backends
m.set_vid(vid);
m.set_pid(pid);