pyGame - Logitech rumble pad input OS X (10.3.9)

K

kjm

Hi everyone,

I have recently acquired a Logitech Rumble pad to use as an input
device. I have been having trouble getting the event que to respond
that a button or hat arrow has been pressed. This is on a system
running OS 10.3.9.

I have modified/written a small piece of code that initializes the
joystick, and pygame does recognize it. I was wondering if someone has
a small snippet of code to get me going? I have posted the code I'm
using to initialize the joystick, plus it's output below.

Versions are:

Version checklist:

Python version 2.3 (OK)
extra Python info: (#1, Sep 13 2003, 00:49:11) [GCC 3.3 20030304 (Apple
Computer, Inc. build 1495)]
Numeric version 24.0b1 (OK)
PyOpenGL (package "OpenGL") version 2.0.2.01 (OK)
pygame version 1.7.0 (OK)
Python Imaging Library (package "Image") version 1.1.5 (OK)



any help is appreciated.

Cheers,


kjm

[begin code]
-------------------------------------------------
import pygame
import pygame.display
import pygame.joystick
from pygame.locals import *

pygame.display.init()

pygame.joystick.init() #initialize joystick module
pygame.joystick.get_init() #verify initialization (boolean)

joystick_count = pygame.joystick.get_count()#get number of joysticks
print('%d joystick(s) connected' %joystick_count)#print number

joystick_object = pygame.joystick.Joystick(0)
#create an instance of a joystick
#first joystick is [0] in the list
#haven't had much luck with multiple joysticks

joystick_object.get_name()
print joystick_object.get_name()
#grab joystick name - flightstick, gravis...
#can (and is in this case) be done before initialization

joystick_object.init()

joystick_object.get_init()
#verify initialization (maybe cool to do some
#error trapping with this so game doesn't crash

num_axes = joystick_object.get_numaxes()
num_buttons = joystick_object.get_numbuttons()

print 'Joystick has %d axes and %d buttons' %(num_axes,num_buttons)

pygame.event.pump()
#necessary for os to pass joystick events

xaxis = joystick_object.get_axis(0)
yaxis = joystick_object.get_axis(1)
wheel = joystick_object.get_axis(2)
trigger = joystick_object.get_button(0)
top = joystick_object.get_button(1)
#from above, you have number of axes and buttons
#could assign more if your joystick has more

print '%f %f %f %d %d' %(xaxis, yaxis, wheel, trigger, top)
#print values to console for debugging
#analog channels (axes) range -1 to 1
#digital channels (buttons) are 1 or 0




joystick_object.quit()
#destroy objects and clean up
pygame.joystick.quit()

[/code]
------------------------------------------------------------------
[begin output]

[XXXXXXX@viridian 16:10:26]$ python testjoy.py
1 joystick(s) connected
Logitech Cordless RumblePad 2
Joystick has 4 axes and 12 buttons
-1.000000 -1.000000 -1.000000 0 0
[XXXXX@viridian 16:10:32]$

[/output]
 
T

Terry Hancock

I have modified/written a small piece of code that initializes the
joystick, and pygame does recognize it. I was wondering if someone has
a small snippet of code to get me going? I have posted the code I'm
using to initialize the joystick, plus it's output below.

First of all, you'd be much better off asking this question on
the pygame mailing list ( (e-mail address removed) ).

But ...
pygame.event.pump()
#necessary for os to pass joystick events

You understand, you have to call pygame.event.pump()
ONCE PER EVENT LOOP?

The code you posted doesn't do that. "pump" doesn't
start a separate thread or anything, it just polls the
event queue and runs some pygame code to update state.

You must repeatedly call it to check for events.

Pygame tries to be very straightforward and explicit.
There isn't much hidden "magic" going on (although
movie and sound objects *do* process things in background
threads).

Cheers,
Terry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top