140
|
1 #include <SDL.h>
|
|
2 #include "Joystick.h"
|
|
3
|
191
|
4 /**
|
|
5 * PS3 コントローラの配置
|
|
6 */
|
|
7 static const int SELECT = 0;
|
|
8 static const int L3 = 1;
|
|
9 static const int R3 = 2;
|
|
10 static const int START = 3;
|
|
11 static const int UP = 4;
|
|
12 static const int RIGHT = 5;
|
|
13 static const int DOWN = 6;
|
|
14 static const int LEFT = 7;
|
|
15 static const int L2 = 8;
|
|
16 static const int R2 = 9;
|
|
17 static const int L1 = 10;
|
|
18 static const int R1 = 11;
|
|
19 static const int TRIANGLE = 12;
|
|
20 static const int CIRCLE = 13;
|
|
21 static const int CROSS = 14;
|
|
22 static const int SQUARE = 15;
|
|
23 static const int PS = 16;
|
|
24
|
|
25 #if 0
|
140
|
26 static const int CROSS = 0;
|
|
27 static const int CIRCLE = 1;
|
|
28 static const int SQUARE = 2;
|
|
29 static const int TRIANGLE = 3;
|
|
30 static const int L1 = 4;
|
|
31 static const int R1 = 5;
|
|
32 static const int L2 = 6;
|
|
33 static const int R2 = 7;
|
|
34 static const int START = 8;
|
|
35 static const int SELECT = 9;
|
|
36 static const int L3 = 10;
|
|
37 static const int R3 = 11;
|
|
38 static const int UP = 12;
|
|
39 static const int DOWN = 13;
|
|
40 static const int RIGHT = 14;
|
|
41 static const int LEFT = 15;
|
|
42 static const int ESCAPE = 16;
|
|
43 static const int SPACE = 17;
|
191
|
44 #endif
|
140
|
45
|
|
46 Joystick::Joystick(SDL_Joystick *j)
|
|
47 {
|
|
48 joy = j;
|
|
49 }
|
|
50
|
|
51 void
|
|
52 Joystick::check(void)
|
|
53 {
|
|
54 SDL_JoystickUpdate();
|
|
55
|
|
56 if (SDL_JoystickGetButton(joy,CROSS)==SDL_PRESSED) {
|
|
57 cross.push_work();
|
|
58 } else {
|
|
59 cross.release_work();
|
|
60 }
|
|
61
|
|
62 if (SDL_JoystickGetButton(joy,CIRCLE)==SDL_PRESSED) {
|
|
63 circle.push_work();
|
|
64 } else {
|
|
65 circle.release_work();
|
|
66 }
|
|
67
|
|
68 if (SDL_JoystickGetButton(joy,SQUARE)==SDL_PRESSED) {
|
|
69 square.push_work();
|
|
70 } else {
|
|
71 square.release_work();
|
|
72 }
|
|
73
|
|
74 if (SDL_JoystickGetButton(joy,TRIANGLE)==SDL_PRESSED) {
|
|
75 triangle.push_work();
|
|
76 } else {
|
|
77 triangle.release_work();
|
|
78 }
|
|
79
|
|
80 if (SDL_JoystickGetButton(joy,L1)==SDL_PRESSED) {
|
|
81 l1.push_work();
|
|
82 } else {
|
|
83 l1.release_work();
|
|
84 }
|
|
85
|
|
86 if (SDL_JoystickGetButton(joy,R1)==SDL_PRESSED) {
|
|
87 r1.push_work();
|
|
88 } else {
|
|
89 r1.release_work();
|
|
90 }
|
|
91
|
|
92 if (SDL_JoystickGetButton(joy,L2)==SDL_PRESSED) {
|
|
93 l2.push_work();
|
|
94 } else {
|
|
95 l2.release_work();
|
|
96 }
|
|
97
|
|
98 if (SDL_JoystickGetButton(joy,R2)==SDL_PRESSED) {
|
|
99 r2.push_work();
|
|
100 } else {
|
|
101 r2.release_work();
|
|
102 }
|
|
103
|
|
104 if (SDL_JoystickGetButton(joy,START)==SDL_PRESSED) {
|
|
105 start.push_work();
|
|
106 } else {
|
|
107 start.release_work();
|
|
108 }
|
|
109
|
|
110 if (SDL_JoystickGetButton(joy,SELECT)==SDL_PRESSED) {
|
|
111 select.push_work();
|
|
112 } else {
|
|
113 select.release_work();
|
|
114 }
|
|
115
|
|
116 if (SDL_JoystickGetButton(joy,L3)==SDL_PRESSED) {
|
|
117 l3.push_work();
|
|
118 } else {
|
|
119 l3.release_work();
|
|
120 }
|
|
121
|
|
122 if (SDL_JoystickGetButton(joy,R3)==SDL_PRESSED) {
|
|
123 r3.push_work();
|
|
124 } else {
|
|
125 r3.release_work();
|
|
126 }
|
|
127
|
191
|
128 if (SDL_JoystickGetButton(joy,UP)==SDL_PRESSED) {
|
|
129 up.push_work();
|
|
130 } else {
|
|
131 up.release_work();
|
|
132 }
|
|
133
|
|
134 if (SDL_JoystickGetButton(joy,DOWN)==SDL_PRESSED) {
|
|
135 down.push_work();
|
|
136 } else {
|
|
137 down.release_work();
|
|
138 }
|
|
139 if (SDL_JoystickGetButton(joy,RIGHT)==SDL_PRESSED) {
|
|
140 right.push_work();
|
|
141 } else {
|
|
142 right.release_work();
|
|
143 }
|
|
144 if (SDL_JoystickGetButton(joy,LEFT)==SDL_PRESSED) {
|
|
145 left.push_work();
|
|
146 } else {
|
|
147 left.release_work();
|
|
148 }
|
|
149
|
140
|
150 axis = SDL_JoystickGetAxis(joy,0);
|
|
151 if (axis >= 3200) {
|
|
152 left.release_work();
|
|
153 right.push_work();
|
|
154 } else if (axis <= -3200) {
|
|
155 right.release_work();
|
|
156 left.push_work();
|
|
157 } else {
|
|
158 left.release_work();
|
|
159 right.release_work();
|
|
160 }
|
|
161
|
|
162 axis = SDL_JoystickGetAxis(joy,1);
|
|
163 if (axis>=3200) {
|
|
164 up.release_work();
|
|
165 down.push_work();
|
|
166 } else if (axis<=-3200) {
|
|
167 down.release_work();
|
|
168 up.push_work();
|
|
169 } else {
|
|
170 up.release_work();
|
|
171 down.release_work();
|
|
172 }
|
|
173 }
|
|
174
|
|
175 void
|
|
176 Joystick::close(void)
|
|
177 {
|
|
178 SDL_JoystickClose(joy);
|
|
179 }
|