2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "vt.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-18 00:09:21 +00:00
|
|
|
s32 D_8012D280 = 1;
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padMgr) {
|
2022-04-09 00:20:23 +00:00
|
|
|
OSMesgQueue* serialEventQueue = NULL;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "serialMsgQ Waiting for lock"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("%2d %d serialMsgQロック待ち %08x %08x %08x\n", osGetThreadId(NULL),
|
2022-04-09 00:20:23 +00:00
|
|
|
MQ_GET_COUNT(&padMgr->serialLockQueue), padMgr, &padMgr->serialLockQueue, &serialEventQueue);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&padMgr->serialLockQueue, (OSMesg*)&serialEventQueue, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "serialMsgQ Locked"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("%2d %d serialMsgQをロックしました %08x\n", osGetThreadId(NULL),
|
2022-04-09 00:20:23 +00:00
|
|
|
MQ_GET_COUNT(&padMgr->serialLockQueue), serialEventQueue);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
return serialEventQueue;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
void PadMgr_UnlockSerialMesgQueue(PadMgr* padMgr, OSMesgQueue* serialEventQueue) {
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "serialMsgQ Unlock"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("%2d %d serialMsgQロック解除します %08x %08x %08x\n", osGetThreadId(NULL),
|
2022-04-09 00:20:23 +00:00
|
|
|
MQ_GET_COUNT(&padMgr->serialLockQueue), padMgr, &padMgr->serialLockQueue, serialEventQueue);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(&padMgr->serialLockQueue, (OSMesg)serialEventQueue, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "serialMsgQ Unlocked"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("%2d %d serialMsgQロック解除しました %08x %08x %08x\n", osGetThreadId(NULL),
|
2022-04-09 00:20:23 +00:00
|
|
|
MQ_GET_COUNT(&padMgr->serialLockQueue), padMgr, &padMgr->serialLockQueue, serialEventQueue);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_LockPadData(PadMgr* padMgr) {
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&padMgr->lockQueue, NULL, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_UnlockPadData(PadMgr* padMgr) {
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(&padMgr->lockQueue, NULL, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_RumbleControl(PadMgr* padMgr) {
|
2020-04-14 17:17:25 +00:00
|
|
|
static u32 errcnt = 0;
|
2020-06-14 03:29:59 +00:00
|
|
|
static u32 frame;
|
2021-02-14 00:49:40 +00:00
|
|
|
s32 temp = 1;
|
2020-04-14 17:17:25 +00:00
|
|
|
s32 triedRumbleComm;
|
2022-04-09 00:20:23 +00:00
|
|
|
OSMesgQueue* serialEventQueue = PadMgr_LockSerialMesgQueue(padMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
s32 var4;
|
|
|
|
s32 i;
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
triedRumbleComm = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2021-02-14 00:49:40 +00:00
|
|
|
if (padMgr->ctrlrIsConnected[i]) {
|
|
|
|
if (padMgr->padStatus[i].status & 1) {
|
|
|
|
if (padMgr->pakType[i] == temp) {
|
|
|
|
if (padMgr->rumbleEnable[i] != 0) {
|
|
|
|
if (padMgr->rumbleCounter[i] < 3) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// clang-format off
|
|
|
|
if (1) {} osSyncPrintf(VT_FGCOL(YELLOW));
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
// "Vibration pack jumble jumble"?
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック ぶるぶるぶるぶる");
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
|
2021-12-01 00:08:57 +00:00
|
|
|
if (__osMotorAccess(&padMgr->pfs[i], temp) != 0) {
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->pakType[i] = 0;
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2021-09-28 23:53:56 +00:00
|
|
|
// "A communication error has occurred with the vibration pack"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックで通信エラーが発生しました");
|
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->rumbleCounter[i] = 3;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-18 00:09:21 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
triedRumbleComm = 1;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2021-02-14 00:49:40 +00:00
|
|
|
if (padMgr->rumbleCounter[i] != 0) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// clang-format off
|
|
|
|
if (1) {} osSyncPrintf(VT_FGCOL(YELLOW));
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
// "Stop vibration pack"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止");
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
|
2021-12-01 00:08:57 +00:00
|
|
|
if (osMotorStop(&padMgr->pfs[i]) != 0) {
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->pakType[i] = 0;
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "A communication error has occurred with the vibration pack"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックで通信エラーが発生しました");
|
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->rumbleCounter[i]--;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-18 00:09:21 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
triedRumbleComm = 1;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2021-02-14 00:49:40 +00:00
|
|
|
if (padMgr->pakType[i] != 0) {
|
|
|
|
if (padMgr->pakType[i] == 1) {
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "It seems that a vibration pack was pulled out"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックが抜かれたようです");
|
|
|
|
osSyncPrintf(VT_RST);
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->pakType[i] = 0;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "It seems that a controller pack that is not a vibration pack was pulled out"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1,
|
|
|
|
"振動パックではないコントローラパックが抜かれたようです");
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->pakType[i] = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
if (!triedRumbleComm) {
|
2020-06-14 03:29:59 +00:00
|
|
|
i = frame % 4;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
if (padMgr->ctrlrIsConnected[i] && (padMgr->padStatus[i].status & 1) && (padMgr->pakType[i] != 1)) {
|
2022-04-09 00:20:23 +00:00
|
|
|
var4 = osMotorInit(serialEventQueue, &padMgr->pfs[i], i);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (var4 == 0) {
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->pakType[i] = 1;
|
2021-12-01 00:08:57 +00:00
|
|
|
osMotorStart(&padMgr->pfs[i]);
|
|
|
|
osMotorStop(&padMgr->pfs[i]);
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "Recognized vibration pack"
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックを認識しました");
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (var4 == 11) {
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->pakType[i] = 2;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (var4 == 4) {
|
2020-04-14 17:17:25 +00:00
|
|
|
LOG_NUM("++errcnt", ++errcnt, "../padmgr.c", 282);
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "Controller pack communication error"
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "コントローラパックの通信エラー");
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
frame++;
|
2022-04-09 00:20:23 +00:00
|
|
|
PadMgr_UnlockSerialMesgQueue(padMgr, serialEventQueue);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_RumbleStop(PadMgr* padMgr) {
|
2020-03-17 04:31:30 +00:00
|
|
|
s32 i;
|
2022-04-09 00:20:23 +00:00
|
|
|
OSMesgQueue* serialEventQueue = PadMgr_LockSerialMesgQueue(padMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2022-04-09 00:20:23 +00:00
|
|
|
if (osMotorInit(serialEventQueue, &padMgr->pfs[i], i) == 0) {
|
2022-02-02 21:43:34 +00:00
|
|
|
if ((gFaultMgr.msgId == 0) && (padMgr->rumbleOnFrames != 0)) {
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Stop vibration pack"
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止");
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 00:08:57 +00:00
|
|
|
osMotorStop(&padMgr->pfs[i]);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
PadMgr_UnlockSerialMesgQueue(padMgr, serialEventQueue);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_RumbleReset(PadMgr* padMgr) {
|
|
|
|
padMgr->rumbleOffFrames = 3;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_RumbleSetSingle(PadMgr* padMgr, u32 ctrlr, u32 rumble) {
|
|
|
|
padMgr->rumbleEnable[ctrlr] = rumble;
|
|
|
|
padMgr->rumbleOnFrames = 240;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_RumbleSet(PadMgr* padMgr, u8* ctrlrRumbles) {
|
2020-04-14 17:17:25 +00:00
|
|
|
s32 i;
|
2020-06-14 03:29:59 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->rumbleEnable[i] = ctrlrRumbles[i];
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->rumbleOnFrames = 240;
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_ProcessInputs(PadMgr* padMgr) {
|
2020-04-14 17:17:25 +00:00
|
|
|
s32 i;
|
2020-06-14 03:29:59 +00:00
|
|
|
Input* input;
|
2020-10-03 15:22:44 +00:00
|
|
|
OSContPad* padnow1; // original name
|
2020-06-14 03:29:59 +00:00
|
|
|
s32 buttonDiff;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_LockPadData(padMgr);
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
input = &padMgr->inputs[0];
|
|
|
|
padnow1 = &padMgr->pads[0];
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
for (i = 0; i < padMgr->nControllers; i++, input++, padnow1++) {
|
2020-06-14 03:29:59 +00:00
|
|
|
input->prev = input->cur;
|
|
|
|
|
|
|
|
if (1) {} // Necessary to match
|
|
|
|
|
|
|
|
switch (padnow1->errno) {
|
|
|
|
case 0:
|
|
|
|
input->cur = *padnow1;
|
2021-02-14 00:49:40 +00:00
|
|
|
if (!padMgr->ctrlrIsConnected[i]) {
|
|
|
|
padMgr->ctrlrIsConnected[i] = true;
|
2020-06-14 03:29:59 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "認識しました"); // "Recognized"
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
input->cur = input->prev;
|
2021-02-14 00:49:40 +00:00
|
|
|
LOG_NUM("this->Key_switch[i]", padMgr->ctrlrIsConnected[i], "../padmgr.c", 380);
|
2020-06-14 03:29:59 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Overrun error occurred"
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "オーバーランエラーが発生");
|
2020-06-14 03:29:59 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
break;
|
|
|
|
case 8:
|
2020-10-03 15:22:44 +00:00
|
|
|
input->cur.button = 0;
|
|
|
|
input->cur.stick_x = 0;
|
|
|
|
input->cur.stick_y = 0;
|
2020-06-14 03:29:59 +00:00
|
|
|
input->cur.errno = padnow1->errno;
|
2021-02-14 00:49:40 +00:00
|
|
|
if (padMgr->ctrlrIsConnected[i]) {
|
|
|
|
padMgr->ctrlrIsConnected[i] = false;
|
|
|
|
padMgr->pakType[i] = 0;
|
|
|
|
padMgr->rumbleCounter[i] = 0xFF;
|
2020-06-14 03:29:59 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Do not respond"?
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "応答しません");
|
2020-06-14 03:29:59 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_HEX("padnow1->errno", padnow1->errno, "../padmgr.c", 396);
|
|
|
|
Fault_AddHungupAndCrash("../padmgr.c", 397);
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
buttonDiff = input->prev.button ^ input->cur.button;
|
|
|
|
input->press.button |= (u16)(buttonDiff & input->cur.button);
|
|
|
|
input->rel.button |= (u16)(buttonDiff & input->prev.button);
|
2020-05-25 21:18:14 +00:00
|
|
|
PadUtils_UpdateRelXY(input);
|
2020-10-03 15:22:44 +00:00
|
|
|
input->press.stick_x += (s8)(input->cur.stick_x - input->prev.stick_x);
|
|
|
|
input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y);
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_UnlockPadData(padMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_HandleRetraceMsg(PadMgr* padMgr) {
|
2020-06-14 03:29:59 +00:00
|
|
|
s32 i;
|
2022-04-09 00:20:23 +00:00
|
|
|
OSMesgQueue* serialEventQueue = PadMgr_LockSerialMesgQueue(padMgr);
|
2020-04-14 17:17:25 +00:00
|
|
|
u32 mask;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osContStartReadData(serialEventQueue);
|
2021-02-14 00:49:40 +00:00
|
|
|
if (padMgr->retraceCallback) {
|
|
|
|
padMgr->retraceCallback(padMgr, padMgr->retraceCallbackValue);
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(serialEventQueue, NULL, OS_MESG_BLOCK);
|
2021-02-14 00:49:40 +00:00
|
|
|
osContGetReadData(padMgr->pads);
|
|
|
|
if (padMgr->preNMIShutdown) {
|
|
|
|
bzero(padMgr->pads, sizeof(padMgr->pads));
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_ProcessInputs(padMgr);
|
2022-04-09 00:20:23 +00:00
|
|
|
osContStartQuery(serialEventQueue);
|
|
|
|
osRecvMesg(serialEventQueue, NULL, OS_MESG_BLOCK);
|
2021-02-14 00:49:40 +00:00
|
|
|
osContGetQuery(padMgr->padStatus);
|
2022-04-09 00:20:23 +00:00
|
|
|
PadMgr_UnlockSerialMesgQueue(padMgr, serialEventQueue);
|
2020-04-14 17:17:25 +00:00
|
|
|
|
|
|
|
mask = 0;
|
2020-06-14 03:29:59 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2021-02-14 00:49:40 +00:00
|
|
|
if (padMgr->padStatus[i].errno == 0) {
|
2021-12-07 14:17:48 +00:00
|
|
|
if (padMgr->padStatus[i].type == CONT_TYPE_NORMAL) {
|
2020-04-14 17:17:25 +00:00
|
|
|
mask |= 1 << i;
|
|
|
|
} else {
|
2021-02-14 00:49:40 +00:00
|
|
|
LOG_HEX("this->pad_status[i].type", padMgr->padStatus[i].type, "../padmgr.c", 458);
|
2020-06-14 03:29:59 +00:00
|
|
|
// "An unknown type of controller is connected"
|
2020-04-14 17:17:25 +00:00
|
|
|
osSyncPrintf("知らない種類のコントローラが接続されています\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->validCtrlrsMask = mask;
|
2020-04-14 17:17:25 +00:00
|
|
|
|
2022-02-02 21:43:34 +00:00
|
|
|
if (gFaultMgr.msgId != 0) {
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_RumbleStop(padMgr);
|
|
|
|
} else if (padMgr->rumbleOffFrames > 0) {
|
|
|
|
--padMgr->rumbleOffFrames;
|
|
|
|
PadMgr_RumbleStop(padMgr);
|
|
|
|
} else if (padMgr->rumbleOnFrames == 0) {
|
|
|
|
PadMgr_RumbleStop(padMgr);
|
|
|
|
} else if (!padMgr->preNMIShutdown) {
|
|
|
|
PadMgr_RumbleControl(padMgr);
|
|
|
|
--padMgr->rumbleOnFrames;
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_HandlePreNMI(PadMgr* padMgr) {
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf("padmgr_HandlePreNMI()\n");
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->preNMIShutdown = true;
|
|
|
|
PadMgr_RumbleReset(padMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_RequestPadData(PadMgr* padMgr, Input* inputs, s32 mode) {
|
2020-06-14 03:29:59 +00:00
|
|
|
s32 i;
|
|
|
|
Input* ogInput;
|
|
|
|
Input* newInput;
|
|
|
|
s32 buttonDiff;
|
2020-04-14 17:17:25 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_LockPadData(padMgr);
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
ogInput = &padMgr->inputs[0];
|
2020-06-14 03:29:59 +00:00
|
|
|
newInput = &inputs[0];
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (mode != 0) {
|
|
|
|
*newInput = *ogInput;
|
2020-10-03 15:22:44 +00:00
|
|
|
ogInput->press.button = 0;
|
|
|
|
ogInput->press.stick_x = 0;
|
|
|
|
ogInput->press.stick_y = 0;
|
|
|
|
ogInput->rel.button = 0;
|
2020-04-14 17:17:25 +00:00
|
|
|
} else {
|
2020-06-14 03:29:59 +00:00
|
|
|
newInput->prev = newInput->cur;
|
|
|
|
newInput->cur = ogInput->cur;
|
2020-10-03 15:22:44 +00:00
|
|
|
buttonDiff = newInput->prev.button ^ newInput->cur.button;
|
|
|
|
newInput->press.button = newInput->cur.button & buttonDiff;
|
|
|
|
newInput->rel.button = newInput->prev.button & buttonDiff;
|
2020-06-14 03:29:59 +00:00
|
|
|
PadUtils_UpdateRelXY(newInput);
|
2020-10-03 15:22:44 +00:00
|
|
|
newInput->press.stick_x += (s8)(newInput->cur.stick_x - newInput->prev.stick_x);
|
|
|
|
newInput->press.stick_y += (s8)(newInput->cur.stick_y - newInput->prev.stick_y);
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
ogInput++;
|
|
|
|
newInput++;
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_UnlockPadData(padMgr);
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_ThreadEntry(PadMgr* padMgr) {
|
2022-04-09 00:20:23 +00:00
|
|
|
s16* msg = NULL;
|
2020-04-14 17:17:25 +00:00
|
|
|
s32 exit;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("コントローラスレッド実行開始\n"); // "Controller thread execution start"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
exit = false;
|
2020-04-14 17:17:25 +00:00
|
|
|
while (!exit) {
|
2022-04-09 00:20:23 +00:00
|
|
|
if ((D_8012D280 > 2) && MQ_IS_EMPTY(&padMgr->interruptQueue)) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "Waiting for controller thread event"
|
2020-04-08 16:36:15 +00:00
|
|
|
osSyncPrintf("コントローラスレッドイベント待ち %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&padMgr->interruptQueue, (OSMesg*)&msg, OS_MESG_BLOCK);
|
|
|
|
LogUtils_CheckNullPointer("msg", msg, "../padmgr.c", 563);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
switch (*msg) {
|
2020-03-17 04:31:30 +00:00
|
|
|
case OS_SC_RETRACE_MSG:
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-04-08 16:36:15 +00:00
|
|
|
osSyncPrintf("padmgr_HandleRetraceMsg START %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_HandleRetraceMsg(padMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-04-08 16:36:15 +00:00
|
|
|
osSyncPrintf("padmgr_HandleRetraceMsg END %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case OS_SC_PRE_NMI_MSG:
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_HandlePreNMI(padMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
break;
|
|
|
|
case OS_SC_NMI_MSG:
|
2020-06-14 03:29:59 +00:00
|
|
|
exit = true;
|
2020-03-17 04:31:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
IrqMgr_RemoveClient(padMgr->irqMgr, &padMgr->irqClient);
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("コントローラスレッド実行終了\n"); // "Controller thread execution end"
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
void PadMgr_Init(PadMgr* padMgr, OSMesgQueue* serialEventQueue, IrqMgr* irqMgr, OSId id, OSPri priority, void* stack) {
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("パッドマネージャ作成 padmgr_Create()\n"); // "Pad Manager creation"
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
bzero(padMgr, sizeof(PadMgr));
|
|
|
|
padMgr->irqMgr = irqMgr;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateMesgQueue(&padMgr->interruptQueue, padMgr->interruptMsgBuf, ARRAY_COUNT(padMgr->interruptMsgBuf));
|
|
|
|
IrqMgr_AddClient(padMgr->irqMgr, &padMgr->irqClient, &padMgr->interruptQueue);
|
|
|
|
osCreateMesgQueue(&padMgr->serialLockQueue, padMgr->serialLockMsgBuf, ARRAY_COUNT(padMgr->serialLockMsgBuf));
|
|
|
|
PadMgr_UnlockSerialMesgQueue(padMgr, serialEventQueue);
|
|
|
|
osCreateMesgQueue(&padMgr->lockQueue, padMgr->lockMsgBuf, ARRAY_COUNT(padMgr->lockMsgBuf));
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_UnlockPadData(padMgr);
|
2022-04-09 00:20:23 +00:00
|
|
|
PadSetup_Init(serialEventQueue, (u8*)&padMgr->validCtrlrsMask, padMgr->padStatus);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
padMgr->nControllers = 4;
|
|
|
|
osContSetCh(padMgr->nControllers);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
osCreateThread(&padMgr->thread, id, (void (*)(void*))PadMgr_ThreadEntry, padMgr, stack, priority);
|
|
|
|
osStartThread(&padMgr->thread);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|