2016-08-03 20:46:46 +02:00
|
|
|
/****************************************************************************
|
2017-03-30 17:53:36 +02:00
|
|
|
* Copyright (C) 2016,2017 Maschell
|
2016-08-03 20:46:46 +02: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, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
2017-05-07 14:44:09 +02:00
|
|
|
#include "./ConfigValues.hpp"
|
2016-08-03 20:46:46 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2017-05-07 14:44:09 +02:00
|
|
|
|
2017-10-29 09:34:47 +01:00
|
|
|
#include <utils/logger.h>
|
2016-08-03 20:46:46 +02:00
|
|
|
|
|
|
|
ConfigValues *ConfigValues::instance = NULL;
|
|
|
|
|
2018-06-19 17:46:37 +02:00
|
|
|
ConfigValues::ConfigValues() {
|
2016-08-03 20:46:46 +02:00
|
|
|
InitValues();
|
|
|
|
}
|
|
|
|
|
2018-06-19 17:46:37 +02:00
|
|
|
ConfigValues::~ConfigValues() {
|
|
|
|
if(HID_DEBUG) {
|
|
|
|
DEBUG_FUNCTION_LINE("\n");
|
|
|
|
}
|
2016-08-03 20:46:46 +02:00
|
|
|
}
|
|
|
|
|
2018-06-20 15:07:15 +02:00
|
|
|
const uint8_t * ConfigValues::getValuesForPreset(std::map<std::string,const uint8_t*> values,std::string possibleValue) {
|
|
|
|
std::map<std::string,const uint8_t*>::iterator it;
|
2016-08-03 20:46:46 +02:00
|
|
|
it = values.find(possibleValue);
|
2018-06-19 17:46:37 +02:00
|
|
|
if (it != values.end()) {
|
2016-08-03 20:46:46 +02:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:07:15 +02:00
|
|
|
BOOL ConfigValues::setIfValueIsAControllerPresetEx(std::string value,int32_t slot,int32_t keyslot) {
|
2016-08-03 20:46:46 +02:00
|
|
|
if(setIfValueIsPreset(presetGCValues,value,slot,keyslot)) return true;
|
|
|
|
if(setIfValueIsPreset(presetDS3Values,value,slot,keyslot)) return true;
|
|
|
|
if(setIfValueIsPreset(presetDS4Values,value,slot,keyslot)) return true;
|
2017-03-30 17:53:36 +02:00
|
|
|
if(setIfValueIsPreset(presetXInputValues,value,slot,keyslot)) return true;
|
2017-04-23 12:18:36 +02:00
|
|
|
if(setIfValueIsPreset(presetSwitchProValues,value,slot,keyslot)) return true;
|
2016-08-03 20:46:46 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//We need this function here so we can use preset sticks.
|
2018-06-20 15:07:15 +02:00
|
|
|
BOOL ConfigValues::setIfValueIsPreset(std::map<std::string,const uint8_t*> values,std::string possibleValue,int32_t slot,int32_t keyslot) {
|
2018-06-19 17:46:37 +02:00
|
|
|
if(slot > gHIDMaxDevices || slot < 0 || keyslot < 0 || keyslot >= CONTRPS_MAX_VALUE) {
|
2017-03-30 17:53:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-20 15:07:15 +02:00
|
|
|
const uint8_t * values_ = NULL;
|
2016-08-03 20:46:46 +02:00
|
|
|
if( keyslot == CONTRPS_VPAD_BUTTON_L_STICK_X ||
|
2018-06-19 17:46:37 +02:00
|
|
|
keyslot == CONTRPS_VPAD_BUTTON_L_STICK_Y ||
|
|
|
|
keyslot == CONTRPS_VPAD_BUTTON_R_STICK_X ||
|
|
|
|
keyslot == CONTRPS_VPAD_BUTTON_R_STICK_Y) {
|
|
|
|
if(HID_DEBUG) {
|
|
|
|
DEBUG_FUNCTION_LINE("This may be a predefined stick %s\n",possibleValue.c_str());
|
|
|
|
}
|
|
|
|
if((values_ = ConfigValues::getValuesStickPreset(possibleValue)) != NULL) {
|
|
|
|
if(HID_DEBUG) {
|
|
|
|
DEBUG_FUNCTION_LINE("Found predefined stick!\n");
|
|
|
|
}
|
2016-08-03 20:46:46 +02:00
|
|
|
config_controller[slot][keyslot][0] = values_[STICK_CONF_BYTE]; //CONTRPS_VPAD_BUTTON_L_STICK_X
|
|
|
|
config_controller[slot][keyslot][1] = values_[STICK_CONF_DEFAULT];
|
|
|
|
config_controller[slot][keyslot+DEF_STICK_OFFSET_INVERT][0] = CONTROLLER_PATCHER_VALUE_SET; //CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT
|
|
|
|
config_controller[slot][keyslot+DEF_STICK_OFFSET_INVERT][1] = values_[STICK_CONF_INVERT];
|
|
|
|
config_controller[slot][keyslot+DEF_STICK_OFFSET_DEADZONE][0] = CONTROLLER_PATCHER_VALUE_SET; //CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE
|
|
|
|
config_controller[slot][keyslot+DEF_STICK_OFFSET_DEADZONE][1] = values_[STICK_CONF_DEADZONE];
|
|
|
|
config_controller[slot][keyslot+DEF_STICK_OFFSET_MINMAX][0] = values_[STICK_CONF_MIN]; //CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX
|
|
|
|
config_controller[slot][keyslot+DEF_STICK_OFFSET_MINMAX][1] = values_[STICK_CONF_MAX];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 17:46:37 +02:00
|
|
|
if((values_ = getValuesForPreset(values,possibleValue)) != NULL) {
|
2016-08-03 20:46:46 +02:00
|
|
|
config_controller[slot][keyslot][0] = values_[0];
|
|
|
|
config_controller[slot][keyslot][1] = values_[1];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-20 15:07:15 +02:00
|
|
|
int32_t ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string nameOfString) {
|
2016-08-03 20:46:46 +02:00
|
|
|
std::map<std::string,int>::iterator it;
|
|
|
|
it = values.find(nameOfString);
|
2018-06-19 17:46:37 +02:00
|
|
|
if (it != values.end()) {
|
|
|
|
return it->second;
|
2016-08-03 20:46:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Value not found
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:07:15 +02:00
|
|
|
int32_t ConfigValues::getPresetValueEx(std::string possibleString) {
|
|
|
|
int32_t rightValue = -1;
|
2018-06-19 17:46:37 +02:00
|
|
|
if((rightValue = getValueFromMap(gGamePadValuesToCONTRPSString,possibleString))!= -1) {
|
|
|
|
if(HID_DEBUG) {
|
|
|
|
DEBUG_FUNCTION_LINE("Used pre-defined VPAD_VALUE! \"%s\" is %d\n",possibleString.c_str(),rightValue);
|
|
|
|
}
|
|
|
|
} else if((rightValue = getValueFromMap(presetValues,possibleString))!= -1) {
|
|
|
|
if(HID_DEBUG) {
|
|
|
|
DEBUG_FUNCTION_LINE("Used pre-defined value! \"%s\" is %d\n",possibleString.c_str(),rightValue);
|
|
|
|
}
|
2016-08-03 20:46:46 +02:00
|
|
|
}
|
|
|
|
return rightValue;
|
|
|
|
}
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2018-06-20 15:07:15 +02:00
|
|
|
void ConfigValues::addDeviceNameEx(uint16_t vid,uint16_t pid,std::string value) {
|
2017-10-29 09:34:47 +01:00
|
|
|
deviceNames[StringTools::strfmt("%04X%04X",vid,pid).c_str()] = value;
|
2018-06-19 17:46:37 +02:00
|
|
|
}
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2018-06-20 15:07:15 +02:00
|
|
|
std::string ConfigValues::getStringByVIDPIDEx(uint16_t vid,uint16_t pid) {
|
2017-03-30 17:53:36 +02:00
|
|
|
std::string result = "";
|
|
|
|
std::map<std::string,std::string>::iterator it;
|
|
|
|
|
2017-10-29 09:34:47 +01:00
|
|
|
it = deviceNames.find(StringTools::strfmt("%04X%04X",vid,pid));
|
2018-06-19 17:46:37 +02:00
|
|
|
if (it != deviceNames.end()) {
|
2017-03-30 17:53:36 +02:00
|
|
|
result = it->second;
|
2018-06-19 17:46:37 +02:00
|
|
|
} else {
|
2017-10-29 09:34:47 +01:00
|
|
|
result = StringTools::strfmt("VID: 0x%04X\nPID: 0x%04X",vid,pid);
|
2017-03-30 17:53:36 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|