[Solved-ish] Using the nubs as joysticks


Fworg64

Who knows?
Joined
Apr 27, 2011
Messages
196
Location
Fargo, ND
First off, if this belongs in the C/C++ section go ahead and move it, figured I'd get better attention here :p


I'm trying to use the nubs as joysticks with allegro, and so far its not going very good. I can't seem to get any values from them at all.


Well, heres my code:


run.sh (used to run it when i throw it into a .pnd, been running it from this for testing)


Nub mode code conveniently stolen from mupen :p



Code:
#!/bin/sh

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/utmp/pfoiy


NUB0MODE=`cat /proc/pandora/nub0/mode`

NUB1MODE=`cat /proc/pandora/nub1/mode`

echo absolute > /proc/pandora/nub0/mode

echo absolute > /proc/pandora/nub1/mode


./pfoiy


echo $NUB0MODE > /proc/pandora/nub0/mode

echo $NUB1MODE > /proc/pandora/nub1/mode



Actual C++/Allegro code: (the important stuff anyway)



Code:
int main()

{

	allegro_init();

	install_keyboard();

	install_timer();

	install_pmask();

	//install_mouse();

	install_joystick(JOY_TYPE_AUTODETECT);

	calibrate_joystick(0);

	set_color_depth(32);

	if (set_gfx_mode(GFX_AUTODETECT, WIDTH, HEIGHT, 0, 0) < 0)

	{

   		allegro_message("Couldn't set gfx mode: %s\n", allegro_error);

   		return 1;

	}

	show_mouse(NULL);

	title();

	//delete_bitmap(buffer);

}



calls this funtion



Code:
void title()

{

	int a=40;

	//clear_to_color(screen,makecol(0,0,0));

	border = load_bmp("titlescreen.bmp",NULL);

	blit(border,screen,0,0,0,0,800,480);

	textprintf_ex(screen,font, 40,40,makecol(255,255,255),-1,"Play");

	textprintf_ex(screen,font, 40,50,makecol(255,255,255),-1,"Difficulty");

	textprintf_ex(screen,font, 40,60,makecol(255,255,255),-1,"Quit");

	textprintf_ex(screen,font, 200,200,makecol(255,255,255),-1,"You are the BLUE CIRCLE,");

	textprintf_ex(screen,font, 200,210,makecol(255,255,255),-1,"use the D-pad to avoid the RED TRIANGLE");

	textprintf_ex(screen,font, 200,220,makecol(255,255,255),-1,"and get the GREEN SQUARE.");


	//const char *msg = calibrate_joystick_name(0);

	//textprintf_ex(screen,font,40,390,makecol(255,255,255),-1,"%s  ",msg); GIANT WTF

	textprintf_ex(screen,font,40,400,makecol(255,255,255),-1,"Flags: %d, numsticks: %d, numbuttons: %d",joy[0].flags,joy[0].num_sticks,joy[0].num_buttons);

	textprintf_ex(screen,font,40,410,makecol(255,255,255),-1,"Flags: %d, numaxis: %d, name: %s",joy[0].stick[0].flags,joy[0].stick[0].num_axis,joy[0].stick[0].name);

	rest(100);

	while (true)

	{

    	rest(90);

    	blit(border,screen,0,0,0,0,39,70);

    	blit(border,screen,40,420,40,420,700,440);

        poll_joystick();

        textprintf_ex(screen,font,40,420,makecol(255,255,255),-1,"analogue pos: %d, digpos: %d:%d, name:%s",joy[0].stick[0].axis[0].pos,joy[0].stick[0].axis[0].d1,joy[0].stick[0].axis[0].d2,joy[0].stick[0].axis[0].name);

    	textprintf_ex(screen,font,40,430,makecol(255,255,255),-1,"analogue pos: %d, digpos: %d:%d, name: %s",joy[0].stick[0].axis[1].pos,joy[0].stick[0].axis[1].d1,joy[0].stick[0].axis[1].d2,joy[0].stick[0].axis[1].name);

    	if (key[KEY_UP] && a != 40) a-=10;

    	if (key[KEY_DOWN] && a != 60) a+=10;

    	textprintf_ex(screen,font, 30,a,makecol(255,255,255),-1,">");

    	if ((key[KEY_ENTER] || key[KEY_PGDN] || key[KEY_PGUP] || key[KEY_END] || key[KEY_HOME] || key[KEY_ALT]) && a == 60) exit(0);

    	if ((key[KEY_ENTER] || key[KEY_PGDN] || key[KEY_PGUP] || key[KEY_END] || key[KEY_HOME] || key[KEY_ALT]) && a == 40) reset();

    	if ((key[KEY_ENTER] || key[KEY_PGDN] || key[KEY_PGUP] || key[KEY_END] || key[KEY_HOME] || key[KEY_ALT]) && a == 50) options();

	}

}


The problem is that no matter what i seem to do i cant get a reading form axis[0].pos or axis[1].pos.


And I tried the whole calibrate_joystick_name() thing, but my compiler yelled at me :(


I feel like i'm either initializing them wrong, or calibrating them wrong.


Any suggestions?
 
Last edited by a moderator:

mcobit

Advanced Member
Joined
Jul 28, 2008
Messages
6,910
allegro detects the first joystick, but joy0 is a nonexisting decice on pandora. You have to make joy1 to be joy0 in your /dev folder.


I know, not convenient, but try. A symlink should work.
 

Fworg64

Who knows?
Joined
Apr 27, 2011
Messages
196
Location
Fargo, ND
so if joy0 does not exist, may i just change my call from joy0 to joy1, as opposed to changing joy1 to joy0? I need it to work in a .pnd, hopefully without too much trickery.


Also just out of curiosity, how does that work if i would need 2 joy sticks? is it joy1 and joy2, not joy0 and joy1?


thanks for the help!


EDIT:: after poking around in my /dev folder i seem to have reached an epiphany, they file joy0 is always present for some reason, and joy1 and joy2 are present when the nubs are set to joystick mode... tricky tricky


EDITEDIT:: thanks for the pointer mcobit! got it all figured out now, but im still curious as to why the file joy0 hangs around when in mouse mode, and why mouse0 hangs around whilst in joystick mode.


EDITEDITEDIT:: well now this is wierd, it seems like the joysticks only work if i sudo the run.sh i set up, how can i get around this?
 
Last edited by a moderator:

Caine

Hardcore Member
Joined
Jun 5, 2008
Messages
4,138
Location
Netherlands
Yes, the joy0 device is an odd one. Also remember that the joystick devices are assigned IDs in first-come first-serve order. So if a user has an external joystick attached those nubs might become js2 and js3. There is no guarantee either that js1 is the left nub and js2 is the right.

EDITEDITEDIT:: well now this is wierd, it seems like the joysticks only work if i sudo the run.sh i set up, how can i get around this?
My nubconfigurator does essentially the same as that script you wrote. I don't recall it ever needing super-user rights to change to joystick mode (only for resetting the nub driver).
 
Last edited by a moderator:

Fworg64

Who knows?
Joined
Apr 27, 2011
Messages
196
Location
Fargo, ND
I dont see why it would need su rights either, but the fact reamains that if i just run "./run.sh" joy1 doesnt seem to work, but when i run "sudo ./run.sh" it does....


I'll look into this later tonight, however i am still terribly confused :p


EDIT:: how queer... when i bindle it into a .pnd, the joystick issue resolves itself, no su rights or anything... just works... "whatevs"
 
Last edited by a moderator:
Top