This commit is contained in:
Maschell 2018-03-04 19:03:47 +01:00
commit bee832131a
4 changed files with 179 additions and 30 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

@ -2,6 +2,7 @@
#include <string.h>
#include <dynamic_libs/os_functions.h>
#include <dynamic_libs/vpad_functions.h>
#include <dynamic_libs/padscore_functions.h>
#include <dynamic_libs/sys_functions.h>
#include <dynamic_libs/fs_functions.h>
#include <dynamic_libs/proc_ui_functions.h>
@ -26,6 +27,7 @@ ON_APPLICATION_START(args) {
InitOSFunctionPointers();
InitSocketFunctionPointers(); //For logging
InitVPadFunctionPointers(); //For logging
InitPadScoreFunctionPointers();
log_init();

View File

@ -8,9 +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 <utils/logger.h>
#include <utils/StringTools.h>
#include <fs/FSUtils.h>
@ -83,8 +83,7 @@ void HandleMultiModPacks(u64 titleID/*,bool showMenu*/) {
int initScreen = 1;
int x_offset = -2;
VPADData vpad;
s32 vpadError;
initControllers();
OSScreenInit();
u32 screen_buf0_size = OSScreenGetBufferSizeEx(0);
@ -111,30 +110,32 @@ void HandleMultiModPacks(u64 titleID/*,bool showMenu*/) {
while(1){
vpadError = -1;
VPADRead(0, &vpad, 1, &vpadError);
pollControllers();
if(vpadError == 0) {
if(vpad.btns_d & VPAD_BUTTON_A) {
if (isButtonPressed(PAD_BTN_A)) {
wantToExit = 1;
initScreen = 1;
} else if(vpad.btns_d & VPAD_BUTTON_DOWN) {
}
else if (isButtonPressed(PAD_BTN_DOWN)) {
selected++;
initScreen = 1;
} else if(vpad.btns_d & VPAD_BUTTON_UP) {
}
else if (isButtonPressed(PAD_BTN_UP)) {
selected--;
initScreen = 1;
} else if(vpad.btns_d & VPAD_BUTTON_L) {
}
else if (isButtonPressed(PAD_BTN_L)) {
selected -= per_page;
initScreen = 1;
} else if(vpad.btns_d & VPAD_BUTTON_R) {
}
else if (isButtonPressed(PAD_BTN_R)) {
selected += per_page;
initScreen = 1;
}
if(selected < 0) selected = 0;
if(selected >= modPackListSize) selected = modPackListSize-1;
if (selected < 0) selected = 0;
if (selected >= modPackListSize) selected = modPackListSize - 1;
page = selected / per_page;
}
if(initScreen) {
OSScreenClearBufferEx(0, 0);
@ -183,6 +184,8 @@ void HandleMultiModPacks(u64 titleID/*,bool showMenu*/) {
OSScreenFlipBuffersEx(0);
OSScreenFlipBuffersEx(1);
releaseControllers();
free(screenbuffers);
return;