Initial merge of RedInquisitive's branch

It all merged, it compiled and it works. There are 2 separate
implementations of POV switches in this which I haven't sorted out yet,
if that's necessary (1 for each type, it's ok I guess?)
This commit is contained in:
Poke 2015-11-11 18:26:30 +10:30
commit b3fe66858b
14 changed files with 99 additions and 22 deletions

5
.gitignore vendored
View File

@ -1,9 +1,10 @@
3DS/build/
3DS/*.elf
3DS/*stripped.elf
3DS/*.3dsx
3DS/*.smdh
3DS/*.3ds
3DS/*.cia
PC/build/
PC/*.exe
*.pnproj
*.pnps
*.ppg

BIN
3DS/3DSController.3dsx Normal file

Binary file not shown.

View File

@ -59,6 +59,8 @@ struct packet {
short x;
short y;
} cStick;
unsigned int volume; //way longer than needed, but it works.
};
struct keysPacket keysPacket;
};
@ -84,4 +86,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, circlePosition cStick);
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick, unsigned int volume);

View File

@ -34,8 +34,8 @@ int main(void) {
acInit();
gfxInitDefault();
gfxSetDoubleBuffering(GFX_TOP, false);
gfxSetDoubleBuffering(GFX_BOTTOM, false);
gfxSetDoubleBuffering(GFX_TOP, true);
gfxSetDoubleBuffering(GFX_BOTTOM, true);
if(setjmp(exitJmp)) goto exit;
@ -91,8 +91,12 @@ int main(void) {
u32 kHeld = hidKeysHeld();
circlePosition circlePad;
circlePosition cStick;
u8 vol8;
u8* volp = &vol8; //As a test for pointing at things.
hidCstickRead(&cStick);
hidCircleRead(&circlePad);
HIDUSER_GetSoundVolume(volp);
u32 volume = (u32)vol8; //Upscale to 32 for transmission
touchPosition touch;
touchRead(&touch);
@ -103,7 +107,11 @@ int main(void) {
keyboardActive = !keyboardActive;
keyboardToggle = false;
if(keyboardActive) enableBacklight();
if(keyboardActive) {
enableBacklight();
} else {
disableBacklight();
}
}
}
else keyboardToggle = true;
@ -135,12 +143,12 @@ int main(void) {
}
}
sendKeys(kHeld, circlePad, touch, cStick);
sendKeys(kHeld, circlePad, touch, cStick, volume);
drawString(10, 10, "Volume: %x", volume);
//receiveBuffer(sizeof(struct packet));
if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) {
sendKeys(0, circlePad, touch, cStick);
sendKeys(0, circlePad, touch, cStick, volume);
longjmp(exitJmp, 1);
}

View File

@ -38,12 +38,13 @@ void sendConnectionRequest(void) {
sendBuf(offsetof(struct packet, connectPacket) + sizeof(struct connectPacket));
}
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick) {
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick, unsigned int volume) {
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);
memcpy(&outBuf.volume, &volume, 4);
sendBuf(offsetof(struct packet, keysPacket) + sizeof(struct keysPacket));
}

BIN
PC/3DSController.exe Normal file

Binary file not shown.

View File

@ -13,6 +13,10 @@
#define joyY iReport.wAxisY
#define joyRX iReport.wAxisXRot
#define joyRY iReport.wAxisYRot
//#define joyVolume iReport.wSlider
#define joyVolume iReport.wAxisZ
#define povHat iReport.bHats
#define joyButtons iReport.lButtons
#define JOY_MIDDLE (128 * 128)

View File

@ -3,4 +3,4 @@
extern unsigned char keyboardActive;
extern unsigned char keyboardToggle;
inline char currentKeyboardKey(void);
char currentKeyboardKey(void);

View File

@ -101,12 +101,14 @@ struct touch {
extern unsigned int lastKeys;
extern unsigned int currentKeys;
extern unsigned int volume;
extern struct circlePad circlePad;
extern struct cStick cStick;
extern struct touch lastTouch;
extern struct touch currentTouch;
inline unsigned int mapVirtualKey(unsigned int key);
unsigned int mapVirtualKey(unsigned int key);
void simulateKeyNewpress(unsigned int key);
void simulateKeyRelease(unsigned int key);
void handleHat(unsigned int hat);

View File

@ -20,6 +20,7 @@ struct settings {
int mouseSpeed;
UINT vJoyDevice;
struct keyMapping A, B, X, Y, L, R, ZL, ZR, Start, Select, Tap, Left, Right, Up, Down, PadLeft, PadRight, PadUp, PadDown, CSLeft, CSRight, CSUp, CSDown;
bool isUsingPov;
};
extern struct settings settings;

View File

@ -51,6 +51,8 @@ struct packet {
short x;
short y;
} cStick;
unsigned int volume;
};
struct keysPacket keysPacket;

View File

@ -7,6 +7,7 @@
unsigned int lastKeys;
unsigned int currentKeys;
unsigned int volume; //slider
struct circlePad circlePad;
struct cStick cStick;
@ -84,4 +85,4 @@ void handleHat(unsigned int hat) {
else if(hat & BIT(2)) iReport.bHats = 2;
else if(hat & BIT(3)) iReport.bHats = 3;
else iReport.bHats = -1;
}
}

View File

@ -121,15 +121,19 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
memcpy(&circlePad, &buffer.circlePad, 4);
memcpy(&currentTouch, &buffer.touch, 4);
memcpy(&cStick, &buffer.cStick, 4);
memcpy(&volume, &buffer.volume, 4);
//printf("\rVolume is currently: %x ", volume); //test
handleKey(KEY_A, settings.A);
handleKey(KEY_B, settings.B);
handleKey(KEY_SELECT, settings.Select);
handleKey(KEY_START, settings.Start);
handleKey(KEY_DRIGHT, settings.Right);
handleKey(KEY_DLEFT, settings.Left);
handleKey(KEY_DUP, settings.Up);
handleKey(KEY_DDOWN, settings.Down);
if(!settings.isUsingPov) { //Handle normally if not using POV in settings.
handleKey(KEY_DRIGHT, settings.Right);
handleKey(KEY_DLEFT, settings.Left);
handleKey(KEY_DUP, settings.Up);
handleKey(KEY_DDOWN, settings.Down);
}
handleKey(KEY_R, settings.R);
handleKey(KEY_L, settings.L);
handleKey(KEY_ZR, settings.ZR);
@ -180,18 +184,28 @@ 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 == joystick1) {
joyX = (currentTouch.x) * 128;
joyY = (currentTouch.y) * 128;
else if(settings.touch == joystick1) { //made a little bit more accurate to the screen size.
joyX = (int)((float)(currentTouch.x) * 102.3f);
joyY = (int)((float)(currentTouch.y) * 136.5f);
}
else if(settings.touch == joystick2) {
joyRX = (currentTouch.x) * 128;
joyRY = (currentTouch.y) * 128;
joyRX = (int)((float)(currentTouch.x) * 102.3f);
joyRY = (int)((float)(currentTouch.y) * 136.5f);
}
else {
handleKey(KEY_TOUCH, settings.Tap);
}
} else { //If we are not touching, move to center (Like if you release the joystick on a normal controller).
if(settings.touch == joystick1) {
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) {
@ -231,6 +245,43 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
joyRY = (128 - cStick.y) * 128;
}
if(settings.isUsingPov) {
if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) {
if((currentKeys & KEY_DRIGHT)) {
povHat = 4500;
} else {
povHat = 0;
}
} else if((currentKeys & KEY_DRIGHT)) {
if((currentKeys & KEY_DDOWN)) {
povHat = 13500;
} else {
povHat = 9000;
}
} else if((currentKeys & KEY_DDOWN)) {
if((currentKeys & KEY_DLEFT)) {
povHat = 22500;
} else {
povHat = 18000;
}
} else if((currentKeys & KEY_DLEFT)) {
if ((currentKeys & KEY_DUP)) {
povHat = 31500;
} else {
povHat = 27000;
}
}
if(!((currentKeys & KEY_DUP) || (currentKeys & KEY_DRIGHT) || (currentKeys & KEY_DDOWN) || (currentKeys & KEY_DLEFT))) {
//If none are pressed, reset the POV hat
povHat = -1;
}
}
joyVolume = volume * 512;
break;
}

View File

@ -32,6 +32,7 @@ struct settings defaultSettings = {
Start: { 1, {VK_RETURN} },
Select: { 1, {VK_BACK} },
Tap: { 1, {'T'} },
isUsingPov: false,
};
static bool getSetting(char *name, char *src, char *dest) {
@ -92,6 +93,9 @@ static struct keyMapping getButton(char *string) {
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 if(strcmp(string, "POV") == 0) {settings.isUsingPov = true;}
//No matter what the others are, if any are set to true then we are using the POV hat for the DPad
//This would mean if any setting at all is POV then the dpad is suddenly a POV.
else if(strcmp(string, "NORTH") == 0) { k.useJoypad = 3; k.joypadButton = 1 << 0; }
else if(strcmp(string, "EAST") == 0) { k.useJoypad = 3; k.joypadButton = 1 << 1; }