2019-11-08 17:10:30 -07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-04-08 07:39:30 -06:00
|
|
|
#include "mouse_m908.h"
|
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
mouse_m908::rd_profile mouse_m908::get_profile(){
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_profile;
|
2019-11-08 17:10:30 -07:00
|
|
|
}
|
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
uint8_t mouse_m908::get_scrollspeed( rd_profile profile ){
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_scrollspeeds[profile];
|
2019-11-08 17:10:30 -07:00
|
|
|
}
|
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
mouse_m908::rd_lightmode mouse_m908::get_lightmode( rd_profile profile ){
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_lightmodes[profile];
|
2019-11-08 17:10:30 -07:00
|
|
|
}
|
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
void mouse_m908::get_color( rd_profile profile, std::array<uint8_t, 3> &color ){
|
2020-05-21 16:50:02 -06:00
|
|
|
color = _s_colors[profile];
|
2019-11-08 17:10:30 -07:00
|
|
|
}
|
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
uint8_t mouse_m908::get_brightness( rd_profile profile ){
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_brightness_levels[profile];
|
2019-11-08 17:10:30 -07:00
|
|
|
}
|
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
uint8_t mouse_m908::get_speed( rd_profile profile ){
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_speed_levels[profile];
|
2019-11-08 17:10:30 -07:00
|
|
|
}
|
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
bool mouse_m908::get_dpi_enable( rd_profile profile, int level ){
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_dpi_enabled[profile][level];
|
2019-11-08 17:10:30 -07:00
|
|
|
}
|
|
|
|
|
2020-09-21 13:16:14 -06:00
|
|
|
/*uint8_t mouse_m908::get_dpi( rd_profile profile, int level ){ TODO! rewrite
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_dpi_levels[profile][level];
|
2020-09-21 13:16:14 -06:00
|
|
|
}*/
|
2019-11-11 15:41:35 -07:00
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
mouse_m908::rd_report_rate mouse_m908::get_report_rate( rd_profile profile ){
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_report_rates[profile];
|
2019-11-11 15:41:35 -07:00
|
|
|
}
|
2019-12-12 19:02:46 -07:00
|
|
|
|
|
|
|
uint8_t mouse_m908::get_macro_repeat( int macro_number ){
|
|
|
|
|
|
|
|
//check if macro_number is valid
|
|
|
|
if( macro_number < 1 || macro_number > 15 ){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
return _s_macro_repeat[macro_number];
|
2019-12-12 19:02:46 -07:00
|
|
|
}
|
2020-05-11 11:02:26 -06:00
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
int mouse_m908::get_key_mapping_raw( mouse_m908::rd_profile profile, int key, std::array<uint8_t, 4>& mapping ){
|
2020-05-11 11:02:26 -06:00
|
|
|
|
2020-07-16 06:12:53 -06:00
|
|
|
// valid key ?
|
|
|
|
if( _c_button_names[key] == "" )
|
2020-05-11 11:02:26 -06:00
|
|
|
return 1;
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
mapping[0] = _s_keymap_data[profile][key][0];
|
|
|
|
mapping[1] = _s_keymap_data[profile][key][1];
|
|
|
|
mapping[2] = _s_keymap_data[profile][key][2];
|
|
|
|
mapping[3] = _s_keymap_data[profile][key][3];
|
2020-05-11 11:02:26 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-12 12:35:13 -06:00
|
|
|
int mouse_m908::get_key_mapping( mouse_m908::rd_profile profile, int key, std::string& mapping ){
|
2020-05-11 11:02:26 -06:00
|
|
|
|
2020-07-16 06:12:53 -06:00
|
|
|
// valid key ?
|
|
|
|
if( _c_button_names[key] == "" )
|
2020-05-11 11:02:26 -06:00
|
|
|
return 1;
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
uint8_t b1 = _s_keymap_data[profile][key][0];
|
|
|
|
uint8_t b2 = _s_keymap_data[profile][key][1];
|
|
|
|
uint8_t b3 = _s_keymap_data[profile][key][2];
|
|
|
|
uint8_t b4 = _s_keymap_data[profile][key][3];
|
2020-05-11 11:02:26 -06:00
|
|
|
bool found_name = false;
|
|
|
|
|
|
|
|
mapping = "";
|
|
|
|
|
|
|
|
// fire button
|
|
|
|
if( b1 == 0x99 ){
|
|
|
|
|
|
|
|
mapping += "fire:";
|
|
|
|
|
|
|
|
// button
|
|
|
|
if( b2 == 0x81 )
|
|
|
|
mapping += "mouse_left:";
|
|
|
|
else if( b2 == 0x82 )
|
|
|
|
mapping += "mouse_right:";
|
|
|
|
else if( b2 == 0x84 )
|
|
|
|
mapping += "mouse_middle:";
|
|
|
|
else{
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
// iterate over _c_keyboard_key_values
|
|
|
|
for( auto keycode : _c_keyboard_key_values ){
|
2020-05-11 11:02:26 -06:00
|
|
|
|
|
|
|
if( keycode.second == b2 ){
|
|
|
|
|
|
|
|
mapping += keycode.first;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
mapping += ":";
|
|
|
|
}
|
|
|
|
|
|
|
|
// repeats
|
|
|
|
mapping += std::to_string( (int)b3 ) + ":";
|
|
|
|
|
|
|
|
// delay
|
|
|
|
mapping += std::to_string( (int)b4 );
|
|
|
|
|
|
|
|
found_name = true;
|
|
|
|
|
|
|
|
// keyboard key
|
|
|
|
} else if( b1 == 0x90 ){
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
// iterate over _c_keyboard_key_values
|
|
|
|
for( auto keycode : _c_keyboard_key_values ){
|
2020-05-11 11:02:26 -06:00
|
|
|
|
|
|
|
if( keycode.second == b3 ){
|
|
|
|
|
|
|
|
mapping += keycode.first;
|
|
|
|
found_name = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// modifiers + keyboard key
|
|
|
|
} else if( b1 == 0x8f ){
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
// iterate over _c_keyboard_modifier_values
|
|
|
|
for( auto modifier : _c_keyboard_modifier_values ){
|
2020-05-11 11:02:26 -06:00
|
|
|
|
|
|
|
if( modifier.second & b2 ){
|
|
|
|
mapping += modifier.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
// iterate over _c_keyboard_key_values
|
|
|
|
for( auto keycode : _c_keyboard_key_values ){
|
2020-05-11 11:02:26 -06:00
|
|
|
|
|
|
|
if( keycode.second == b3 ){
|
|
|
|
|
|
|
|
mapping += keycode.first;
|
|
|
|
found_name = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else{ // mousebutton or special function ?
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
// iterate over _c_keycodes
|
|
|
|
for( auto keycode : _c_keycodes ){
|
2020-05-11 11:02:26 -06:00
|
|
|
|
|
|
|
if( keycode.second[0] == b1 &&
|
|
|
|
keycode.second[1] == b2 &&
|
|
|
|
keycode.second[2] == b3 ){
|
|
|
|
|
|
|
|
mapping += keycode.first;
|
|
|
|
found_name = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found_name ){
|
2020-05-11 13:29:19 -06:00
|
|
|
mapping += "unknown, please report as bug: (dec) ";
|
2020-05-11 11:02:26 -06:00
|
|
|
mapping += " " + std::to_string( (int)b1 ) + " ";
|
|
|
|
mapping += " " + std::to_string( (int)b2 ) + " ";
|
|
|
|
mapping += " " + std::to_string( (int)b3 ) + " ";
|
|
|
|
mapping += " " + std::to_string( (int)b4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-11 13:29:19 -06:00
|
|
|
|
|
|
|
int mouse_m908::get_macro_raw( int number, std::array<uint8_t, 256>& macro ){
|
|
|
|
|
|
|
|
//check if macro_number is valid
|
|
|
|
if( number < 1 || number > 15 )
|
|
|
|
return 1;
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
std::copy( _s_macro_data[number-1].begin(), _s_macro_data[number-1].end(), macro.begin() );
|
2020-05-11 13:29:19 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mouse_m908::get_macro( int number, std::string& macro ){
|
|
|
|
|
|
|
|
std::stringstream output;
|
|
|
|
|
|
|
|
// macro undefined?
|
2020-05-21 16:50:02 -06:00
|
|
|
if( _s_macro_data[number-1][8] == 0 && _s_macro_data[number-1][9] == 0 && _s_macro_data[number-1][10] == 0 )
|
2020-05-11 13:29:19 -06:00
|
|
|
return 0;
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
for( long unsigned int j = 8; j < _s_macro_data[number-1].size(); ){
|
2020-05-11 13:29:19 -06:00
|
|
|
|
|
|
|
// failsafe
|
2020-05-21 16:50:02 -06:00
|
|
|
if( j >= _s_macro_data[number-1].size() )
|
2020-05-11 13:29:19 -06:00
|
|
|
break;
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
if( _s_macro_data[number-1][j] == 0x81 ){ // mouse button down
|
2020-05-11 13:29:19 -06:00
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
if( _s_macro_data[number-1][j] == 0x01 )
|
2020-05-11 13:29:19 -06:00
|
|
|
output << "down\tmouse_left\n";
|
2020-05-21 16:50:02 -06:00
|
|
|
else if( _s_macro_data[number-1][j] == 0x02 )
|
2020-05-11 13:29:19 -06:00
|
|
|
output << "down\tmouse_right\n";
|
2020-05-21 16:50:02 -06:00
|
|
|
else if( _s_macro_data[number-1][j] == 0x04 )
|
2020-05-11 13:29:19 -06:00
|
|
|
output << "down\tmouse_middle\n";
|
|
|
|
else{
|
|
|
|
output << "unknown, please report as bug: ";
|
2020-05-21 16:50:02 -06:00
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+1] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+2];
|
2020-05-11 13:29:19 -06:00
|
|
|
output << std::dec << "\n";
|
|
|
|
}
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
} else if( _s_macro_data[number-1][j] == 0x01 ){ // mouse button up
|
2020-05-11 13:29:19 -06:00
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
if( _s_macro_data[number-1][j] == 0x01 )
|
2020-05-11 13:29:19 -06:00
|
|
|
output << "up\tmouse_left\n";
|
2020-05-21 16:50:02 -06:00
|
|
|
else if( _s_macro_data[number-1][j] == 0x02 )
|
2020-05-11 13:29:19 -06:00
|
|
|
output << "up\tmouse_right\n";
|
2020-05-21 16:50:02 -06:00
|
|
|
else if( _s_macro_data[number-1][j] == 0x04 )
|
2020-05-11 13:29:19 -06:00
|
|
|
output << "up\tmouse_middle\n";
|
|
|
|
else{
|
|
|
|
output << "unknown, please report as bug: ";
|
2020-05-21 16:50:02 -06:00
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+1] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+2];
|
2020-05-11 13:29:19 -06:00
|
|
|
output << std::dec << "\n";
|
|
|
|
}
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
} else if( _s_macro_data[number-1][j] == 0x84 ){ // keyboard key down
|
2020-05-11 13:29:19 -06:00
|
|
|
|
|
|
|
bool found_name = false;
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
// iterate over _c_keyboard_key_values
|
|
|
|
for( auto keycode : _c_keyboard_key_values ){
|
2020-05-11 13:29:19 -06:00
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
if( keycode.second == _s_macro_data[number-1][j+1] ){
|
2020-05-11 13:29:19 -06:00
|
|
|
|
|
|
|
output << "down\t" << keycode.first << "\n";
|
|
|
|
found_name = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found_name ){
|
|
|
|
output << "unknown, please report as bug: ";
|
2020-05-21 16:50:02 -06:00
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+1] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+2];
|
2020-05-11 13:29:19 -06:00
|
|
|
output << std::dec << "\n";
|
|
|
|
}
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
} else if( _s_macro_data[number-1][j] == 0x04 ){ // keyboard key up
|
2020-05-11 13:29:19 -06:00
|
|
|
|
|
|
|
bool found_name = false;
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
// iterate over _c_keyboard_key_values
|
|
|
|
for( auto keycode : _c_keyboard_key_values ){
|
2020-05-11 13:29:19 -06:00
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
if( keycode.second == _s_macro_data[number-1][j+1] ){
|
2020-05-11 13:29:19 -06:00
|
|
|
|
|
|
|
output << "up\t" << keycode.first << "\n";
|
|
|
|
found_name = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found_name ){
|
|
|
|
output << "unknown, please report as bug: ";
|
2020-05-21 16:50:02 -06:00
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+1] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+2];
|
2020-05-11 13:29:19 -06:00
|
|
|
output << std::dec << "\n";
|
|
|
|
}
|
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
} else if( _s_macro_data[number-1][j] == 0x06 ){ // delay
|
2020-05-11 13:29:19 -06:00
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
output << "delay\t" << (int)_s_macro_data[number-1][j+1] << "\n";
|
2020-05-11 13:29:19 -06:00
|
|
|
|
2020-05-21 16:50:02 -06:00
|
|
|
} else if( _s_macro_data[number-1][j] == 0x00 ){ // padding
|
2020-05-11 13:29:19 -06:00
|
|
|
|
|
|
|
j++;
|
|
|
|
|
|
|
|
} else{
|
|
|
|
output << "unknown, please report as bug: ";
|
2020-05-21 16:50:02 -06:00
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+1] << " ";
|
|
|
|
output << std::hex << (int)_s_macro_data[number-1][j+2];
|
2020-05-11 13:29:19 -06:00
|
|
|
output << std::dec << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// increment
|
|
|
|
j+=3;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
macro = output.str();
|
|
|
|
return 0;
|
|
|
|
}
|