• Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
RetroPie forum home
  • Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login

Getting the rom name and emulator

Scheduled Pinned Locked Moved General Discussion and Gaming
pi model v3pythonscriptretropiesetup
82 Posts 5 Posters 18.8k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    meleu @cyperghost
    last edited by meleu 20 Jul 2017, 03:24

    @cyperghost said in Getting the rom name and emulator:

    @buzz I call a python programm with $@ within runcommand. What will be the result and how does the python script "knows" how many arguments are given.

    So if
    $1 - the system (eg: atari2600, nes, snes, megadrive, fba, etc).
    $2 - the emulator (eg: lr-stella, lr-fceumm, lr-picodrive, pifba, etc).
    $3 - the full path to the rom file.
    $4 - the full command line used to launch the emulator

    can I just use romfile=$3 variable within python and I get my romfile even by using $@?

    I'm not comfortable with python at all, I only learned it to tweak the joy2key tool and never used it again. But I think the answer for your question can be found here: https://docs.python.org/2/library/sys.html#sys.argv

    Maybe this example can answer too:

    [PROMPT] $ cat args.py
    #!/usr/bin/python
    import sys
    print '\nnumber of arguments:'
    print len(sys.argv)
    print '\nhere are the given arguments:'
    for arg in sys.argv:
    print arg
    print '\nhere is the third argument:'
    print sys.argv[3]
    [PROMPT] $ ./args.py one two three
    number of arguments:
    4
    here is the given arguments:
    ./args.py
    one
    two
    three
    here is the third argument:
    three
    [PROMPT] $ ./args.py catch errors
    number of arguments:
    3
    here is the given arguments:
    ./args.py
    catch
    errors
    here is the third argument:
    Traceback (most recent call last):
    File "./args.py", line 13, in <module>
    print sys.argv[3]
    IndexError: list index out of range
    • Useful topics
    • joystick-selection tool
    • rpie-art tool
    • achievements I made
    C 1 Reply Last reply 20 Jul 2017, 05:24 Reply Quote 1
    • C
      cyperghost @meleu
      last edited by 20 Jul 2017, 05:24

      @meleu That's it
      Thank you

      D 1 Reply Last reply 20 Jul 2017, 17:17 Reply Quote 0
      • D
        daveyman123 @cyperghost
        last edited by 20 Jul 2017, 17:17

        @cyperghost

        Would you know why something about launching a game stops my unicorn hat from functioning?

        If I launch a game and immediately back out it will continue to scroll through the rom on the unicorn hat.

        However,
        if the game actually launches the unicorn hat stops.
        would there be something interfering with the PINS from retropie?

        I have the python script running in the background but no difference.

        C 1 Reply Last reply 20 Jul 2017, 18:01 Reply Quote 0
        • C
          cyperghost @daveyman123
          last edited by cyperghost 20 Jul 2017, 18:01

          @daveyman123 That isn't hard

          1. nano /opt/retropie/configs/all/runcommand-onstart.sh
          2. Add your script for ex /home/pi/RetroPie/loop.sh $1 &

          That's it

          code example loop.sh
          make loop executable by chmod +x loop.sh

          #!/bin/bash
          counter=0
          while [ $counter -lt 10 ]; do
          echo The counter is $counter
          echo "The romsystem is $1" >> /tmp/counter.log
          let counter=counter+1
          sleep 5
          done

          That's it ... now in tmp/counter.log is 10 times written "The romsystem is ....."
          As the ROM is loaded in foreground the bash example in background is logging the system.

          D 2 Replies Last reply 20 Jul 2017, 18:25 Reply Quote 1
          • D
            daveyman123 @cyperghost
            last edited by 20 Jul 2017, 18:25

            @cyperghost
            almost done writing it up
            if this works youre a genius!

            1 Reply Last reply Reply Quote 0
            • M
              meleu
              last edited by meleu 20 Jul 2017, 18:54

              @daveyman123 can you tell me WTF is an unicorn hat?
              I want to believe that you are not talking about this:
              unicornhat

              @cyperghost I remember that you said you didn't learn programming in a "formal" way. But I would like to make you care more about the importance of indentation.

              Please, I don't want to sound like the smart guy teaching you the right way to code. If your code works for you, then it's fine. But I know that you like to share code with the community (giving and receiving contributions), and for this purpose indentation is a basic requirement. ;-)

              • Useful topics
              • joystick-selection tool
              • rpie-art tool
              • achievements I made
              C 1 Reply Last reply 20 Jul 2017, 19:11 Reply Quote 1
              • S
                Sano
                last edited by Sano 20 Jul 2017, 18:58

                More like this I think : https://shop.pimoroni.com/products/unicorn-hat
                But yours is way more fun :D

                M 1 Reply Last reply 20 Jul 2017, 19:01 Reply Quote 0
                • M
                  meleu @Sano
                  last edited by 20 Jul 2017, 19:01

                  @sano said in Getting the rom name and emulator:

                  But yours is way more fun

                  haha! both models are kinda psychodelic! :D

                  • Useful topics
                  • joystick-selection tool
                  • rpie-art tool
                  • achievements I made
                  1 Reply Last reply Reply Quote 0
                  • D
                    daveyman123 @cyperghost
                    last edited by 20 Jul 2017, 19:09

                    @cyperghost
                    here is the python script. I think its reading the log just fine.

                    from UHScroll import *
                    import sys
                    import time
                    import os
                    import unicornhat as unicorn
                    infile = r"/tmp/counter.log"
                    
                    #print len(sys.argv)
                    #emulator_name = $1
                    #emulator_name = os.environ["$1"]
                    #emulator_name = os.path.basename(os.path.normpath(sys.argv[3]))
                    with open(infile) as f:
                        f = f.readlines()
                    
                    for line in f:
                            rom_name = line
                            unicorn_scroll(rom_name,'white',255,0.2)`
                    1 Reply Last reply Reply Quote 0
                    • D
                      daveyman123
                      last edited by 20 Jul 2017, 19:11

                      and here is the loop bash script

                      #!/bin/bash
                      counter=0
                      while [ $counter -lt 10 ]; do
                      echo The counter is $counter
                      echo "$3" >> /tmp/counter.log
                      let counter=counter+1
                      sleep 5
                      sudo python /opt/retropie/configs/all/onstart2.py
                      sleep 5
                      done

                      and here is the startup script (runcommand-onstart.sh)

                      /home/pi/RetroPie/loop.sh $1 &
                      sudo python onstart2.py "$1" &
                      C 1 Reply Last reply 20 Jul 2017, 19:25 Reply Quote 0
                      • C
                        cyperghost @meleu
                        last edited by 20 Jul 2017, 19:11

                        @meleu A Unicorn Hat seem to be a LED grid of 8x8. So it can be used/abused as simple display. As far as I understood this

                        Yes the code is of course messy and unclean ... it's just an example that a bash file can run in the background by wrinting a logging file. I don't have an code editor so everything is written in nano. I'm thankfull for every tip and I appreciate your way you tell me do and what is better not done!

                        @daveyman123 Thanks for your comment but please don't call me genius for writing a simple bash script. There are others that do programming as profession. I do it just for hobby and still make lot of errors ... like missing indentation or not using remarks for this.

                        D 2 Replies Last reply 20 Jul 2017, 19:18 Reply Quote 0
                        • D
                          daveyman123 @cyperghost
                          last edited by 20 Jul 2017, 19:18

                          @cyperghost

                          its just my way of sayin i appreciate the help

                          1 Reply Last reply Reply Quote 0
                          • D
                            daveyman123 @cyperghost
                            last edited by 20 Jul 2017, 19:20

                            @cyperghost said in Getting the rom name and emulator:

                            A Unicorn Hat seem to be a LED grid of 8x8. So it can be used/abused as simple display. As far as I understood this

                            @cyperghost said in Getting the rom name and emulator:

                            A Unicorn Hat seem to be a LED grid of 8x8. So it can be used/abused as simple display. As far as I understood this

                            I am coming to believe this is not how it works. However I am unsure and should probably do some research. :)

                            1 Reply Last reply Reply Quote 0
                            • C
                              cyperghost @daveyman123
                              last edited by cyperghost 20 Jul 2017, 19:25

                              @daveyman123 No no :)
                              The loop.sh was just intended as an example how to call a bash or python script.
                              for the loop.sh. You used the way and read out a logfile ... this isn't neccesary.

                              Your pyhton script should use the argument given via sys.argv[1]
                              so the runcommand-onstart.sh should only contain

                              sudo python onstart2.py "$1" &
                              

                              why do you use sudo? Can't you use the regular user? sudo commands are often responsible for unwanted effects (locked file access)

                              Keep in mind ... now the process python is running endless in background. You can end it by sending a exitcode to the script or by killing the python process.

                              Sorry I don't know how the Unicorn device works and what can be done by coding. I think you have to do some research ... the magic of the background is the & sign

                              @meleu
                              Is there a better way to end a process running in background?

                              C M 2 Replies Last reply 20 Jul 2017, 19:40 Reply Quote 0
                              • C
                                cyperghost @cyperghost
                                last edited by cyperghost 20 Jul 2017, 19:40

                                @daveyman123
                                Well there could be a method that should work.

                                You write the $3 argument to a file on runcommand-onstart.sh

                                echo $3 > /home/pi/unicorn.txt
                                sudo python onstart2.py &

                                Open the file /home/pi/unicorn.txt in python for every loop and dispaly the string from written file to your program

                                Then on runcommand-onend.sh

                                echo "killterm" > /home/pi/unicorn.txt
                                

                                you write on killterm to the same file as on runcommand-onstart.sh
                                Within python you analyse the content of unicorn.txt
                                if it's not "killterm" then the unicorn flys, if it's killterm the python program ends

                                BUT THAT'S A MESSY STYLE!!!

                                D 1 Reply Last reply 20 Jul 2017, 19:52 Reply Quote 0
                                • D
                                  daveyman123 @cyperghost
                                  last edited by 20 Jul 2017, 19:52

                                  @cyperghost
                                  I use sudo because it wont run otherwise
                                  lol its ok that your code is sloppy im a newbie and cant tell the difference

                                  as for the python script. I think the problem lies in something to do with RetroPie being an experimental OS for the unicorn.

                                  here is my code in the python script

                                  
                                  from UHScroll import *
                                  import sys
                                  import time
                                  import os
                                  import unicornhat as unicorn
                                  
                                  rom_name = os.path.basename(os.path.normpath(sys.argv[3]))
                                  
                                  unicorn_scroll(rom_name,'white',255,0.2)
                                  

                                  this produces the result of freezing half way through writing "GOLDENEYE". e.g it prints "GOLDEN" then freezes.

                                  1 Reply Last reply Reply Quote 0
                                  • M
                                    meleu @cyperghost
                                    last edited by 20 Jul 2017, 19:53

                                    @cyperghost said in Getting the rom name and emulator:

                                    Is there a better way to end a process running in background?

                                    My favorites are using pgrep/pkill.

                                    @daveyman123 I'm confused about this unicorn stuff. Can you explain what exactly you want to do and what info you need from runcommand?

                                    • Useful topics
                                    • joystick-selection tool
                                    • rpie-art tool
                                    • achievements I made
                                    C 1 Reply Last reply 20 Jul 2017, 19:55 Reply Quote 0
                                    • C
                                      cyperghost @meleu
                                      last edited by cyperghost 20 Jul 2017, 19:55

                                      @meleu and what about the method here
                                      I thought killing processes by pkill/kill is bad style? Isn't it not?

                                      M 1 Reply Last reply 20 Jul 2017, 20:00 Reply Quote 0
                                      • S
                                        Sano
                                        last edited by 20 Jul 2017, 19:59

                                        SIGKILL (-9) is bad, SIGTERM (-15) is totally normal.
                                        Default behaviour of kill/pkill is to send a SIGTERM.

                                        1 Reply Last reply Reply Quote 1
                                        • M
                                          meleu @cyperghost
                                          last edited by 20 Jul 2017, 20:00

                                          @cyperghost said in Getting the rom name and emulator:

                                          I thought killing processes by pkill/kill is bad style? Isn't it not?

                                          IMHO this is THE method for killing processes. :)

                                          I think we can strongly simplify things here, but I don't know what exactly @daveyman123 wants to do nor what exact info his python script needs.

                                          • Useful topics
                                          • joystick-selection tool
                                          • rpie-art tool
                                          • achievements I made
                                          D C 2 Replies Last reply 20 Jul 2017, 20:03 Reply Quote 0
                                          38 out of 82
                                          • First post
                                            38/82
                                            Last post

                                          Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                          Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.

                                            This community forum collects and processes your personal information.
                                            consent.not_received