My favorites
|
Sign in
supersnippets
Supersnippets by Sole!
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
r20
Source path:
svn
/
trunk
/
psp
/
01_buttons
/
main.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
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
// Soledad Penades http://soledadpenades.com
#include <stdlib.h>
#include "SDL.h"
#include "SDL_main.h"
#ifdef PSP
#include <pspdebug.h>
#define printf pspDebugScreenPrintf
#else
#include <stdio.h>
#endif
#define W 480
#define H 272
SDL_Surface *screen;
void printJoystickInfo(SDL_Joystick *joystick)
{
int index;
index = SDL_JoystickIndex(joystick);
printf( "JOYSTICK INFO\n\n"
"Index: %d\n"
"Name: %s\n"
"Num axes: %d\n"
"Num balls: %d\n"
"Num hats: %d\n"
"Num buttons: %d\n",
index,
SDL_JoystickName(index),
SDL_JoystickNumAxes(joystick),
SDL_JoystickNumBalls(joystick),
SDL_JoystickNumHats(joystick),
SDL_JoystickNumButtons(joystick)
);
}
int main(int argc, char *argv[])
{
SDL_Joystick *joystick = NULL;
SDL_Event event;
int done = 0;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
{
printf("init error: %s\n", SDL_GetError());
return 1;
}
if((screen = SDL_SetVideoMode(W, H, 32, 0)) == NULL)
{
printf("SetVideoMode: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(1000);
if(SDL_NumJoysticks())
{
joystick = SDL_JoystickOpen(0);
printJoystickInfo(joystick);
}
else
{
printf("No joystick detected\n");
}
done = 0;
while(!done)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_JOYBUTTONDOWN:
printf("Pressed button %d\n", event.jbutton.button);
break;
case SDL_JOYAXISMOTION:
printf("Axis motion: j index = %d axis = %d value = %d\n", event.jaxis.which, event.jaxis.axis, event.jaxis.value);
break;
case SDL_QUIT:
done = 1;
break;
}
}
}
if(joystick)
{
SDL_JoystickClose(joystick);
}
SDL_Quit();
return(0);
}
Show details
Hide details
Change log
r15
by supersole on Sep 02, 2008
Diff
psp in
Go to:
/trunk/psp
/trunk/psp/01_buttons
/trunk/psp/01_buttons/main.c
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1676 bytes, 98 lines
View raw file
Hosted by