Move M913 and M686 keycodes to a new class

This commit is contained in:
dokutan 2022-01-04 17:39:16 +01:00
parent aa26e97806
commit 4ba501c093
12 changed files with 94 additions and 47 deletions

View file

@ -30,6 +30,8 @@ target_sources(mouse_m908
include/load_config.h
include/rd_mouse.cpp
include/rd_mouse.h
include/rd_mouse_wireless.cpp
include/rd_mouse_wireless.h
include/generic/constructor.cpp
include/generic/data.cpp
include/generic/getters.cpp

View file

@ -62,22 +62,6 @@ std::map< int, std::array<uint8_t, 3> > mouse_m686::_c_keyboard_key_buttons = {
{ 11, {0x02, 0x60, 0x87} }, // button_dpi_down
};
std::map< std::string, std::array<uint8_t, 4> > mouse_m686::_c_keycodes = {
{ "left", { 0x01, 0x01, 0x00, 0x53 } },
{ "right", { 0x01, 0x02, 0x00, 0x52 } },
{ "middle", { 0x01, 0x04, 0x00, 0x50 } },
{ "backward", { 0x01, 0x08, 0x00, 0x4c } },
{ "forward", { 0x01, 0x10, 0x00, 0x44 } },
{ "led_toggle", { 0x08, 0x00, 0x00, 0x4d } },
{ "report_rate", { 0x07, 0x00, 0x00, 0x4e } },
{ "dpi-", { 0x02, 0x03, 0x00, 0x50 } },
{ "dpi+", { 0x02, 0x02, 0x00, 0x51 } },
{ "dpi-cycle", { 0x02, 0x01, 0x00, 0x52 } },
{ "default", { 0x05, 0x00, 0x00, 0x50 } },
{ "none", { 0x00, 0x00, 0x00, 0x55 } },
{ "profile_switch", { 0x09, 0x00, 0x00, 0x4c } },
};
/* see documentation/m913-key-press.txt for a description of these packets, partially generated with:
#!/usr/bin/env julia
for i in [0:25;]

View file

@ -302,7 +302,7 @@ int mouse_m686::_i_decode_button_mapping( const std::array<uint8_t, 4>& bytes, s
std::stringstream mapping_stream;
// known keycode ?
for( auto keycode : _c_keycodes ){
for( auto keycode : rd_mouse_wireless::_c_keycodes ){
if(
bytes.at(0) == keycode.second.at(0) &&
bytes.at(1) == keycode.second.at(1) &&

View file

@ -20,6 +20,8 @@
#ifndef MOUSE_M686
#define MOUSE_M686
#include "../rd_mouse_wireless.h"
#include <libusb.h>
#include <map>
#include <array>
@ -54,7 +56,7 @@
* - \_s\_* for variables that describe the settings on the mouse
* - \_c\_* for constants like keycodes, USB data, minimum and maximum values, etc. (these are not neccessarily defined as const)
*/
class mouse_m686 : public rd_mouse{
class mouse_m686 : public rd_mouse, protected rd_mouse_wireless {
public:
@ -311,8 +313,6 @@ class mouse_m686 : public rd_mouse{
/// DPI → bytecode
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;

View file

@ -178,7 +178,7 @@ int mouse_m686::set_key_mapping( rd_profile profile, int key, std::string mappin
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"];
_s_keymap_data[rd_profile_to_m686_profile(profile)][key] = rd_mouse_wireless::_c_keycodes["default"];
// and additional packets are sent
_s_keyboard_key_packets.push_back(_c_keyboard_key_packets[mapping]);
@ -186,9 +186,9 @@ int mouse_m686::set_key_mapping( rd_profile profile, int key, std::string mappin
_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, ...
}else if( rd_mouse_wireless::_c_keycodes.find(mapping) != rd_mouse_wireless::_c_keycodes.end() ){ // mouse buttons, special functions, ...
_s_keymap_data[rd_profile_to_m686_profile(profile)][key] = _c_keycodes[mapping];
_s_keymap_data[rd_profile_to_m686_profile(profile)][key] = rd_mouse_wireless::_c_keycodes[mapping];
}

View file

@ -70,22 +70,6 @@ std::map< int, std::array<uint8_t, 3> > mouse_m913::_c_keyboard_key_buttons = {
{ 15, {0x02, 0xe0, 0x07} }, // button_12
};
std::map< std::string, std::array<uint8_t, 4> > mouse_m913::_c_keycodes = {
{ "left", { 0x01, 0x01, 0x00, 0x53 } },
{ "right", { 0x01, 0x02, 0x00, 0x52 } },
{ "middle", { 0x01, 0x04, 0x00, 0x50 } },
{ "backward", { 0x01, 0x08, 0x00, 0x4c } },
{ "forward", { 0x01, 0x10, 0x00, 0x44 } },
{ "led_toggle", { 0x08, 0x00, 0x00, 0x4d } },
{ "report_rate", { 0x07, 0x00, 0x00, 0x4e } },
{ "dpi-", { 0x02, 0x03, 0x00, 0x50 } },
{ "dpi+", { 0x02, 0x02, 0x00, 0x51 } },
{ "dpi-cycle", { 0x02, 0x01, 0x00, 0x52 } },
{ "default", { 0x05, 0x00, 0x00, 0x50 } },
{ "none", { 0x00, 0x00, 0x00, 0x55 } },
{ "profile_switch", { 0x09, 0x00, 0x00, 0x4c } },
};
/* see documentation/m913-key-press.txt for a description of these packets, partially generated with:
#!/usr/bin/env julia
for i in [0:25;]

View file

@ -302,7 +302,7 @@ int mouse_m913::_i_decode_button_mapping( const std::array<uint8_t, 4>& bytes, s
std::stringstream mapping_stream;
// known keycode ?
for( auto keycode : _c_keycodes ){
for( auto keycode : rd_mouse_wireless::_c_keycodes ){
if(
bytes.at(0) == keycode.second.at(0) &&
bytes.at(1) == keycode.second.at(1) &&

View file

@ -20,6 +20,8 @@
#ifndef MOUSE_M913
#define MOUSE_M913
#include "../rd_mouse_wireless.h"
#include <libusb.h>
#include <map>
#include <array>
@ -54,7 +56,7 @@
* - \_s\_* for variables that describe the settings on the mouse
* - \_c\_* for constants like keycodes, USB data, minimum and maximum values, etc. (these are not neccessarily defined as const)
*/
class mouse_m913 : public rd_mouse{
class mouse_m913 : public rd_mouse, protected rd_mouse_wireless {
public:
@ -311,8 +313,6 @@ class mouse_m913 : public rd_mouse{
/// DPI → bytecode
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;

View file

@ -178,7 +178,7 @@ int mouse_m913::set_key_mapping( rd_profile profile, int key, std::string mappin
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"];
_s_keymap_data[rd_profile_to_m913_profile(profile)][key] = rd_mouse_wireless::_c_keycodes["default"];
// and additional packets are sent
_s_keyboard_key_packets.push_back(_c_keyboard_key_packets[mapping]);
@ -186,9 +186,9 @@ int mouse_m913::set_key_mapping( rd_profile profile, int key, std::string mappin
_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, ...
}else if( rd_mouse_wireless::_c_keycodes.find(mapping) != rd_mouse_wireless::_c_keycodes.end() ){ // mouse buttons, special functions, ...
_s_keymap_data[rd_profile_to_m913_profile(profile)][key] = _c_keycodes[mapping];
_s_keymap_data[rd_profile_to_m913_profile(profile)][key] = rd_mouse_wireless::_c_keycodes[mapping];
}

View file

@ -0,0 +1,35 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#include "rd_mouse_wireless.h"
std::map< std::string, std::array<uint8_t, 4> > rd_mouse_wireless::_c_keycodes = {
{ "left", { 0x01, 0x01, 0x00, 0x53 } },
{ "right", { 0x01, 0x02, 0x00, 0x52 } },
{ "middle", { 0x01, 0x04, 0x00, 0x50 } },
{ "backward", { 0x01, 0x08, 0x00, 0x4c } },
{ "forward", { 0x01, 0x10, 0x00, 0x44 } },
{ "led_toggle", { 0x08, 0x00, 0x00, 0x4d } },
{ "report_rate", { 0x07, 0x00, 0x00, 0x4e } },
{ "dpi-", { 0x02, 0x03, 0x00, 0x50 } },
{ "dpi+", { 0x02, 0x02, 0x00, 0x51 } },
{ "dpi-cycle", { 0x02, 0x01, 0x00, 0x52 } },
{ "default", { 0x05, 0x00, 0x00, 0x50 } },
{ "none", { 0x00, 0x00, 0x00, 0x55 } },
{ "profile_switch", { 0x09, 0x00, 0x00, 0x4c } },
};

View file

@ -0,0 +1,39 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#ifndef RD_MOUSE_WIRELESS
#define RD_MOUSE_WIRELESS
#include <array>
#include <string>
#include <map>
#include <vector>
/**
* This class holds data that is shared between the wireless mice.
*/
class rd_mouse_wireless{
protected:
/// Values/keycodes of mouse buttons and special button functions
static std::map< std::string, std::array<uint8_t, 4> > _c_keycodes;
};
#endif

View file

@ -14,7 +14,7 @@ LIBS != pkg-config --libs libusb-1.0
VERSION_STRING = "\"3.2\""
# compile
build: m607 m686 m908 m709 m711 m715 m719 m721 m913 m990 m990chroma generic data_rd.o rd_mouse.o load_config.o mouse_m908.o
build: m607 m686 m908 m709 m711 m715 m719 m721 m913 m990 m990chroma generic data_rd.o rd_mouse.o rd_mouse_wireless.o load_config.o mouse_m908.o
$(CC) *.o -o mouse_m908 $(LIBS) $(CC_OPTIONS)
# copy all files to their correct location
@ -110,6 +110,9 @@ data_rd.o:
rd_mouse.o:
$(CC) -c include/rd_mouse.cpp $(CC_OPTIONS)
rd_mouse_wireless.o:
$(CC) -c include/rd_mouse_wireless.cpp $(CC_OPTIONS)
constructor_m607.o:
$(CC) -c include/m607/constructor.cpp $(CC_OPTIONS) -o constructor_m607.o