annotate TaskManager/Test/test_render/Joystick.cpp @ 140:861271089c43

add Controller
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Fri, 28 Nov 2008 15:24:55 +0900
parents
children 5e3b0405a44b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
140
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 #include <SDL.h>
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
2 #include "Joystick.h"
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
3
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 static const int CROSS = 0;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
5 static const int CIRCLE = 1;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6 static const int SQUARE = 2;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 static const int TRIANGLE = 3;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
8 static const int L1 = 4;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 static const int R1 = 5;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 static const int L2 = 6;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 static const int R2 = 7;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12 static const int START = 8;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13 static const int SELECT = 9;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
14 static const int L3 = 10;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
15 static const int R3 = 11;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 static const int UP = 12;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
17 static const int DOWN = 13;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
18 static const int RIGHT = 14;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
19 static const int LEFT = 15;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
20 static const int ESCAPE = 16;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
21 static const int SPACE = 17;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
22
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
23 Joystick::Joystick(SDL_Joystick *j)
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
24 {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
25 joy = j;
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
26 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
27
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
28 void
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
29 Joystick::check(void)
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
30 {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
31 SDL_JoystickUpdate();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
32
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
33 if (SDL_JoystickGetButton(joy,CROSS)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 cross.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 cross.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
38
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 if (SDL_JoystickGetButton(joy,CIRCLE)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40 circle.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
41 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
42 circle.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
43 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
45 if (SDL_JoystickGetButton(joy,SQUARE)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 square.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48 square.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 if (SDL_JoystickGetButton(joy,TRIANGLE)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 triangle.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
54 triangle.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 if (SDL_JoystickGetButton(joy,L1)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 l1.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
60 l1.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 if (SDL_JoystickGetButton(joy,R1)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 r1.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
66 r1.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
67 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
68
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
69 if (SDL_JoystickGetButton(joy,L2)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
70 l2.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
71 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
72 l2.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
73 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
74
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
75 if (SDL_JoystickGetButton(joy,R2)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
76 r2.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
77 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
78 r2.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
79 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
80
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
81 if (SDL_JoystickGetButton(joy,START)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
82 start.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
83 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
84 start.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
85 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
86
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
87 if (SDL_JoystickGetButton(joy,SELECT)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
88 select.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
89 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
90 select.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
91 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
92
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
93 if (SDL_JoystickGetButton(joy,L3)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
94 l3.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
95 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
96 l3.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
97 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
98
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
99 if (SDL_JoystickGetButton(joy,R3)==SDL_PRESSED) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
100 r3.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
101 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
102 r3.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
103 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
104
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
105 axis = SDL_JoystickGetAxis(joy,0);
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
106 if (axis >= 3200) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
107 left.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
108 right.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
109 } else if (axis <= -3200) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
110 right.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
111 left.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
112 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
113 left.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
114 right.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
115 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
116
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
117 axis = SDL_JoystickGetAxis(joy,1);
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
118 if (axis>=3200) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
119 up.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
120 down.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
121 } else if (axis<=-3200) {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
122 down.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
123 up.push_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
124 } else {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
125 up.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
126 down.release_work();
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
127 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
128 }
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
129
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
130 void
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
131 Joystick::close(void)
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
132 {
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
133 SDL_JoystickClose(joy);
861271089c43 add Controller
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
134 }