Skip to content

Commit

Permalink
Improvements: activation of the mouse on the trigger and sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
r57zone committed Jan 18, 2021
1 parent e3729c1 commit 7f2f90f
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 216 deletions.
73 changes: 32 additions & 41 deletions X360AdvanceApp/X360Advance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "IniReader\IniReader.h"

float SensX, SensY;
float ArduinoData[4] = { 0, 0, 0, 0 }; //Mode, Yaw, Pitch, Roll
float ArduinoData[4] = { 0, 0, 0, 0 }; // Mode, Yaw, Pitch, Roll
float LastArduinoData[4] = { 0, 0, 0, 0 };
float YRPOffset[3] = { 0, 0, 0 };
int last_x = 0, last_y = 0;
float accumulatedX = 0, accumulatedY = 0;
int GameMode = 2;
bool ArduinoWork = false;

Expand Down Expand Up @@ -36,49 +36,34 @@ bool CorrectAngleValue(float Value)
}
}

int MouseGetDelta(int val, int prev) //Implementation from OpenTrack https://github.com/opentrack/opentrack/blob/unstable/proto-mouse/
{
const int a = std::abs(val - prev), b = std::abs(val + prev);
if (b < a)
return val + prev;
else
return val - prev;
}

void MouseMove(const double axisX, const double axisY) //Implementation from OpenTrack https://github.com/opentrack/opentrack/blob/unstable/proto-mouse/
{
int mouse_x = 0, mouse_y = 0;

mouse_x = round(axisX * SensX * 2);
mouse_y = round(axisY * SensY * 2);

const int dx = MouseGetDelta(mouse_x, last_x);
const int dy = MouseGetDelta(mouse_y, last_y);

last_x = mouse_x;
last_y = mouse_y;

if (dx || dy)
{
INPUT input;
input.type = INPUT_MOUSE;
MOUSEINPUT& mi = input.mi;
mi = {};
mi.dx = dx;
mi.dy = dy;
mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_MOVE_NOCOALESCE;

SendInput(1, &input, sizeof(input));
}
//Implementation from https://github.com/JibbSmart/JoyShockMapper/blob/master/JoyShockMapper/src/win32/InputHelpers.cpp
void MouseMove(float x, float y) {
accumulatedX += x;
accumulatedY += y;

int applicableX = (int)accumulatedX;
int applicableY = (int)accumulatedY;

accumulatedX -= applicableX;
accumulatedY -= applicableY;

INPUT input;
input.type = INPUT_MOUSE;
input.mi.mouseData = 0;
input.mi.time = 0;
input.mi.dx = applicableX;
input.mi.dy = applicableY;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
SendInput(1, &input, sizeof(input));
}

int main()
{
SetConsoleTitle("X360Advance");

CIniReader IniFile("X360Advance.ini");
SensX = IniFile.ReadFloat("Main", "SensX", 4.5);
SensY = IniFile.ReadFloat("Main", "SensY", 3.5);
SensX = IniFile.ReadFloat("Main", "SensX", 35);
SensY = IniFile.ReadFloat("Main", "SensY", 30);
HANDLE hSerial;

char sPortName[8];
Expand Down Expand Up @@ -112,7 +97,7 @@ int main()
}
else
{
printf("Mouse movement activated\r\nNumpad 5 - centering\r\n");
printf("Mouse movement activated\r\nNumpad 5 - reset\r\n");
printf("Press \"~\" to exit\r\n");
}

Expand Down Expand Up @@ -162,9 +147,15 @@ int main()
YRPOffset[2] = LastArduinoData[3];
}

if (GameMode == 2)
MouseMove(OffsetYPR(ArduinoData[1], YRPOffset[0]) * -1, OffsetYPR(ArduinoData[3], YRPOffset[2]));
if (GameMode == 2) {
float NewX = OffsetYPR(ArduinoData[1], YRPOffset[0]) * -1;
float NewY = OffsetYPR(ArduinoData[3], YRPOffset[2]);

MouseMove(NewX * SensX, NewY * SensY);

YRPOffset[0] = LastArduinoData[1];
YRPOffset[2] = LastArduinoData[3];
}

