| Games and SDL SDL Installation SDL for Embedded SDL API SDL Events | SDL Graphics SDL Threads Thread Example SDL Animation SDL Sound | Raw Video Player Video Formats Video Compression | Game Trees About The Author |
SDL for Embedded Systems
Mouse and TS have similar input mechanisms. For latest Linux versions, the devices in general can be accessed via
For backward compatibility, the mouse may also be accessed via /dev/input/mice, /dev/input/mouse0, or /dev/input/mouse1, etc
You could test if the mouse works by the executing the command,
In an ARM-9 board, most likely you can only see
SDL mouse support
You need to modify the following three files located at src/video/fbcon of the SDL source code tree:
static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat)
...
#ifdef __ARM__
if ( FB_OpenEventX(this) == 0 ) {
SDL_SetError("Unable to open /dev/input/eventX");
FB_VideoQuit(this);
return(-1);
}
#else
//PC original code
#endif
|
static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat) extern int FB_OpenEventX(_THIS); extern void FB_CloseEventX(_THIS); extern void FB_vgamousecallback(int button, int relative, int dx, int dy); |
#include <linux/input.h>
....
static int event0_fd = -1;
static int event1_fd = -1;
struct input_event ev0[64];
struct input_event ev1[64];
//for handling TS
static void handle_event0(_THIS)
{
int button=0, x=0, y=0, realx=0, realy=0, i, rd;
rd = read(event0_fd, ev0, sizeof(struct input_event) * 64);
if( rd < sizeof(struct input_event) ) return;
for (i = 0; i < rd / sizeof(struct input_event); i++)
{
if(ev0[i].type == 3 && ev0[i].code == 0) x = ev0[i].value;
else if(ev0[i].type == 3 && ev0[i].code == 1) y = ev0[i].value;
else if(ev0[i].type == 1 && ev0[i].code == 330) button = ev0[i].value << 2;
else if(ev0[i].type == 0 && ev0[i].code == 0 && ev0[i].value == 0)
{
//need to define numbers in header for flexibility
realx = (950-y)*240/(950-70);
realy = (x-70)*320/(950-70);
if( realx < 0 ) realx = 0;
if( realx > 240 ) realx = 240;
if( realy < 0 ) realy = 0;
if( realy > 320 )realx = 320;
FB_vgamousecallback(button, 0, realx, realy);
}
}
return;
}
//for handling mouse
static void handle_event1(_THIS)
{
int button=0, x=0, y=0, i, rd;
rd = read(event1_fd, ev1, sizeof(struct input_event) * 64);
if( rd < sizeof(struct input_event) ) return;
for (i = 0; i < rd / sizeof(struct input_event); i++)
{
if(ev1[i].type == 2 && ev1[i].code == 0) x = ev1[i].value;
else if(ev1[i].type == 2 && ev1[i].code == 1) y = ev1[i].value;
else if(ev1[i].type == 1) {
if(ev1[i].code == 272) {
button &= ~0x4;
button |= ev1[i].value << 2;
} else if(ev1[i].code == 273) {
button &= ~0x1;
button |= ev1[i].value;
} else if(ev1[i].code == 274) {
button &= ~0x2;
button |= ev1[i].value << 1;
}
} else if(ev1[i].type == 0 && ev1[i].code == 0 && ev1[i].value == 0) {
FB_vgamousecallback(button, 1, x, y);
x=0, y=0;
}
}
return;
}
int FB_OpenEventX(_THIS)
{
event0_fd = open("/dev/input/event0", O_RDWR);
event1_fd = open("/dev/input/event1", O_RDWR);
if(event0_fd < 0 && event1_fd < 0)
return 0;
return 1;
}
void FB_CloseEventX(_THIS)
{
if ( event0_fd > 0 ) {
close(event0_fd);
}
if ( event1_fd > 0 ) {
close(event1_fd);
}
event0_fd = -1;
event1_fd = -1;
}
....
|
After you've made the above modifications, recompile the SDL library as discussed in the previous chapters. The new library will support both USB mouse and touch screen.