M686: Implement button mappings a-z

This commit is contained in:
dokutan 2022-01-03 16:45:18 +01:00
parent 010169acd2
commit 877310edf0
4 changed files with 73 additions and 41 deletions

View file

@ -45,25 +45,21 @@ std::map< int, std::string > mouse_m686::_c_button_names = {
{ 9, "ignore" },
{ 10, "button_dpi_up" },
{ 11, "button_dpi_down" },
/* first (wrong) attempt:
{ 0, "button_1" },
{ 1, "button_2" },
{ 2, "button_3" },
{ 3, "button_4" },
{ 4, "button_5" },
{ 5, "button_6" },
{ 6, "button_right" },
{ 7, "button_left" },
{ 8, "button_7" },
{ 9, "button_8" },
{ 10, "button_middle" },
{ 11, "button_fire" },
{ 12, "button_9" },
{ 13, "button_10" },
{ 14, "button_11" },
{ 15, "button_12" }
*/
};
std::map< int, std::array<uint8_t, 3> > mouse_m686::_c_keyboard_key_buttons = {
{ 0, {0x01, 0x00, 0xe8} }, // button_left
{ 1, {0x01, 0x20, 0xc8} }, // button_right
{ 2, {0x01, 0x40, 0xa8} }, // button_middle
{ 3, {0x00, 0x00, 0x00} }, // ignore/unused
{ 4, {0x02, 0x00, 0xe7} }, // button_side_1
{ 5, {0x01, 0x60, 0x88} }, // button_side_3
{ 6, {0x00, 0x00, 0x00} }, // ignore/unused
{ 7, {0x00, 0x00, 0x00} }, // ignore/unused
{ 8, {0x01, 0x80, 0x68} }, // button_side_2
{ 9, {0x00, 0x00, 0x00} }, // ignore/unused
{ 10, {0x02, 0x40, 0xa7} }, // button_dpi_up
{ 11, {0x02, 0x60, 0x87} }, // button_dpi_down
};
std::map< std::string, std::array<uint8_t, 4> > mouse_m686::_c_keycodes = {
@ -82,6 +78,41 @@ std::map< std::string, std::array<uint8_t, 4> > mouse_m686::_c_keycodes = {
{ "profile_switch", { 0x09, 0x00, 0x00, 0x4c } },
};
/* see documentation/m913-key-press.txt for a description of these packets, generated with:
#!/usr/bin/env julia
for i in [0:25;]
println("{ \"", Char('a'+i), "\", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x", string(4+i, base=16, pad=2), ", 0x00, 0x41, 0x", string(4+i, base=16, pad=2), ", 0x00, 0x", string(0x89 - 2*i, base=16, pad=2), ", 0x00, 0x00, 0x48} },")
end
*/
std::map< std::string, std::array<uint8_t, 17> > mouse_m686::_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} },
{ "c", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x06, 0x00, 0x41, 0x06, 0x00, 0x85, 0x00, 0x00, 0x48} },
{ "d", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x07, 0x00, 0x41, 0x07, 0x00, 0x83, 0x00, 0x00, 0x48} },
{ "e", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x08, 0x00, 0x41, 0x08, 0x00, 0x81, 0x00, 0x00, 0x48} },
{ "f", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x09, 0x00, 0x41, 0x09, 0x00, 0x7f, 0x00, 0x00, 0x48} },
{ "g", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x0a, 0x00, 0x41, 0x0a, 0x00, 0x7d, 0x00, 0x00, 0x48} },
{ "h", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x0b, 0x00, 0x41, 0x0b, 0x00, 0x7b, 0x00, 0x00, 0x48} },
{ "i", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x0c, 0x00, 0x41, 0x0c, 0x00, 0x79, 0x00, 0x00, 0x48} },
{ "j", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x0d, 0x00, 0x41, 0x0d, 0x00, 0x77, 0x00, 0x00, 0x48} },
{ "k", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x0e, 0x00, 0x41, 0x0e, 0x00, 0x75, 0x00, 0x00, 0x48} },
{ "l", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x0f, 0x00, 0x41, 0x0f, 0x00, 0x73, 0x00, 0x00, 0x48} },
{ "m", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x10, 0x00, 0x41, 0x10, 0x00, 0x71, 0x00, 0x00, 0x48} },
{ "n", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x11, 0x00, 0x41, 0x11, 0x00, 0x6f, 0x00, 0x00, 0x48} },
{ "o", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x12, 0x00, 0x41, 0x12, 0x00, 0x6d, 0x00, 0x00, 0x48} },
{ "p", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x13, 0x00, 0x41, 0x13, 0x00, 0x6b, 0x00, 0x00, 0x48} },
{ "q", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x14, 0x00, 0x41, 0x14, 0x00, 0x69, 0x00, 0x00, 0x48} },
{ "r", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x15, 0x00, 0x41, 0x15, 0x00, 0x67, 0x00, 0x00, 0x48} },
{ "s", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x16, 0x00, 0x41, 0x16, 0x00, 0x65, 0x00, 0x00, 0x48} },
{ "t", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x17, 0x00, 0x41, 0x17, 0x00, 0x63, 0x00, 0x00, 0x48} },
{ "u", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x18, 0x00, 0x41, 0x18, 0x00, 0x61, 0x00, 0x00, 0x48} },
{ "v", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x19, 0x00, 0x41, 0x19, 0x00, 0x5f, 0x00, 0x00, 0x48} },
{ "w", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x1a, 0x00, 0x41, 0x1a, 0x00, 0x5d, 0x00, 0x00, 0x48} },
{ "x", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x1b, 0x00, 0x41, 0x1b, 0x00, 0x5b, 0x00, 0x00, 0x48} },
{ "y", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x1c, 0x00, 0x41, 0x1c, 0x00, 0x59, 0x00, 0x00, 0x48} },
{ "z", {0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x1d, 0x00, 0x41, 0x1d, 0x00, 0x57, 0x00, 0x00, 0x48} },
};
// DPI → bytecode
std::map< int, std::array<uint8_t,3> > mouse_m686::_c_dpi_codes = {
{ 100, { 0x00, 0x00, 0x55 } }, // minimum DPI
@ -247,18 +278,6 @@ std::map< int, std::array<uint8_t,3> > mouse_m686::_c_dpi_codes = {
};
//usb data packets
uint8_t mouse_m686::_c_data_unknown_1[9][17] = {
{0x08, 0x07, 0x00, 0x01, 0x60, 0x08, 0x02, 0x81, 0x21, 0x00, 0x41, 0x21, 0x00, 0x4f, 0x00, 0x00, 0x88},
{0x08, 0x07, 0x00, 0x01, 0x80, 0x08, 0x02, 0x81, 0x22, 0x00, 0x41, 0x22, 0x00, 0x4d, 0x00, 0x00, 0x68},
{0x08, 0x07, 0x00, 0x01, 0xa0, 0x08, 0x02, 0x81, 0x23, 0x00, 0x41, 0x23, 0x00, 0x4b, 0x00, 0x00, 0x48},
{0x08, 0x07, 0x00, 0x02, 0x00, 0x08, 0x02, 0x81, 0x24, 0x00, 0x41, 0x24, 0x00, 0x49, 0x00, 0x00, 0xe7},
{0x08, 0x07, 0x00, 0x02, 0x20, 0x08, 0x02, 0x81, 0x25, 0x00, 0x41, 0x25, 0x00, 0x47, 0x00, 0x00, 0xc7},
{0x08, 0x07, 0x00, 0x02, 0x80, 0x08, 0x02, 0x81, 0x26, 0x00, 0x41, 0x26, 0x00, 0x45, 0x00, 0x00, 0x67},
{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, 0xe0, 0x08, 0x02, 0x81, 0x56, 0x00, 0x41, 0x56, 0x00, 0xe5, 0x00, 0x00, 0x07},
};
uint8_t mouse_m686::_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, 0x68, 0x08, 0x05, 0x00, 0x00, 0x50, 0x01, 0x08, 0x00, 0x4c, 0x00, 0x00, 0x2c},

View file

@ -313,6 +313,8 @@ class mouse_m686 : 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,10 +328,11 @@ class mouse_m686 : public rd_mouse{
std::array<std::array<std::array<uint8_t, 4>, 12>, 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
static uint8_t _c_data_unknown_1[9][17];
/// Packets to map buttons to keyboard keys
static std::map< std::string, std::array<uint8_t, 17> > _c_keyboard_key_packets;
/// button mapping
static uint8_t _c_data_button_mapping[8][17];
/// DPI values

View file

@ -174,9 +174,22 @@ int mouse_m686::set_key_mapping( rd_profile profile, int key, std::string mappin
// current assumption: only one profile
profile = rd_mouse::rd_profile::profile_1;
// the m686 uses different keycodes, therefore the decoding is done here
if( _c_keycodes.find(mapping) != _c_keycodes.end() ){
// the M686 uses different keycodes, therefore the decoding is done here
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_m686_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_m686_profile(profile)][key] = _c_keycodes[mapping];
}
return 0;

View file

@ -43,13 +43,10 @@ int mouse_m686::write_data(uint8_t data[][17], size_t rows){
int mouse_m686::write_button_mapping( m686_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]);