if ((GetAsyncKeyState(VK_NUMPAD5) & 0x8000) != 0) {
PurgeComm(hSerial, PURGE_TXCLEAR | PURGE_RXCLEAR);
Expand Down
70 changes: 53 additions & 17 deletions X360AdvanceSettings/Unit1.dfm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
object Form1: TForm1
object Main: TMain
Left = 192
Top = 125
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'X360Advance - Settings'
ClientHeight = 210
ClientHeight = 249
ClientWidth = 384
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Expand All @@ -19,7 +19,7 @@ object Form1: TForm1
TextHeight = 13
object ApplyBtn: TButton
Left = 8
Top = 176
Top = 216
Width = 75
Height = 25
Caption = 'Apply'
Expand All @@ -28,7 +28,7 @@ object Form1: TForm1
end
object CloseBtn: TButton
Left = 88
Top = 176
Top = 216
Width = 75
Height = 25
Caption = 'Close'
Expand All @@ -39,26 +39,26 @@ object Form1: TForm1
Left = 192
Top = 8
Width = 185
Height = 161
Height = 201
Caption = 'Mouse'
TabOrder = 2
object XAxisSensitivityLbl: TLabel
Left = 8
Top = 24
Top = 48
Width = 76
Height = 13
Caption = 'X-axis sensitivity'
end
object YAxisSensitivityLbl: TLabel
Left = 8
Top = 88
Top = 96
Width = 76
Height = 13
Caption = 'Y-axis sensitivity'
end
object XAxisSensitivityValueLbl: TLabel
Left = 160
Top = 52
Top = 68
Width = 6
Height = 13
Caption = '0'
Expand All @@ -70,15 +70,29 @@ object Form1: TForm1
Height = 13
Caption = '0'
end
object TriggerSensitivityLbl: TLabel
Left = 8
Top = 144
Width = 118
Height = 13
Caption = 'Sensitivity with left trigger'
end
object TriggerSensitivityValueLbl: TLabel
Left = 160
Top = 165
Width = 6
Height = 13
Caption = '0'
end
object XAxisSensitivityTB: TTrackBar
Left = 8
Top = 48
Top = 64
Width = 150
Height = 33
Max = 100
Min = 1
Frequency = 10
Position = 45
Position = 30
TabOrder = 0
OnChange = XAxisSensitivityTBChange
end
Expand All @@ -90,16 +104,38 @@ object Form1: TForm1
Max = 100
Min = 1
Frequency = 10
Position = 35
Position = 25
TabOrder = 1
OnChange = YAxisSensitivityTBChange
end
object CBOnlyTrigger: TCheckBox
Left = 8
Top = 21
Width = 169
Height = 17
Caption = 'Activate by left trigger'
TabOrder = 2
end
object TriggerSensitivityTB: TTrackBar
Left = 8
Top = 160
Width = 150
Height = 33
Hint = 'Decrease the sensitivity to aim more accurately.'
Max = 20
Min = 1
ParentShowHint = False
Position = 10
ShowHint = True
TabOrder = 3
OnChange = TriggerSensitivityTBChange
end
end
object SteeringWheelGB: TGroupBox
Left = 8
Top = 88
Top = 112
Width = 177
Height = 81
Height = 97
Caption = 'Steering wheel'
TabOrder = 3
object SensitivityAngleLbl: TLabel
Expand Down Expand Up @@ -133,7 +169,7 @@ object Form1: TForm1
Left = 8
Top = 8
Width = 177
Height = 73
Height = 97
Caption = 'Setup'
TabOrder = 4
object COMPortLbl: TLabel
Expand All @@ -154,15 +190,15 @@ object Form1: TForm1
end
object AboutBtn: TButton
Left = 349
Top = 176
Top = 216
Width = 27
Height = 25
Caption = '?'
TabOrder = 5
OnClick = AboutBtnClick
end
object XPManifest1: TXPManifest
Left = 312
Top = 176
Left = 152
Top = 24
end
end
Loading

0 comments on commit 7f2f90f

Please sign in to comment.