Moved controller stuff out of the modpack selector files for cleanliness

This commit is contained in:
jakobkg 2018-02-26 10:14:01 +01:00
parent 731860bef2
commit 8737d4bc54
3 changed files with 145 additions and 137 deletions

View File

@ -0,0 +1,129 @@
#include <utils/logger.h>
#include "controllers.h"
VPADData vpad;
s32 vpadError;
KPADData pads[4];
s32 padErrors[4];
u32 padTypes[4];
void initControllers() {
KPADInit();
}
void releaseControllers() {
for(int i = 0; i < 4; i++) {
padErrors[i] = WPADProbe(i, &padTypes[i]);
if(padErrors[i] == 0) {
WPADDisconnect(i);
}
}
//Clear buffers so future launches of SDCafiine don't read old data
memset(&vpad, 0, sizeof(VPADData));
vpadError = 0;
memset(pads, 0, sizeof(KPADData) * 4);
memset(padErrors, 0, sizeof(s32) * 4);
memset(padTypes, 0, sizeof(u32) * 4);
}
void pollControllers() {
VPADRead(0, &vpad, 1, &vpadError);
for(int i = 0; i < 4; i++) {
padErrors[i] = WPADProbe(i, &padTypes[i]);
if(padErrors[i] == 0) {
KPADRead(i, &pads[i], 1);
}
}
}
bool isButtonPressed(enum PadButton btn) {
if(vpadError == 0) {
switch (btn) {
case PAD_BTN_A:
if (vpad.btns_d & VPAD_BUTTON_A) return true;
break;
case PAD_BTN_UP:
if (vpad.btns_d & VPAD_BUTTON_UP) return true;
break;
case PAD_BTN_DOWN:
if (vpad.btns_d & VPAD_BUTTON_DOWN) return true;
break;
case PAD_BTN_L:
if (vpad.btns_d & VPAD_BUTTON_L) return true;
break;
case PAD_BTN_R:
if (vpad.btns_d & VPAD_BUTTON_R) return true;
break;
default:
break;
}
}
for(int i = 0; i < 4; i++) {
if(padErrors[i] == 0) {
if(pads[i].device_type < 2) {
switch(btn) {
case PAD_BTN_A:
if (pads[i].btns_d & WPAD_BUTTON_A) return true;
break;
case PAD_BTN_UP:
if (pads[i].btns_d & WPAD_BUTTON_UP) return true;
break;
case PAD_BTN_DOWN:
if (pads[i].btns_d & WPAD_BUTTON_DOWN) return true;
break;
case PAD_BTN_L:
if (pads[i].btns_d & WPAD_BUTTON_1) return true;
break;
case PAD_BTN_R:
if (pads[i].btns_d & WPAD_BUTTON_2) return true;
break;
default:
break;
}
}
else {
switch(btn) {
case PAD_BTN_A:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_A) return true;
break;
case PAD_BTN_UP:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_UP) return true;
break;
case PAD_BTN_DOWN:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_DOWN) return true;
break;
case PAD_BTN_L:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_L) return true;
break;
case PAD_BTN_R:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_R) return true;
break;
default:
break;
}
}
}
}
return false;
}

View File

@ -0,0 +1,15 @@
#include <dynamic_libs/vpad_functions.h>
#include <dynamic_libs/padscore_functions.h>
enum PadButton {
PAD_BTN_A,
PAD_BTN_UP,
PAD_BTN_DOWN,
PAD_BTN_L,
PAD_BTN_R
};
void initControllers();
void releaseControllers();
void pollControllers();
bool isButtonPressed(enum PadButton btn);

View File

@ -8,10 +8,9 @@
#include <malloc.h>
#include "modpackSelector.h"
#include "common/common.h"
#include "controllers.h"
#include <dynamic_libs/os_functions.h>
#include <dynamic_libs/vpad_functions.h>
#include <dynamic_libs/padscore_functions.h>
#include <utils/logger.h>
#include <utils/StringTools.h>
#include <fs/FSUtils.h>
@ -21,141 +20,6 @@
#define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2))
enum PadButton {
PAD_BTN_A,
PAD_BTN_UP,
PAD_BTN_DOWN,
PAD_BTN_L,
PAD_BTN_R
};
VPADData vpad;
s32 vpadError;
KPADData pads[4];
s32 padErrors[4];
u32 padTypes[4];
void initControllers() {
KPADInit();
}
void releaseControllers() {
for(int i = 0; i < 4; i++) {
padErrors[i] = WPADProbe(i, &padTypes[i]);
if(padErrors[i] == 0) {
WPADDisconnect(i);
}
}
//Clear buffers so future launches of SDCafiine don't read old data
memset(&vpad, 0, sizeof(VPADData));
vpadError = 0;
memset(pads, 0, sizeof(KPADData) * 4);
memset(padErrors, 0, sizeof(s32) * 4);
memset(padTypes, 0, sizeof(u32) * 4);
}
void pollControllers() {
VPADRead(0, &vpad, 1, &vpadError);
for(int i = 0; i < 4; i++) {
padErrors[i] = WPADProbe(i, &padTypes[i]);
if(padErrors[i] == 0) {
KPADRead(i, &pads[i], 1);
}
}
}
bool isButtonPressed(enum PadButton btn) {
if(vpadError == 0) {
switch (btn) {
case PAD_BTN_A:
if (vpad.btns_d & VPAD_BUTTON_A) return true;
break;
case PAD_BTN_UP:
if (vpad.btns_d & VPAD_BUTTON_UP) return true;
break;
case PAD_BTN_DOWN:
if (vpad.btns_d & VPAD_BUTTON_DOWN) return true;
break;
case PAD_BTN_L:
if (vpad.btns_d & VPAD_BUTTON_L) return true;
break;
case PAD_BTN_R:
if (vpad.btns_d & VPAD_BUTTON_R) return true;
break;
default:
break;
}
}
for(int i = 0; i < 4; i++) {
if(padErrors[i] == 0) {
if(pads[i].device_type < 2) {
switch(btn) {
case PAD_BTN_A:
if (pads[i].btns_d & WPAD_BUTTON_A) return true;
break;
case PAD_BTN_UP:
if (pads[i].btns_d & WPAD_BUTTON_UP) return true;
break;
case PAD_BTN_DOWN:
if (pads[i].btns_d & WPAD_BUTTON_DOWN) return true;
break;
case PAD_BTN_L:
if (pads[i].btns_d & WPAD_BUTTON_1) return true;
break;
case PAD_BTN_R:
if (pads[i].btns_d & WPAD_BUTTON_2) return true;
break;
default:
break;
}
}
else {
switch(btn) {
case PAD_BTN_A:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_A) return true;
break;
case PAD_BTN_UP:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_UP) return true;
break;
case PAD_BTN_DOWN:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_DOWN) return true;
break;
case PAD_BTN_L:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_L) return true;
break;
case PAD_BTN_R:
if (pads[i].classic.btns_d & WPAD_CLASSIC_BUTTON_R) return true;
break;
default:
break;
}
}
}
}
return false;
}
void HandleMultiModPacks(u64 titleID/*,bool showMenu*/) {
gModFolder[0] = 0;