forked from drizzt/GaiaManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_pad.cpp
111 lines (90 loc) · 2.04 KB
/
input_pad.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "input_pad.h"
#include <cell/pad/libpad.h>
//#include <cell/pad/error.h>
#define CELL_OK 0 // include cell pad error.h didn't works, and was just neede by this
InputPad * InputPad::instance = 0;
int InputPad::init(void)
{
return cellPadInit(1);
}
InputPad* InputPad::getSingle( void)
{
if( instance == 0)
instance = new InputPad();
return instance;
}
void InputPad::free( void)
{
delete instance;
instance = 0;
cellPadEnd();
}
InputPad::InputPad()
{
old_info = 0;
new_pad = 0;
old_pad = 0;
}
int InputPad::read(void)
{
int ret;
u32 padd;
CellPadData databuf;
#if (CELL_SDK_VERSION<=0x210001)
CellPadInfo infobuf;
#else
CellPadInfo2 infobuf;
#endif
#if (CELL_SDK_VERSION<=0x210001)
ret = cellPadGetInfo(&infobuf);
#else
ret = cellPadGetInfo2(&infobuf);
#endif
if (ret != 0) {
old_pad = new_pad = 0;
return 1;
}
#if (CELL_SDK_VERSION<=0x210001)
if (infobuf.status[0] == CELL_PAD_STATUS_DISCONNECTED) {
#else
if (infobuf.port_status[0] == CELL_PAD_STATUS_DISCONNECTED) {
#endif
old_pad = new_pad = 0;
return 1;
}
#if (CELL_SDK_VERSION<=0x210001)
if ((infobuf.info & CELL_PAD_INFO_INTERCEPTED)
&& (!(old_info & CELL_PAD_INFO_INTERCEPTED))) {
old_info = infobuf.info;
} else if ((!(infobuf.info & CELL_PAD_INFO_INTERCEPTED))
&& (old_info & CELL_PAD_INFO_INTERCEPTED)) {
old_info = infobuf.info;
old_pad = new_pad = 0;
return 1;
}
#else
if ((infobuf.system_info & CELL_PAD_INFO_INTERCEPTED)
&& (!(old_info & CELL_PAD_INFO_INTERCEPTED))) {
old_info = infobuf.system_info;
} else if ((!(infobuf.system_info & CELL_PAD_INFO_INTERCEPTED))
&& (old_info & CELL_PAD_INFO_INTERCEPTED)) {
old_info = infobuf.system_info;
old_pad = new_pad = 0;
return 1;
}
#endif
ret = cellPadGetData(0, &databuf);
if (ret != CELL_OK) {
old_pad = new_pad = 0;
return 1;
}
if (databuf.len == 0) {
new_pad = 0;
return 1;
}
padd = (databuf.button[2] | (databuf.button[3] << 8));
new_pad = padd & (~old_pad);
old_pad = padd;
return 1;
}
/* vim: set ts=4 sw=4 sts=4 tw=120 */