Script Stops when XBMC is Active, Continues when XBMC is closed
#1
Hello!

I have recently bought a Raspberry Pi, installed Raspian and installed both XBMC and emulationstation, to play games and watch movies. The gaming works great with the gamepads I bought, however, they are not supported by XBMC. After searching for answers online and trying several things like custom keymapping, using joy2key without any success, I decided to write some python code to help me out.

The script is inspired by this blog post: Driver Writing with Python

When I test the script without XBMC running it works great and is able to respond to all my button presses. Once I boot XBMC I started to run into trouble.
Using ssh i remotely logged in and executed my script. I noticed it would freeze when XBMC had started, and then unfreeze once I closed XBMC.

I have tried running the program using multithreading, multiprocessing in Python and even tried to execute it in a subprocess in the Linux shell, and running the program inside autoexec.py.
Nothing seemed to resolve the freezing of the script. Please not that I am a beginner to Linux and Python programming, but I do have some basic understanding of both.

This is my version of the script, basically the same as described in the blog post, but with added functionality to send JSON commands to XBMC
Currently, only one JSON command is implemented as an example (pressing the left button)

I hope anyone can tell me why this script pauses / freezes once XBMC is booted (it does not freeze at once, it does about 150 iterations of the loop before freezing, i have tested this) and then continues when XBMC closes

(sorry for the weird indenting after the first line, I cannot seem to fix that. I can assure you that indenting is correct in my actual script)

Code:
s = requests.Session()
        pipe = open('/dev/input/js0','r')
        action = []
        spacing = 0

        while 1:
                for character in pipe.read(1):
                        action += ['%02X' % ord(character)]
                        if len(action) == 8:
        
                                num = int(action[5], 16) # Translate back to integer form
                                percent254 = str(((float(num)-128.0)/126.0)-100)[4:6] # Calculate the percentage of push
                                percent128 = str((float(num)/127.0))[2:4]
        
                                if percent254 == '.0':
                                        percent254 = '100'
                                if percent128 == '0':
                                        percent128 = '100'
        
                                if action[6] == '01': # Button
                                        if action[4] == '01':
                                                print 'You pressed button: ' + action[7]
                                        else:
                                                print 'You released button: ' + action[7]
        
                                elif action[7] == '00': # D-pad left/right
                                        if action[4] == 'FF':
                                                print 'You pressed right on the D-pad'
                                        elif action[4] == '01':
                                                print 'You pressed left on the D-pad'
                                                s.get('http://192.168.0.103:8080/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Input.Left"}')
        
                                                
                                        else:
                                                print 'You released the D-pad'
        
        
                                elif action[7] == '01': # D-pad up/down
                                        if action[4] == 'FF':
                                                print 'You pressed down on the D-pad'
                                        elif action[4] == '01':
                                                print  'You pressed up on the D-pad'
                                        else:
                                                print 'You released the D-pad'
        
                                action = []
Reply

Logout Mark Read Team Forum Stats Members Help
Script Stops when XBMC is Active, Continues when XBMC is closed0