Skip to content
This repository was archived by the owner on Oct 13, 2019. It is now read-only.

Add Ordinaryperson2 fixes #9

Merged
merged 6 commits into from
Sep 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion 3DS/include/wireless.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ struct packet {
unsigned short x;
unsigned short y;
} touch;

struct {
short x;
short y;
} cStick;
};
struct keysPacket keysPacket;
};
Expand All @@ -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);
8 changes: 5 additions & 3 deletions 3DS/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -133,7 +135,7 @@ int main(void) {
}
}

sendKeys(kHeld, circlePad, touch);
sendKeys(kHeld, circlePad, touch, cStick);

receiveBuffer(sizeof(struct packet));

Expand Down
3 changes: 2 additions & 1 deletion 3DS/source/wireless.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
13 changes: 10 additions & 3 deletions PC/3DSController.ini
Original file line number Diff line number Diff line change
@@ -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,

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions PC/include/joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions PC/include/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand All @@ -78,6 +82,11 @@ struct circlePad {
short y;
};

struct cStick {
short x;
short y;
};

struct touch {
short x;
short y;
Expand All @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions PC/include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions PC/include/wireless.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ struct packet {
unsigned short x;
unsigned short y;
} touch;

struct {
short x;
short y;
} cStick;
};
struct keysPacket keysPacket;

Expand Down
1 change: 1 addition & 0 deletions PC/source/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ unsigned int lastKeys;
unsigned int currentKeys;

struct circlePad circlePad;
struct cStick cStick;
struct touch lastTouch;
struct touch currentTouch;

Expand Down
44 changes: 42 additions & 2 deletions PC/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}

Expand Down
44 changes: 33 additions & 11 deletions PC/source/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'} },
Expand All @@ -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} },
Expand Down Expand 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;
Expand All @@ -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];

Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down
Binary file modified PC/vJoyInterface.dll
Binary file not shown.
Loading