-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.c
65 lines (56 loc) · 1.26 KB
/
controller.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <libpad.h>
#include <stdio.h>
#include <tamtypes.h>
#include "controller.h"
#include <kernel.h>
static char padBuff[256] __attribute__((aligned(64)));
u32 PadData = 0;
void InitPad()
{
int ret;
padInit(0);
ret = padPortOpen(0, 0, padBuff);
if(ret == 0)
{
printf("padOpenPort failed\n");
SleepThread();
}
WaitPadReady(0, 0);
//We only need barebones pad functionality.
}
int WaitPadReady(int port, int slot)
{
int state;
int lastState;
state = padGetState(port, slot);
lastState = -1;
printf("Waiting for PAD...\n");
while((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1))
{
state=padGetState(port, slot);
}
if(lastState != -1)
{
printf("Pad OK!\n");
}
return 0;
}
static u32 oldPad;
u32 GetPad()
{
struct padButtonStatus buttons;
int ret = padGetState(0, 0);
while((ret != PAD_STATE_STABLE) && (ret != PAD_STATE_FINDCTP1))
{
if(ret==PAD_STATE_DISCONN)
{
printf("Controller Disconnected...\n");
}
ret = padGetState(0, 0);
}
ret = padRead(0, 0, &buttons);
u32 paddata = 0xFFFF ^ buttons.btns;
u32 newButtons = paddata & ~oldPad;
oldPad = paddata;
return newButtons;
}