Skip to content

Commit

Permalink
Allow to modify the strength of the FFB effects #359
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Laurendeau committed Sep 27, 2017
1 parent c9ce7b4 commit c2828c8
Show file tree
Hide file tree
Showing 21 changed files with 334 additions and 92 deletions.
57 changes: 54 additions & 3 deletions config/gimx-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,16 @@ const long configFrame::ID_STATICTEXT25 = wxNewId();
const long configFrame::ID_STATICTEXT49 = wxNewId();
const long configFrame::ID_BUTTON20 = wxNewId();
const long configFrame::ID_STATICLINE13 = wxNewId();
const long configFrame::ID_STATICTEXT31 = wxNewId();
const long configFrame::ID_STATICTEXT50 = wxNewId();
const long configFrame::ID_STATICTEXT29 = wxNewId();
const long configFrame::ID_STATICTEXT33 = wxNewId();
const long configFrame::ID_STATICTEXT48 = wxNewId();
const long configFrame::ID_CHECKBOX2 = wxNewId();
const long configFrame::ID_SPINCTRL4 = wxNewId();
const long configFrame::ID_SPINCTRL3 = wxNewId();
const long configFrame::ID_SPINCTRL2 = wxNewId();
const long configFrame::ID_SPINCTRL1 = wxNewId();
const long configFrame::ID_STATICLINE15 = wxNewId();
const long configFrame::ID_BUTTON24 = wxNewId();
const long configFrame::ID_PANEL8 = wxNewId();
Expand Down Expand Up @@ -971,10 +980,32 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu
FlexGridSizer54->Add(ForceFeedbackAutoDetect, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticLine13 = new wxStaticLine(PanelForceFeedback, ID_STATICLINE13, wxDefaultPosition, wxSize(-1,50), wxLI_VERTICAL, _T("ID_STATICLINE13"));
FlexGridSizer54->Add(StaticLine13, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer56 = new wxFlexGridSizer(1, 1, 0, 0);
FFBTweaksInvert = new wxCheckBox(PanelForceFeedback, ID_CHECKBOX2, _("Invert direction"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
FlexGridSizer56 = new wxFlexGridSizer(2, 5, 0, 0);
StaticText4 = new wxStaticText(PanelForceFeedback, ID_STATICTEXT31, _("Invert direction"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT31"));
FlexGridSizer56->Add(StaticText4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText5 = new wxStaticText(PanelForceFeedback, ID_STATICTEXT50, _("Rumble"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT50"));
FlexGridSizer56->Add(StaticText5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText10 = new wxStaticText(PanelForceFeedback, ID_STATICTEXT29, _("Constant"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT29"));
FlexGridSizer56->Add(StaticText10, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText16 = new wxStaticText(PanelForceFeedback, ID_STATICTEXT33, _("Spring"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT33"));
FlexGridSizer56->Add(StaticText16, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText19 = new wxStaticText(PanelForceFeedback, ID_STATICTEXT48, _("Damper"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT48"));
FlexGridSizer56->Add(StaticText19, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FFBTweaksInvert = new wxCheckBox(PanelForceFeedback, ID_CHECKBOX2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
FFBTweaksInvert->SetValue(false);
FlexGridSizer56->Add(FFBTweaksInvert, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FFBTweaksRumbleGain = new wxSpinCtrl(PanelForceFeedback, ID_SPINCTRL4, _T("100"), wxDefaultPosition, wxSize(55,-1), 0, -1000, 1000, 100, _T("ID_SPINCTRL4"));
FFBTweaksRumbleGain->SetValue(_T("100"));
FlexGridSizer56->Add(FFBTweaksRumbleGain, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FFBTweaksConstantGain = new wxSpinCtrl(PanelForceFeedback, ID_SPINCTRL3, _T("100"), wxDefaultPosition, wxSize(55,-1), 0, -1000, 1000, 100, _T("ID_SPINCTRL3"));
FFBTweaksConstantGain->SetValue(_T("100"));
FlexGridSizer56->Add(FFBTweaksConstantGain, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FFBTweaksSpringGain = new wxSpinCtrl(PanelForceFeedback, ID_SPINCTRL2, _T("100"), wxDefaultPosition, wxSize(55,-1), 0, -1000, 1000, 100, _T("ID_SPINCTRL2"));
FFBTweaksSpringGain->SetValue(_T("100"));
FlexGridSizer56->Add(FFBTweaksSpringGain, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FFBTweaksDamperGain = new wxSpinCtrl(PanelForceFeedback, ID_SPINCTRL1, _T("100"), wxDefaultPosition, wxSize(55,-1), 0, -1000, 1000, 100, _T("ID_SPINCTRL1"));
FFBTweaksDamperGain->SetValue(_T("100"));
FlexGridSizer56->Add(FFBTweaksDamperGain, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer54->Add(FlexGridSizer56, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticLine15 = new wxStaticLine(PanelForceFeedback, ID_STATICLINE15, wxDefaultPosition, wxSize(-1,50), wxLI_VERTICAL, _T("ID_STATICLINE15"));
FlexGridSizer54->Add(StaticLine15, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Expand Down Expand Up @@ -1306,7 +1337,6 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu
MenuAdvanced->Append(MenuItemWindowEvents);
MenuItemLinkControls = new wxMenuItem(MenuAdvanced, ID_MENUITEM25, _("Link controls"), wxEmptyString, wxITEM_CHECK);
MenuAdvanced->Append(MenuItemLinkControls);
MenuItemLinkControls->Check(true);
MenuAutoBindControls = new wxMenuItem(MenuAdvanced, ID_MENUITEM27, _("Auto-bind controls"), wxEmptyString, wxITEM_NORMAL);
MenuAdvanced->Append(MenuAutoBindControls);
MenuBar1->Append(MenuAdvanced, _("Advanced"));
Expand Down Expand Up @@ -2280,6 +2310,18 @@ void configFrame::save_current()
profile->GetForceFeedback()->GetJoystick()->SetName(ffbTweaksTabDeviceName);
profile->GetForceFeedback()->GetJoystick()->SetId(string(FFBTweaksId->GetLabel().mb_str(wxConvUTF8)));
profile->GetForceFeedback()->setInversion(FFBTweaksInvert->GetValue() ? "yes" : "no");
wxString rumble;
rumble << FFBTweaksRumbleGain->GetValue();
profile->GetForceFeedback()->setRumbleGain(string(rumble.mb_str(wxConvUTF8)));
wxString constant;
constant << FFBTweaksConstantGain->GetValue();
profile->GetForceFeedback()->setConstantGain(string(constant.mb_str(wxConvUTF8)));
wxString spring;
spring << FFBTweaksSpringGain->GetValue();
profile->GetForceFeedback()->setSpringGain(string(spring.mb_str(wxConvUTF8)));
wxString damper;
damper << FFBTweaksDamperGain->GetValue();
profile->GetForceFeedback()->setDamperGain(string(damper.mb_str(wxConvUTF8)));
//Save ControlMappers
buttonMappers = profile->GetButtonMapperList();
buttonMappers->erase(buttonMappers->begin(), buttonMappers->end());
Expand Down Expand Up @@ -2503,6 +2545,10 @@ void configFrame::load_current()
FFBTweaksName->SetLabel(wxString(name.c_str(),wxConvUTF8));
FFBTweaksId->SetLabel(wxString(tweaks->GetJoystick()->GetId().c_str(),wxConvUTF8));
FFBTweaksInvert->SetValue(tweaks->getInversion() == "yes");
FFBTweaksRumbleGain->SetValue(wxString(tweaks->getRumbleGain().c_str(),wxConvUTF8));
FFBTweaksConstantGain->SetValue(wxString(tweaks->getConstantGain().c_str(),wxConvUTF8));
FFBTweaksSpringGain->SetValue(wxString(tweaks->getSpringGain().c_str(),wxConvUTF8));
FFBTweaksDamperGain->SetValue(wxString(tweaks->getDamperGain().c_str(),wxConvUTF8));
//Load buttonMappers
clearGrid(GridPanelButton);
buttonMappers = profile->GetButtonMapperList();
Expand Down Expand Up @@ -4500,6 +4546,11 @@ void configFrame::OnButtonFFBTweaksDelete(wxCommandEvent& event __attribute__((u

FFBTweaksInvert->SetValue(false);

FFBTweaksRumbleGain->SetValue(_T("100"));
FFBTweaksConstantGain->SetValue(_T("100"));
FFBTweaksSpringGain->SetValue(_T("100"));
FFBTweaksDamperGain->SetValue(_T("100"));

refresh_gui();
}

Expand Down
22 changes: 20 additions & 2 deletions config/gimx-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,16 @@ class configFrame: public wxFrame
static const long ID_STATICTEXT49;
static const long ID_BUTTON20;
static const long ID_STATICLINE13;
static const long ID_STATICTEXT31;
static const long ID_STATICTEXT50;
static const long ID_STATICTEXT29;
static const long ID_STATICTEXT33;
static const long ID_STATICTEXT48;
static const long ID_CHECKBOX2;
static const long ID_SPINCTRL4;
static const long ID_SPINCTRL3;
static const long ID_SPINCTRL2;
static const long ID_SPINCTRL1;
static const long ID_STATICLINE15;
static const long ID_BUTTON24;
static const long ID_PANEL8;
Expand Down Expand Up @@ -352,6 +361,7 @@ class configFrame: public wxFrame
wxStaticLine* StaticLine1;
wxStaticText* ButtonTabEventId;
wxTextCtrl* AxisTabSensitivity;
wxSpinCtrl* FFBTweaksSpringGain;
wxStaticLine* StaticLine8;
wxMenuItem* MenuItemReplaceMouse;
wxChoice* IntensityDirection;
Expand Down Expand Up @@ -400,13 +410,15 @@ class configFrame: public wxFrame
wxGrid* GridJoystickCorrections;
wxMenu* MenuEdit;
wxStaticText* FFBTweaksType;
wxStaticText* StaticText16;
wxMenuItem* MenuProfile2;
wxPanel* PanelJoystickCorrections;
wxGrid* GridPanelAxis;
wxMenu* MenuFile;
wxPanel* PanelAxis;
wxStaticText* IntensityDeviceName;
wxStaticText* MouseOptionsName;
wxSpinCtrl* FFBTweaksConstantGain;
wxMenuItem* MenuItemDS4;
wxButton* IntensityAutoDetect;
wxPanel* PanelButton;
Expand All @@ -417,14 +429,15 @@ class configFrame: public wxFrame
wxStaticText* StaticTextLabel;
wxButton* Button5;
wxMenuItem* MenuItemSaveAs;
wxChoice* AxisTabShape;
wxMenuItem* MenuItemJs;
wxChoice* AxisTabShape;
wxStaticText* AxisTabEventId;
wxMenuItem* MenuController3;
wxStaticText* StaticTextEmptyPanelAxis;
wxStaticText* FFBTweaksAxis;
wxStaticText* StaticTextDZPanelAxis;
wxMenuItem* MenuItem2;
wxStaticText* StaticText4;
wxChoice* ButtonTabButtonId;
wxStaticText* StaticText8;
wxMenuItem* MenuItemXOne;
Expand All @@ -440,6 +453,7 @@ class configFrame: public wxFrame
wxMenuItem* MenuItemReplaceMouseDPI;
wxStaticLine* StaticLine6;
wxPanel* PanelMouseOptions;
wxStaticText* StaticText19;
wxStaticText* MouseOptionsType;
wxButton* Button7;
wxChoice* IntensityShape;
Expand All @@ -458,11 +472,12 @@ class configFrame: public wxFrame
wxTextCtrl* AxisTabAcceleration;
wxStaticText* ButtonTabDeviceType;
wxMenuItem* MenuItemSave;
wxMenuItem* MenuItemDfPs2;
wxMenuItem* MenuItemReplaceKeyboard;
wxMenuItem* MenuItemSetMouseDPI;
wxMenuItem* MenuItemDfPs2;
wxMenuItem* MenuProfile4;
wxButton* MouseOptionsModify;
wxSpinCtrl* FFBTweaksRumbleGain;
wxStaticText* MouseOptionsButton;
wxTextCtrl* JoystickCorrectionsHighValue;
wxMenuItem* MenuItemDS3;
Expand All @@ -484,10 +499,13 @@ class configFrame: public wxFrame
wxButton* JoystickCorrectionModify;
wxStaticText* StaticTextAccelPanelAxis;
wxStaticLine* StaticLine14;
wxStaticText* StaticText10;
wxTextCtrl* JoystickCorrectionsLowCoef;
wxStaticText* StaticText5;
wxStaticText* StaticTextDelayPanelOverall;
wxNotebook* Notebook1;
wxStaticLine* StaticLine15;
wxSpinCtrl* FFBTweaksDamperGain;
wxStaticText* StaticTextSensPanelAxis;
wxMenuItem* MenuController7;
wxButton* ButtonDelete;
Expand Down
89 changes: 85 additions & 4 deletions config/wxsmith/configframe.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,16 +1054,98 @@
</object>
<object class="sizeritem">
<object class="wxFlexGridSizer" variable="FlexGridSizer56" member="no">
<cols>1</cols>
<rows>1</rows>
<cols>5</cols>
<rows>2</rows>
<object class="sizeritem">
<object class="wxCheckBox" name="ID_CHECKBOX2" variable="FFBTweaksInvert" member="yes">
<object class="wxStaticText" name="ID_STATICTEXT31" variable="StaticText4" member="yes">
<label>Invert direction</label>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="ID_STATICTEXT50" variable="StaticText5" member="yes">
<label>Rumble</label>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="ID_STATICTEXT29" variable="StaticText10" member="yes">
<label>Constant</label>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="ID_STATICTEXT33" variable="StaticText16" member="yes">
<label>Spring</label>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="ID_STATICTEXT48" variable="StaticText19" member="yes">
<label>Damper</label>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxCheckBox" name="ID_CHECKBOX2" variable="FFBTweaksInvert" member="yes" />
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxSpinCtrl" name="ID_SPINCTRL4" variable="FFBTweaksRumbleGain" member="yes">
<value>100</value>
<min>-1000</min>
<max>1000</max>
<size>55,-1</size>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxSpinCtrl" name="ID_SPINCTRL3" variable="FFBTweaksConstantGain" member="yes">
<value>100</value>
<min>-1000</min>
<max>1000</max>
<size>55,-1</size>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxSpinCtrl" name="ID_SPINCTRL2" variable="FFBTweaksSpringGain" member="yes">
<value>100</value>
<min>-1000</min>
<max>1000</max>
<size>55,-1</size>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxSpinCtrl" name="ID_SPINCTRL1" variable="FFBTweaksDamperGain" member="yes">
<value>100</value>
<min>-1000</min>
<max>1000</max>
<size>55,-1</size>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
Expand Down Expand Up @@ -2008,7 +2090,6 @@
</object>
<object class="wxMenuItem" name="ID_MENUITEM25" variable="MenuItemLinkControls" member="yes">
<label>Link controls</label>
<checked>1</checked>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="ID_MENUITEM27" variable="MenuAutoBindControls" member="yes">
Expand Down
40 changes: 24 additions & 16 deletions core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "gimx.h"
#include "macros.h"
#include <controller.h>
#include "include/haptic/haptic_core.h"
#include "haptic/haptic_core.h"

#define DEFAULT_RADIUS 512
#define DEFAULT_VELOCITY 1
Expand Down Expand Up @@ -85,14 +85,18 @@ static s_mapper_table joystick_axes[MAX_DEVICES][MAX_CONTROLLERS][MAX_PROFILES];
/*
* FFB tweaks, for each controller and each profile.
*/
static s_ffb_tweaks ffb_tweaks[MAX_CONTROLLERS][MAX_PROFILES];
static s_haptic_core_tweaks ffb_tweaks[MAX_CONTROLLERS][MAX_PROFILES];

void cfg_set_ffb_tweaks(const s_config_entry * entry)
{
ffb_tweaks[entry->controller_id][entry->profile_id].invert = entry->params.ffb_tweaks.invert;
ffb_tweaks[entry->controller_id][entry->profile_id].gain.rumble = entry->params.ffb_tweaks.gain.rumble;
ffb_tweaks[entry->controller_id][entry->profile_id].gain.constant = entry->params.ffb_tweaks.gain.constant;
ffb_tweaks[entry->controller_id][entry->profile_id].gain.spring = entry->params.ffb_tweaks.gain.spring;
ffb_tweaks[entry->controller_id][entry->profile_id].gain.damper = entry->params.ffb_tweaks.gain.damper;
}

static inline const s_ffb_tweaks * cfg_get_ffb_tweaks(int controller)
const s_haptic_core_tweaks * cfg_get_ffb_tweaks(int controller)
{
return ffb_tweaks[controller] + cfg_controllers[controller].current->index;
}
Expand All @@ -105,6 +109,10 @@ void cfg_init_ffb_tweaks()
for (j = 0; j < MAX_PROFILES; ++j)
{
ffb_tweaks[i][j].invert = 0;
ffb_tweaks[i][j].gain.rumble = 100;
ffb_tweaks[i][j].gain.constant = 100;
ffb_tweaks[i][j].gain.spring = 100;
ffb_tweaks[i][j].gain.damper = 100;
}
}
}
Expand All @@ -115,29 +123,29 @@ static struct
s_js_corr * corr;
} js_corr[MAX_DEVICES] = {};

int cfg_add_js_corr(uint8_t device, s_js_corr * corr)
int cfg_add_js_corr(int joystick, s_js_corr * corr)
{
void * ptr = realloc(js_corr[device].corr, (js_corr[device].nb + 1) * sizeof(*(js_corr->corr)));
void * ptr = realloc(js_corr[joystick].corr, (js_corr[joystick].nb + 1) * sizeof(*(js_corr->corr)));
if(ptr == NULL)
{
gerror("%s:%d %s: realloc failed\n", __FILE__, __LINE__, __func__);
return -1;
}
js_corr[device].corr = ptr;
js_corr[device].corr[js_corr[device].nb].axis = corr->axis;
memcpy(js_corr[device].corr[js_corr[device].nb].coef, corr->coef, sizeof(corr->coef));
++(js_corr[device].nb);
js_corr[joystick].corr = ptr;
js_corr[joystick].corr[js_corr[joystick].nb].axis = corr->axis;
memcpy(js_corr[joystick].corr[js_corr[joystick].nb].coef, corr->coef, sizeof(corr->coef));
++(js_corr[joystick].nb);
return 0;
}

static s_js_corr * get_js_corr(uint8_t device, uint8_t axis)
static s_js_corr * get_js_corr(int joystick, int axis)
{
unsigned int i;
for (i = 0; i < js_corr[device].nb; ++i)
for (i = 0; i < js_corr[joystick].nb; ++i)
{
if(js_corr[device].corr[i].axis == axis)
if(js_corr[joystick].corr[i].axis == axis)
{
return js_corr[device].corr + i;
return js_corr[joystick].corr + i;
}
}
return NULL;
Expand Down Expand Up @@ -865,9 +873,9 @@ void cfg_profile_activation()
update_stick(i, j);
}

const s_ffb_tweaks * tweaks = cfg_get_ffb_tweaks(i);

adapter_set_haptic_tweaks(i, tweaks->invert);
const s_haptic_core_tweaks * tweaks = cfg_get_ffb_tweaks(i);
adapter_set_haptic_tweaks(i, tweaks);
}

cfg_controllers[i].next = NULL;
Expand Down
Loading

0 comments on commit c2828c8

Please sign in to comment.