Merge pull request #9 from Ordinaryperson2/master

Add Ordinaryperson2 fixes
This commit is contained in:
CTurt 2015-09-06 18:25:10 +01:00
commit b2c7c42d9b
13 changed files with 127 additions and 28 deletions

View File

@ -54,6 +54,11 @@ struct packet {
unsigned short x;
unsigned short y;
} touch;
struct {
short x;
short y;
} cStick;
};
struct keysPacket keysPacket;
};
@ -79,4 +84,4 @@ bool openSocket(int port);
void sendBuf(int length);
int receiveBuffer(int length);
void sendConnectionRequest(void);
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch);
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick);

View File

@ -87,12 +87,14 @@ int main(void) {
while(aptMainLoop()) {
hidScanInput();
//irrstScanInput();
irrstScanInput();
u32 kHeld = hidKeysHeld();
circlePosition circlePad;
//hidCstickRead(&cstick);
circlePosition cStick;
hidCircleRead(&circlePad);
irrstCstickRead(&cStick);
touchPosition touch;
touchRead(&touch);
@ -133,7 +135,7 @@ int main(void) {
}
}
sendKeys(kHeld, circlePad, touch);
sendKeys(kHeld, circlePad, touch, cStick);
receiveBuffer(sizeof(struct packet));

View File

@ -38,11 +38,12 @@ void sendConnectionRequest(void) {
sendBuf(offsetof(struct packet, connectPacket) + sizeof(struct connectPacket));
}
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch) {
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick) {
outBuf.command = KEYS;
outBuf.keyboardActive = keyboardActive;
memcpy(&outBuf.keys, &keys, 4);
memcpy(&outBuf.circlePad, &circlePad, 4);
memcpy(&outBuf.touch, &touch, 4);
memcpy(&outBuf.cStick, &cStick, 4);
sendBuf(offsetof(struct packet, keysPacket) + sizeof(struct keysPacket));
}

View File

@ -1,10 +1,13 @@
Default port is 8889, if you change this, you must change it in the 3DS's 3DSController.ini as well,
Circle Pad and Touch can be either JOYSTICK or MOUSE,
Circle Pad, C Stick and Touch can be MOUSE, JOYSTICK1 or JOYSTICK2
JOYSTICK1 uses X and Y. JOYSTICK2 uses Rx and Ry. These are 0, 1, 3 and 4 respectively, leaving 2 and 5 unused.
Mouse Speed controls how fast the Circle Pad or Touch Screen moves the mouse. If set to 0 and using the Touch Screen, it will set to the absolute position, rather than moving relatively to last position,
Buttons can be a letter for a keyboard key (like Q, W, E, R, T, or Y), a special keyboard key (like SPACE, CLICK, RIGHT CLICK, ENTER, BACKSPACE, SHIFT, TAB, LEFT, RIGHT, UP, DOWN, PAGE UP, PAGE DOWN, or WINDOWS), or a joypad button (JOY1, JOY2, JOY3, to JOY8),
Buttons can be a letter for a keyboard key (like Q, W, E, R, T, or Y), a special keyboard key (like SPACE, CLICK, RIGHT CLICK, ENTER, BACKSPACE, SHIFT, TAB, LEFT, RIGHT, UP, DOWN, PAGE UP, PAGE DOWN, or WINDOWS), or a joypad button (JOY1, JOY2, JOY3, to JOY16).
If you want to use JOY9 through JOY16 you need to reconfigure vJoy. Search for vJoyConf in your start menu and set buttons to 16.
Alternatively, you can disable a key by binding it to NONE,
@ -17,15 +20,19 @@ Make sure to use a single space, not a tab for seperating settings,
Port: 8889
Throttle: 20
Circle Pad: JOYSTICK
Circle Pad: JOYSTICK1
C Stick: JOYSTICK2
Touch: MOUSE
Mouse Speed: 0
A: A
B: B
X: X
Y: Y
L: L
R: R
ZL: Q
ZR: W
Left: LEFT
Right: RIGHT
Up: UP

View File

@ -11,6 +11,8 @@
#define joyX iReport.wAxisX
#define joyY iReport.wAxisY
#define joyRX iReport.wAxisXRot
#define joyRY iReport.wAxisYRot
#define joyButtons iReport.lButtons
#define JOY_MIDDLE (128 * 128)

