User avatar
Gomez
Posts: 40
Joined: Mon Dec 15, 2014 3:42 am
Location: Porto, Portugal

Autostart a python script?

Wed Dec 02, 2015 1:21 am

I wrote a little python script to work with RetroPie, it uses a pcf8591p to read the values of a psp joystick and emulate keyboard inputs accordingly .. the code itself is working on the terminal but when I put it into the rc.local to autorun into retropie and then reboot the system, it goes into the emulationstation but the keys are not being emulated and as soon as I press F4 to quit emulationstation the code is executed and I have to ctrl + c to stop it in order to write in the terminal otherwise there will only appear on the screen the arrow keys being emulated..

so the code is being autostarted but on the terminal, I need it to autostart itself on retropie/emulationstation instead...

idk if the code is important in this situation since i only want to autorun a python script but this is what I got, only one direction of one axis is working atm, which is the left key.. for testing purposes ..

Code: Select all

  GNU nano 2.2.6                         File: pcf2.py

from smbus import SMBus
import uinput
import time

bus = SMBus(1)
events = (uinput.KEY_UP, uinput.KEY_DOWN, uinput.KEY_LEFT, uinput.KEY_RIGHT)

bus.write_byte(0x48, 1)
last_reading =-1
device = uinput.Device(events)

while(0 == 0):
    reading = bus.read_byte(0x48)
    if(abs(last_reading - reading) > 2):
        last_reading = reading
    if(reading>120):
        device.emit(uinput.KEY_LEFT, 1)
        time.sleep(0.1)
        device.emit(uinput.KEY_LEFT, 0)


Return to “Beginners”