FS#43746 - [python2-pygame] printf statements in joystick.c for SDL calls

Attached to Project: Arch Linux
Opened by Neil Munday (NeilMunday) - Sunday, 08 February 2015, 23:06 GMT
Last edited by Eric Belanger (Snowman) - Tuesday, 10 February 2015, 06:23 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Eric Belanger (Snowman)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:


When calling the various joystick.get_* functions from pygame, SDL calls are made in joystick.c. Unfortunately, a number of debug printf statements have been left in. This means that any pygame programs that call the joystick.get_* functions print loads of debug info to stdout which can be quite annoying.


Additional info:
* package version(s): extra/python2-pygame 1.9.1-8

Steps to reproduce:

Install the package and its dependencies, then run the following program (jstest.py) with a joystick connected:

#!/usr/bin/env python2
import sys
import os
import argparse
import signal
from signal import SIGTERM
import pygame
from pygame.locals import *

def stopTest(sig, dummy):
print "Exiting..."
sys.exit(0)

if __name__ == "__main__":

signal.signal(signal.SIGTERM, stopTest)
signal.signal(signal.SIGINT, stopTest)

parser = argparse.ArgumentParser(description='joystick detection test code', add_help=True)
parser.add_argument('-j', '--joystick', help='Joystick number to test', dest='jsNumber', type=int, required=True)
args = parser.parse_args()

os.environ["SDL_VIDEODRIVER"] = "dummy"

pygame.init()
pygame.joystick.init()

js = pygame.joystick.Joystick(args.jsNumber)
if js == None:
print "Error initialising joystick"
sys.exit(1)
js.init()
initialAxis = []
for i in range(0, js.get_numaxes()):
initialAxis.append(0)

print "\nListening for joystick events for joystick %d (%s), press Ctrl + C to exit" % (args.jsNumber, js.get_name())

stop = False
initialised = False
lastAxis = -1

print "Please press a button once your control pad's axes are in their rest positions"

while stop == False:

for event in pygame.event.get():
pass

# loop through buttons
for i in range(0, js.get_numbuttons()):
if js.get_button(i):
print "joystick %d, button %d pressed" % (args.jsNumber, i)
pygame.time.wait(10)

print "Exiting..."
sys.exit(0)

Now run it:

python2 ./jstest.py -j 0

Now press any buttons on the joystick and you will see:

SDL_JoystickGetButton value

print many times!

Here's a patch for src/joystick.c included in the PyGame source tar ball:

--- joystick.c-orig 2009-05-26 22:15:24.000000000 +0100
+++ joystick.c 2015-02-08 23:03:49.908606516 +0000
@@ -201,8 +201,6 @@
}

value = SDL_JoystickGetAxis (joy, axis);
- printf("SDL_JoystickGetAxis value:%d:\n", value);
-

return PyFloat_FromDouble (value / 32768.0);
}
@@ -241,8 +239,6 @@
}

value = SDL_JoystickGetButton (joy, _index);
- printf("SDL_JoystickGetButton value:%d:\n", value);
-
return PyInt_FromLong (value);
}

@@ -277,7 +273,6 @@
return RAISE (PyExc_SDLError, "Joystick not initialized");
}
value = SDL_JoystickNumBalls (joy);
- printf("SDL_JoystickNumBalls value:%d:\n", value);

if (_index < 0 || _index >= value) {
return RAISE (PyExc_SDLError, "Invalid joystick trackball");
@@ -300,7 +295,6 @@
}

value = SDL_JoystickNumHats (joy);
- printf("SDL_JoystickNumHats value:%d:\n", value);

return PyInt_FromLong (value);
}
@@ -327,7 +321,6 @@

px = py = 0;
value = SDL_JoystickGetHat (joy, _index);
- printf("SDL_JoystickGetHat value:%d:\n", value);

if (value & SDL_HAT_UP) {
py = 1;


It would be great if this patch could be included in a revised version of this package.

Thanks,

Neil.
This task depends upon

Closed by  Eric Belanger (Snowman)
Tuesday, 10 February 2015, 06:23 GMT
Reason for closing:  Fixed
Additional comments about closing:  python2-pygame-1.9.1-9
Comment by Neil Munday (NeilMunday) - Sunday, 08 February 2015, 23:16 GMT
Here is the test Python program.

Loading...