Help with [ESC] to menu

Tagged: , , ,

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of ectoarckanox ectoarckanox 2 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40653
    Profile photo of juicebox
    juicebox
    Participant

    I am trying so setup a script that will execute an [ESC] when a button is pushed (wired to the GPIO). I have tried writing a bash script using xdotool to no avail and have now switched gears to a python script using uinput. Here is my script:

    
    #!/usr/bin/env python
    
    import RPi.GPIO as GPIO
    import os
    import time
    import uinput
    
    #Setup
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(6, GPIO.IN)
    KEY_EVENTS = (uinput.KEY_ESC, uinput.KEY_X)
    DEVICE = uinput.Device(KEY_EVENTS)
    
    while True:
            GPIO.wait_for_edge(6, GPIO.FALLING)
            print("Button pressed...")
            start_time = time.time()
    
            GPIO.wait_for_edge(6, GPIO.RISING)
            time_pressed = time.time() - start_time
    
            if time_pressed < 6:
                    print("[ESC] key sent")
                    DEVICE.emit_click(uinput.KEY_ESC)
            else:
                    print("Power down")
                    GPIO.cleanup()
                    os.system("sudo reboot")
    
            time.sleep(2)
    

    After the pi boots, I exit the emulator and run

    
    ./myscript.py $
    

    Then restart the emulator, load a ROM, and push my little black button. You’re not gonna believe this but, the damn thing doesn’t work. If I hit the [ESC] on my keyboard, I get back to the menu without fail. I know the input logic is working because I can see the returned output lines in the terminal window, and the logic that drives rebooting if the button is pushed for more that 6 secs works well. Any help here would be appreciated.

    #81593
    Profile photo of ectoarckanox
    ectoarckanox
    Participant

    Hi,

    I’ve tried to do the same thing and stumbled into the same issue 🙁

    Did you find a solution ?

    thanks in advance 🙂

    #81595
    Profile photo of brooksyx
    brooksyx
    Participant

    You have to press the GPIO 3 times in a row to register the esc key being pressed.

    I rewrote snesdev to only need it to be pushed once. Build from my git and replace the snesdev included with retropie:

    https://github.com/brooksyx/SNESDev-RPi

    #81596
    Profile photo of ectoarckanox
    ectoarckanox
    Participant

    first, thanks for answering so quickly.
    I was aiming for a solution that was not using snesdev, like juicebox here above.
    but with a lot of my research results pointing to snesdev, it was my fallback option if plan A was not working.

    I’ll try your version, thanks for sharing.

    Which gpio pin do I have to connect my switch to? I just need the reset button.

    thanks!

Viewing 4 posts - 1 through 4 (of 4 total)

Forums are currently read only - please visit the new RetroPie forums at https://retropie.org.uk/forums/

Skip to toolbar