Author: duncan
Date: Sat Feb 24 13:42:50 2007
New Revision: 9265
Modified:
branches/rel-1/freevo/src/plugins/joy.py
Log:
Added changes for PS3 usage
Modified: branches/rel-1/freevo/src/plugins/joy.py
==============================================================================
--- branches/rel-1/freevo/src/plugins/joy.py (original)
+++ branches/rel-1/freevo/src/plugins/joy.py Sat Feb 24 13:42:50 2007
@@ -5,13 +5,13 @@
# $Id$
#
# Notes:
-# To use this plugin make sure that your joystick is already working
+# To use this plugin make sure that your joystick is already working
# properly and then configure JOY_DEV and JOY_CMDS in your local_conf.py.
# You will also need to have plugin.activate('joy') in your config as well.
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
-# Copyright (C) 2003 Krister Lagerstrom, et al.
+# Copyright (C) 2003 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
@@ -49,7 +49,7 @@
def __init__(self):
self.device_name = ''
self.enabled = True
-
+
if config.JOY_DEV == 0:
self.reason = 'Joystick input module disabled'
return
@@ -59,7 +59,7 @@
try:
self.joyfd = os.open(self.device_name, os.O_RDONLY|os.O_NONBLOCK)
except OSError:
-
+
print 'Unable to open %s, trying /dev/js%s...' % \
(self.device_name, str((config.JOY_DEV - 1)))
self.device_name = '/dev/js' + str((config.JOY_DEV - 1))
@@ -75,22 +75,32 @@
# ok, joystick is working
plugin.DaemonPlugin.__init__(self)
self.plugin_name = 'JOY'
-
- print 'Using joystick %s (%s)' % (config.JOY_DEV, self.device_name)
-
+
+ print 'Using joystick %s (%s) (sensitivity %s)' % (config.JOY_DEV,
self.device_name, config.JOY_SENS)
+
self.poll_interval = 1
self.poll_menu_only = False
+ def config(self):
+ return [
+ ('JOY_DEV', 1, 'Joystick number, 1 is \'/dev/js0\' or
\'/dev/input/js0\''),
+ ('JOY_SENS', 16384, 'Joystick sensitivity'),
+ ('JOY_LOCKFILE', None, 'Joystick lock file'),
+ ]
+
+
def poll(self):
if not self.enabled:
return
- command = ''
+ command = ''
_debug_('self.joyfd = %s' % self.joyfd, level=3)
(r, w, e) = select.select([self.joyfd], [], [], 0)
_debug_('r,w,e = %s,%s,%s' % (r,w,e), level=3)
-
+
+ self.sensitivity = config.JOY_SENS
+
if r:
c = os.read(self.joyfd, 8)
else:
@@ -100,20 +110,21 @@
if data[2] == 1 & data[1] == 1:
button = 'button '+str((data[3] + 1))
command = config.JOY_CMDS.get(button, '')
- sleep(0.3) # the direction pad can use lower debounce time
+
if data[2] == 2:
- if ((data[3] == 1) & (data[1] < -16384)):
+ if ((data[3] == 1) & (data[1] < -self.sensitivity)):
button = 'up'
command = config.JOY_CMDS['up']
- if ((data[3] == 1) & (data[1] > 16384)):
+ if ((data[3] == 1) & (data[1] > self.sensitivity)):
button = 'down'
command = config.JOY_CMDS['down']
- if ((data[3] == 0) & (data[1] < -16384)):
+ if ((data[3] == 0) & (data[1] < -self.sensitivity)):
button = 'left'
command = config.JOY_CMDS['left']
- if ((data[3] == 0) & (data[1] > 16384)):
+ if ((data[3] == 0) & (data[1] > self.sensitivity)):
button = 'right'
command = config.JOY_CMDS['right']
+
if command != '':
_debug_('Translation: "%s" -> "%s"' % (button, command))
command = rc.key_event_mapper(command)
@@ -122,7 +133,7 @@
rc.post_event(command)
elif not os.path.exists(config.JOY_LOCKFILE):
rc.post_event(command)
-
+
def enable(self, enable_joy=True):
self.enabled = enable_joy
return
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog