Merge pull request #14 from jakobkg/sdcafiine-padscore

[SDCafiine] Add support for more controllers...
This commit is contained in:
Maschell 2018-03-04 19:03:16 +01:00 committed by GitHub
commit 5c371135c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 <string.h>
#include <dynamic_libs/os_functions.h> #include <dynamic_libs/os_functions.h>
#include <dynamic_libs/vpad_functions.h> #include <dynamic_libs/vpad_functions.h>
#include <dynamic_libs/padscore_functions.h>
#include <dynamic_libs/sys_functions.h> #include <dynamic_libs/sys_functions.h>
#include <dynamic_libs/fs_functions.h> #include <dynamic_libs/fs_functions.h>
#include <dynamic_libs/proc_ui_functions.h> #include <dynamic_libs/proc_ui_functions.h>
@ -26,18 +27,19 @@ ON_APPLICATION_START(args) {
InitOSFunctionPointers(); InitOSFunctionPointers();
InitSocketFunctionPointers(); //For logging InitSocketFunctionPointers(); //For logging
InitVPadFunctionPointers(); //For logging InitVPadFunctionPointers(); //For logging
InitPadScoreFunctionPointers();
log_init(); log_init();
if(FileReplacerUtils::setGroupAndOwnerID()) { if(FileReplacerUtils::setGroupAndOwnerID()) {
//DEBUG_FUNCTION_LINE("SUCCESS\n"); //DEBUG_FUNCTION_LINE("SUCCESS\n");
} }
DEBUG_FUNCTION_LINE("SD mounted? %d\n",args.sd_mounted); DEBUG_FUNCTION_LINE("SD mounted? %d\n",args.sd_mounted);
DEBUG_FUNCTION_LINE("USB mounted? %d\n",args.usb_mounted); DEBUG_FUNCTION_LINE("USB mounted? %d\n",args.usb_mounted);
gSDInitDone = args.sd_mounted; gSDInitDone = args.sd_mounted;
gUSBInitDone = args.usb_mounted; gUSBInitDone = args.usb_mounted;
HandleMultiModPacks(OSGetTitleID()); HandleMultiModPacks(OSGetTitleID());
@ -51,4 +53,4 @@ ON_APPLICATION_ENDING() {
ON_APP_STATUS_CHANGED(status) { ON_APP_STATUS_CHANGED(status) {
gAppStatus = status; gAppStatus = status;
} }

View File

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