View File

@ -21,14 +21,18 @@
#define release(key) (!(currentKeys & key) && (lastKeys & key))
#define handleKey(DSKey, PCKey) do {\
if(PCKey.useKeyboard) {\
if(!PCKey.useJoypad) {\
if(newpress(DSKey)) simulateKeyNewpress(PCKey.virtualKey);\
if(release(DSKey)) simulateKeyRelease(PCKey.virtualKey);\
}\
else {\
else if(PCKey.useJoypad == 1) {\
if(currentKeys & DSKey) joyButtons |= PCKey.joypadButton;\
else joyButtons &= ~PCKey.joypadButton;\
}\
else if(PCKey.useJoypad == 2) {\
if(currentKeys & DSKey) joyButtons |= PCKey.joypadButton << 8;\
else joyButtons &= ~(PCKey.joypadButton << 8);\
}\
} while(0)
#define BIT(n) (1 << (n))
@ -66,7 +70,7 @@ typedef enum {
} KEYPAD_BITS;
struct keyMapping {
unsigned char useKeyboard; // 0 joypad button, 1 keyboard key
unsigned char useJoypad; // 0 keyboard key, 1 joypad1-8, 2 joypad9-16
union {
unsigned char virtualKey;
unsigned char joypadButton;
@ -78,6 +82,11 @@ struct circlePad {
short y;
};
struct cStick {
short x;
short y;
};
struct touch {
short x;
short y;
@ -87,6 +96,7 @@ extern unsigned int lastKeys;
extern unsigned int currentKeys;
extern struct circlePad circlePad;
extern struct cStick cStick;
extern struct touch lastTouch;
extern struct touch currentTouch;

View File

@ -6,16 +6,18 @@
enum analogue {
mouse,
joystick,
joystick1,
joystick2,
};
struct settings {
int port;
int throttle;
enum analogue circlePad;
enum analogue cStick;
enum analogue touch;
int mouseSpeed;
struct keyMapping A, B, X, Y, L, R, Left, Right, Up, Down, Start, Select, Tap;
struct keyMapping A, B, X, Y, L, R, ZL, ZR, Left, Right, Up, Down, Start, Select, Tap;
};
extern struct settings settings;

View File

@ -46,6 +46,11 @@ struct packet {
unsigned short x;
unsigned short y;
} touch;
struct {
short x;
short y;
} cStick;
};
struct keysPacket keysPacket;

View File

@ -8,6 +8,7 @@ unsigned int lastKeys;
unsigned int currentKeys;
struct circlePad circlePad;
struct cStick cStick;
struct touch lastTouch;
struct touch currentTouch;

View File

@ -28,11 +28,14 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
bool vJoy = true;
UINT iInterface = 1;
iReport.wAxisX = JOY_MIDDLE;
iReport.wAxisY = JOY_MIDDLE;
iReport.wAxisZ = JOY_MIDDLE;
iReport.wAxisXRot = JOY_MIDDLE;
iReport.wAxisYRot = JOY_MIDDLE;
iReport.wAxisZRot = JOY_MIDDLE;
iReport.wSlider = JOY_MIDDLE;
iReport.wDial = JOY_MIDDLE;
iReport.lButtons = 0;
iReport.bHats = -1;
@ -61,6 +64,9 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
initNetwork();
char nButtons = GetVJDButtonNumber(iInterface);
if(nButtons <16) printf("Your vJoy has less than 16 buttons (8 by default), some may not work!\n");
printf("Port: %d\n", settings.port);
printf("Running on: %s\n", hostName);
@ -93,6 +99,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
lastTouch.y = 0;
currentTouch.x = 0;
currentTouch.y = 0;
cStick.x = 0;
cStick.y = 0;
buffer.command = CONNECT;
printf("3DS Connected!\n");
@ -114,6 +122,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
memcpy(&currentKeys, &buffer.keys, 4);
memcpy(&circlePad, &buffer.circlePad, 4);
memcpy(&currentTouch, &buffer.touch, 4);
memcpy(&cStick, &buffer.cStick, 4);
handleKey(KEY_A, settings.A);
handleKey(KEY_B, settings.B);
@ -125,6 +134,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
handleKey(KEY_DDOWN, settings.Down);
handleKey(KEY_R, settings.R);
handleKey(KEY_L, settings.L);
handleKey(KEY_ZR, settings.ZR);
handleKey(KEY_ZL, settings.ZL);
handleKey(KEY_X, settings.X);
handleKey(KEY_Y, settings.Y);
@ -155,10 +166,15 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
SetCursorPos((int)((double)currentTouch.x * widthMultiplier), (int)((double)currentTouch.y * heightMultiplier));
}
}
else if(settings.touch == joystick) {
else if(settings.touch == joystick1) {
joyX = (currentTouch.x) * 128;
joyY = (currentTouch.y) * 128;
}
else if(settings.touch == joystick2) {
joyRX = (currentTouch.x) * 128;
joyRY = (currentTouch.y) * 128;
}
else {
handleKey(KEY_TOUCH, settings.Tap);
}
@ -172,11 +188,35 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
GetCursorPos(&p);
SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32);
}
else if(settings.circlePad == joystick) {
else if(settings.circlePad == joystick1) {
joyX = (circlePad.x + 128) * 128;
joyY = (128 - circlePad.y) * 128;
}
else if(settings.circlePad == joystick2) {
joyRX = (circlePad.x + 128) * 128;
joyRY = (128 - circlePad.y) * 128;
}
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;
}
else if(settings.cStick == joystick2) {
joyRX = (cStick.x + 128) * 128;
joyRY = (128 - cStick.y) * 128;
}
break;
}

