Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event number input and Fake axis check #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 38 additions & 22 deletions create_xboxdrv_evdev_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,33 @@ def write(self, x):
sys.stdout = flushfile(sys.stdout)


num = int(input("Insert controller's /dev/input/event* number, in you don't know it, insert -1): "))

evdev_filename=f"/dev/input/event{num}"

if(num == -1):
# Get the device either from the command line or by using identify_evdev
if len(sys.argv) > 2 or len(sys.argv) == 2 and sys.argv[1] == '--help':
print("USAGE: %s [event-device]" % sys.argv[0], file=sys.stderr)
print(file=sys.stderr)
print("Generates a xboxdrv command for treating event-device as an XBox controller.", file=sys.stderr)
print("If event-device is omitted, the controller will be identified by asking the", file=sys.stderr)
print("user to press a button on it.", file=sys.stderr)
sys.exit()
elif len(sys.argv) == 2:
evdev_filename = sys.argv[1]
else:
from identify_evdev import list_active_evdev
fns = None
# Keep going until there's input from only one device.
while fns is None or len(fns) != 1:
print("Press any button on only the joystick you are setting up.")
fns = list_active_evdev()
evdev_filename = fns[0]
print("Selected event device: %s" % evdev_filename)
print("Stop pressing any buttons.")
# Give user time to stop pressing buttons.
time.sleep(2)
if len(sys.argv) > 2 or len(sys.argv) == 2 and sys.argv[1] == '--help':
print("USAGE: %s [event-device]" % sys.argv[0], file=sys.stderr)
print(file=sys.stderr)
print("Generates a xboxdrv command for treating event-device as an XBox controller.", file=sys.stderr)
print("If event-device is omitted, the controller will be identified by asking the", file=sys.stderr)
print("user to press a button on it.", file=sys.stderr)
sys.exit()
elif len(sys.argv) == 2:
evdev_filename = sys.argv[1]
else:
from identify_evdev import list_active_evdev
fns = None
# Keep going until there's input from only one device.
while fns is None or len(fns) != 1:
print("Press any button on only the joystick you are setting up.")
fns = list_active_evdev()
evdev_filename = fns[0]
print("Selected event device: %s" % evdev_filename)
print("Stop pressing any buttons.")
# Give user time to stop pressing buttons.
time.sleep(2)

# Open the device
dev = evdev.device.InputDevice(evdev_filename)
Expand All @@ -74,7 +79,7 @@ def eat_events(dev):
event = dev.read_one()
if event is None:
return
except Exception, e:
except :
return

def get_next_pressed_button_name(dev):
Expand All @@ -99,11 +104,22 @@ def get_next_maxed_axis(dev, mappings):
# If an axis has been moved...
elif event.type == evdev.ecodes.EV_ABS:
# ... look up the min/max values for that axis...

absinfo = dict(dev.capabilities()[evdev.ecodes.EV_ABS])[event.code]
axis = evdev.ecodes.ABS[event.code]
# ... and if the min or max has been reached, return it.


#check for digital input represented as axes
if absinfo.min == -1 and absinfo.max == 1:
if event.value == -1:
return 'min', axis
elif event.value == 1:
return 'max', axis

if event.value <= absinfo.min + 20:
return 'min', axis

elif event.value >= absinfo.max - 20:
return 'max', axis

Expand Down
2 changes: 1 addition & 1 deletion identify_evdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def list_active_evdev():
try:
devices.append(evdev.device.InputDevice(dev))
except (IOError, OSError):
# Don't have permissions for that device, ignore it.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental change?

#Don't have permissions for that device, ignore it.
pass
devices = {dev.fd : dev for dev in devices}

Expand Down