K
K
kharlashkin2015-07-06 17:01:59
linux
kharlashkin, 2015-07-06 17:01:59

How to send vibration to xbox 360 controller using python on linux?

Actually the question is asked, I do not have enough qualifications and knowledge to understand and solve.
There are the following inputs:

  1. Documentation for the module for sending vibrations to the gamepad.
  2. Source code for the test program for checking vibrations written in C.
  3. I'm using the built-in driver for the Xbox 360 controller Xpad - source , documentation .

Can anyone suggest a direction or give an example of the implementation of an analogue of fftest in python?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kharlashkin, 2015-07-14
@kharlashkin

The necessary code was found , which, with the help of a slight modification, allows you to do the necessary actions, in the example, launching 4 vibrations lasting 2 seconds each with a 2-second interval (the first vibration does not work for some reason). Ubuntu 14.04 LTS OS in a VMWare virtual machine with an Xbox 360 wired gamepad thrown inside
.

import fcntl, struct, array, time
  
EVIOCRMFF = 0x40044581
EVIOCSFF = 0x40304580
LOG_CLASS_ON = False
TIME_DELTA = 25

class Vibrate:

    def __init__(self, file):
        self.ff_joy = open(file, "r+")

    def close(self):
        self.ff_joy.close()

    def new_effect(self, strong, weak, length):
        effect = struct.pack('HhHHHHHxHH', 0x50, -1, 0, 0, 0, length, 0, int(strong * 0xFFFF), int(weak * 0xFFFF))
        a = array.array('h', effect)
        fcntl.ioctl(self.ff_joy, EVIOCSFF, a, True)
        return a[1]
        id = a[1]
        return (ev_play, ev_stop)

    def play_efect(self, id):
        if type(id) == tuple or type(id) == list:
            ev_play = ''
            for i in id:
                ev_play = ev_play + struct.pack('LLHHi', 0, 0, 0x15, i, 1)
        else:
            ev_play = struct.pack('LLHHi', 0, 0, 0x15, id, 1)
        self.ff_joy.write(ev_play)
        self.ff_joy.flush()

    def stop_effect(self, id):
        if type(id) == tuple or type(id) == list:
            ev_stop = ''
            for i in id:
                ev_stop = ev_stop + struct.pack('LLHHi', 0, 0, 0x15, i, 0)
        else:
            ev_stop = struct.pack('LLHHi', 0, 0, 0x15, id, 0)
        self.ff_joy.write(ev_stop)
        self.ff_joy.flush()

    def forget_effect(self, id):
        if type(id) == tuple or type(id) == list:
            for i in id:
                fcntl.ioctl(self.ff_joy, EVIOCRMFF, i)
        else:
            fcntl.ioctl(self.ff_joy, EVIOCRMFF, id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question