view test/testhread.c @ 892:dc29e5907694

Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT) From: David MacCormack Subject: [SDL] Linux joystick patch I recently got myself a PS2 -> USB converter (a super joybox 5). It accepts 4 PSX/PS2 controllers. It's implemented as a HID, which is nice because it doesn't require its own driver, but the problem is that it's implemented as a *single* HID -- that is, it shows up as a single joystick with 19 axes, 4 hats, and 48 buttons. This poses a problem for a number of apps which use SDL (stella, fce ultra, zsnes, to name a few) and see only a single (physical) joystick even though there are really 4 (logical) joysticks. There are a number of these types of devices on the market, and I've seen others post messages (in the zsnes forum, for example) with the same problem, so I came up with what I think is a pretty generic solution. I patched src/joystick/linux/SDL_sysjoystic.c to include support for logical joysticks; basically, it's a static array and supporting functions that map a single physical joystick to multiple logical joysticks. The attached patch has the new code. It's wrapped inside #ifndef statements so that you can get the old behavior if you want.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 16 May 2004 18:46:24 +0000
parents 74212992fb08
children be9c9c8f6d53
line wrap: on
line source


/* Simple test of the SDL threading code */

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include "SDL.h"
#include "SDL_thread.h"

static int alive = 0;

int ThreadFunc(void *data)
{
	printf("Started thread %s: My thread id is %u\n",
				(char *)data, SDL_ThreadID());
	while ( alive ) {
		printf("Thread '%s' is alive!\n", (char *)data);
		SDL_Delay(1*1000);
	}
	printf("Thread '%s' exiting!\n", (char *)data);
	return(0);
}

static void killed(int sig)
{
	printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
	SDL_Delay(5*1000);
	alive = 0;
	exit(0);
}

int main(int argc, char *argv[])
{
	SDL_Thread *thread;

	/* Load the SDL library */
	if ( SDL_Init(0) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		exit(1);
	}
	atexit(SDL_Quit);

	alive = 1;
	thread = SDL_CreateThread(ThreadFunc, "#1");
	if ( thread == NULL ) {
		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
		exit(1);
	}
	SDL_Delay(5*1000);
	printf("Waiting for thread #1\n");
	alive = 0;
	SDL_WaitThread(thread, NULL);

	alive = 1;
	thread = SDL_CreateThread(ThreadFunc, "#2");
	if ( thread == NULL ) {
		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
		exit(1);
	}
	SDL_Delay(5*1000);
	printf("Killing thread #2\n");
	SDL_KillThread(thread);

	alive = 1;
	signal(SIGTERM, killed);
	thread = SDL_CreateThread(ThreadFunc, "#3");
	if ( thread == NULL ) {
		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
		exit(1);
	}
	raise(SIGTERM);

	return(0);	/* Never reached */
}