Added Clamping to Joystick Values

Added Clamp function to general.c
Now clamps all final joystick values to be from 0 - 32767 (2^15 - 1).

Output from the 3ds was giving a strange range on the values, even though the
code expected it to be in the range -128 to 128.

Was more like -146 to 146 on the c-stick, and -170 to 170 on the circle pad.
This may remove some of the resolution of the sticks, but increase compatability with programs.
This commit is contained in:
Alex Rowe 2017-02-12 15:33:25 -06:00
parent 63268cd32e
commit f5bc0146d7
4 changed files with 36 additions and 22 deletions

Binary file not shown.

View File

@ -3,3 +3,5 @@
#include <stdio.h>
void error(const char *functionName);
int clamp(int val, int min, int max);

View File

@ -5,14 +5,26 @@
void error(const char *functionName) {
char errorMsg[92];
ZeroMemory(errorMsg, 92);
sprintf(errorMsg, "Call to %s returned error %d!", (char *)functionName, WSAGetLastError());
MessageBox(NULL, errorMsg, "socketIndication", MB_OK);
closesocket(client);
closesocket(listener);
WSACleanup();
exit(0);
}
int clamp (int val, int min, int max) {
if (val < min) {
return min;
}
if (val > max) {
return max;
}
return val;
}

View File

@ -200,51 +200,51 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
joyX = 16383; //Halfway between the x
joyY = 16383; //Halfway between the y
}
else if(settings.touch == joystick2) {
joyRX = 16383; //Halfway between the rx
joyRY = 16383; //Halfway between the ry
}
}
if(settings.circlePad == mouse) {
if(abs(circlePad.x) < settings.mouseSpeed * 3) circlePad.x = 0;
if(abs(circlePad.y) < settings.mouseSpeed * 3) circlePad.y = 0;
POINT p;
GetCursorPos(&p);
SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32);
}
else if(settings.circlePad == joystick1) {
joyX = (circlePad.x + 128) * 128;
joyY = (128 - circlePad.y) * 128;
joyX = clamp((circlePad.x + 128) * 128, 0, 32767);
joyY = clamp((128 - circlePad.y) * 128, 0, 32767);
}
else if(settings.circlePad == joystick2) {
joyRX = (circlePad.x + 128) * 128;
joyRY = (128 - circlePad.y) * 128;
joyRX = clamp((circlePad.x + 128) * 128, 0, 32767);
joyRY = clamp((128 - circlePad.y) * 128, 0, 32767);
}
if(settings.cStick == mouse) {
if(abs(cStick.x) < settings.mouseSpeed * 3) cStick.x = 0;
if(abs(cStick.y) < settings.mouseSpeed * 3) cStick.y = 0;
POINT p;
GetCursorPos(&p);
SetCursorPos(p.x + (cStick.x * settings.mouseSpeed) / 32, p.y - (cStick.y * settings.mouseSpeed) / 32);
}
else if(settings.cStick == joystick1) {
joyX = (cStick.x + 128) * 128;
joyY = (128 - cStick.y) * 128;
joyX = clamp((cStick.x + 128) * 128, 0, 32767);
joyY = clamp((128 - cStick.y) * 128, 0, 32767);
}
else if(settings.cStick == joystick2) {
joyRX = (cStick.x + 128) * 128;
joyRY = (128 - cStick.y) * 128;
joyRX = clamp((cStick.x + 128) * 128, 0, 32767);
joyRY = clamp((128 - cStick.y) * 128, 0, 32767);
}
if(settings.dPad == cPov) {
if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) {
if((currentKeys & KEY_DRIGHT)) {