View File

@ -12,7 +12,8 @@ struct settings settings;
struct settings defaultSettings = {
port: 8889,
throttle: 20,
circlePad: joystick,
circlePad: joystick1,
cStick: joystick2,
touch: mouse,
mouseSpeed: 4,
A: { 1, {'A'} },
@ -21,6 +22,8 @@ struct settings defaultSettings = {
Y: { 1, {'Y'} },
L: { 1, {'L'} },
R: { 1, {'R'} },
ZL: { 1, {'Q'} },
ZR: { 1, {'W'} },
Left: { 1, {VK_LEFT} },
Right: { 1, {VK_RIGHT} },
Up: { 1, {VK_UP} },
@ -52,6 +55,7 @@ static bool getSetting(char *name, char *src, char *dest) {
static struct keyMapping getButton(char *string) {
struct keyMapping k = { 1, {0} };
k.useJoypad = 0;
if(strcmp(string, "SPACE") == 0) k.virtualKey = VK_SPACE;
else if(strcmp(string, "CLICK") == 0) k.virtualKey = VK_LBUTTON;
else if(strcmp(string, "RIGHT CLICK") == 0) k.virtualKey = VK_RBUTTON;
@ -68,14 +72,22 @@ static struct keyMapping getButton(char *string) {
else if(strcmp(string, "WINDOWS") == 0) k.virtualKey = VK_LWIN;
else if(strcmp(string, "NONE") == 0) k.virtualKey = 0;
else if(strcmp(string, "JOY1") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 0; }
else if(strcmp(string, "JOY2") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 1; }
else if(strcmp(string, "JOY3") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 2; }
else if(strcmp(string, "JOY4") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 3; }
else if(strcmp(string, "JOY5") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 4; }
else if(strcmp(string, "JOY6") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 5; }
else if(strcmp(string, "JOY7") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 6; }
else if(strcmp(string, "JOY8") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 7; }
else if(strcmp(string, "JOY1") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 0; }
else if(strcmp(string, "JOY2") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 1; }
else if(strcmp(string, "JOY3") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 2; }
else if(strcmp(string, "JOY4") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 3; }
else if(strcmp(string, "JOY5") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 4; }
else if(strcmp(string, "JOY6") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 5; }
else if(strcmp(string, "JOY7") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 6; }
else if(strcmp(string, "JOY8") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 7; }
else if(strcmp(string, "JOY9") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 0; }
else if(strcmp(string, "JOY10") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 1; }
else if(strcmp(string, "JOY11") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 2; }
else if(strcmp(string, "JOY12") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 3; }
else if(strcmp(string, "JOY13") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 4; }
else if(strcmp(string, "JOY14") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 5; }
else if(strcmp(string, "JOY15") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 6; }
else if(strcmp(string, "JOY16") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 7; }
else k.virtualKey = (int)string[0];
@ -118,12 +130,20 @@ bool readSettings(void) {
if(getSetting("Circle Pad: ", buffer, setting)) {
if(strcmp(setting, "MOUSE") == 0) settings.circlePad = mouse;
else if(strcmp(setting, "JOYSTICK") == 0) settings.circlePad = joystick;
else if(strcmp(setting, "JOYSTICK1") == 0) settings.circlePad = joystick1;
else if(strcmp(setting, "JOYSTICK2") == 0) settings.circlePad = joystick2;
}
if(getSetting("C Stick: ", buffer, setting)) {
if(strcmp(setting, "MOUSE") == 0) settings.cStick = mouse;
else if(strcmp(setting, "JOYSTICK1") == 0) settings.cStick = joystick1;
else if(strcmp(setting, "JOYSTICK2") == 0) settings.cStick = joystick2;
}
if(getSetting("Touch: ", buffer, setting)) {
if(strcmp(setting, "MOUSE") == 0) settings.touch = mouse;
else if(strcmp(setting, "JOYSTICK") == 0) settings.touch = joystick;
else if(strcmp(setting, "JOYSTICK1") == 0) settings.touch = joystick1;
else if(strcmp(setting, "JOYSTICK2") == 0) settings.touch = joystick2;
}
if(getSetting("Mouse Speed: ", buffer, setting)) {
@ -136,6 +156,8 @@ bool readSettings(void) {
if(getSetting("Y: ", buffer, setting)) settings.Y = getButton(setting);
if(getSetting("L: ", buffer, setting)) settings.L = getButton(setting);
if(getSetting("R: ", buffer, setting)) settings.R = getButton(setting);
if(getSetting("ZL: ", buffer, setting)) settings.ZL = getButton(setting);
if(getSetting("ZR: ", buffer, setting)) settings.ZR = getButton(setting);
if(getSetting("Left: ", buffer, setting)) settings.Left = getButton(setting);
if(getSetting("Right: ", buffer, setting)) settings.Right = getButton(setting);
if(getSetting("Up: ", buffer, setting)) settings.Up = getButton(setting);

Binary file not shown.

View File

@ -6,7 +6,7 @@ A 3DS homebrew application which allows you to use your 3DS as a wireless contro
The latest release will always be downloadable from [here](https://github.com/CTurt/3DSController/releases/).
### Setup and Usage
Firstly, if you want to be able to use the circle pad as a joystick you will need to install [vJoy (version 2.0.4 is preferable)](http://sourceforge.net/projects/vjoystick/files/Beta%202.x/2.0.4%20220914/vJoy_204_I220914.exe/download). However, if you just want to use the buttons, this is not necessary.
Firstly, if you want to be able to use the circle pad as a joystick you will need to install [vJoy (version 2.0.5-120515 is preferable)](http://sourceforge.net/projects/vjoystick/files/Beta%202.x/2.0.5-120515/vJoy_205_050515.exe/download). However, if you just want to use keyboard buttons, this is not necessary.
Extract the archive and copy the executable in the `3DS` directory with the extension that applies to your loader: `3DSController.3dsx` and `3DSController.smdh` for Ninjhax, `3DSController.3ds` for flashcards, or `3DSController.cia` for CFWs, into your 3DS's SD card or flashcard's micro SD card.
@ -24,10 +24,12 @@ Otherwise, you should just see a black screen, this is a good sign. To see if it
If using version 0.4 or above you can press L, R and X to bring up the keyboard. Press L, R and X again to close it.
If using version 0.6 or above, up to 16 joystick buttons are available. If you wish to use more than 8, you need to configure vJoy. Search in your start menu for vJoyConfig and set buttons to 16.
If using Ninjhax press Start and Select to return to the Homebrew Loader, otherwise you can just exit with the Home button.
### Configuration
Find the line `Port: 8888` and change it to your desired port, do this for both the 3DS's `3DSController.ini` and the PC's `3DSController.ini`.
Find the line `Port: 8889` and change it to your desired port, do this for both the 3DS's `3DSController.ini` and the PC's `3DSController.ini`.
To use custom key bindings, just change the PC's `3DSController.ini` file, it should be straight forward.