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

    GPIO triggered by retroachievements?

    Scheduled Pinned Locked Moved Ideas and Development
    cheevosretroachievemen
    18 Posts 4 Posters 5.1k 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.
    • meleuM
      meleu @spruce_m00se
      last edited by meleu

      @spruce_m00se said in GPIO triggered by retroachievements?:

      Any thoughts? @meleu

      yes, launch RetroArch with --verbose and find a way to check runcommand.log. We just have to find an elegant way for that checking, an infinite loop would be a very ugly approach.
      (edit: I found the elegant way and posted here)

      When you earn a cheevo, you'll see something like this on the log:

      RetroArch [INFO] :: CHEEVOS awarded achievement 30444
      RetroArch [INFO] :: CHEEVOS awarding cheevo 30436: From The Grave To Your Plate (Get a platinum relic in Hoppin' Coffins.)
      
      • Useful topics
      • joystick-selection tool
      • rpie-art tool
      • achievements I made
      1 Reply Last reply Reply Quote 0
      • spruce_m00seS
        spruce_m00se
        last edited by

        so do you get a visual notification onscreen that you got the cheevo? and assumedly there is a website (from what I remember reading) that gets updated with your list?

        so obviously for now its not realtime. with the highscore, maybe there is some way to register when the game over has happened? thats normally when a highscore is registered right ?
        how does the emlator update the log? could it be programmed into that part that aswell as update the log it blips a GPIO pin for a while?

        meleuM 1 Reply Last reply Reply Quote 0
        • meleuM
          meleu @spruce_m00se
          last edited by meleu

          @spruce_m00se said in GPIO triggered by retroachievements?:

          so do you get a visual notification onscreen that you got the cheevo?

          Didn't you never got a cheevo? Suggestion: start Metroid (NES) and go left to grab the Morph Ball. You'll see what happens. (edit: use QuickNES for this test)

          But I'm afraid you can't trigger GPIO with something happening on the screen, right?

          and assumedly there is a website (from what I remember reading) that gets updated with your list?

          Trying to simplify:

          • RetroArch asks to retroachievements.org if the game X has cheevos (based on the ROM's hash).
          • the website gives the game's achievements list to RetroArch.
          • once RetroArch gets the list, the communication between both ends stops
          • when you do what is needed to earn the cheevo, RetroArch
            • shows a message on the screen;
            • if you're running RetroArch with --verbose it writes that message on the log;
            • tries to register your cheevo on the site;
              • if RetroArch can't register you earned the cheevo on the site, it keeps trying until it succeed or RetroArch terminates.

          so obviously for now its not realtime.

          If you find a way to make your "GPIO manager" check the logs, then you can make it virtually realtime.

          with the highscore, maybe there is some way to register when the game over has happened? thats normally when a highscore is registered right ?

          Well, if you're talking about cheevos, that question doesn't make sense, I'm afraid...

          how does the emlator update the log?

          Realtime. It keeps the file opened and keeps writing in it.

          could it be programmed into that part that aswell as update the log it blips a GPIO pin for a while?

          Yes, but you would need to change the RetroArch code itself. I think it would be overengineering. I think you can get what you want with python and/or bash more easily.

          • Useful topics
          • joystick-selection tool
          • rpie-art tool
          • achievements I made
          1 Reply Last reply Reply Quote 1
          • SanoS
            Sano
            last edited by

            Following @meleu advice, you could write a simple script based on tail and grep, or take a look at swatch (raspbian package).

            meleuM 1 Reply Last reply Reply Quote 0
            • meleuM
              meleu @Sano
              last edited by

              @sano I've googled trying to find an "elegant" way to check updates on a file in realtime and no infinite loop. And looks like the inotify-tools worths a try.

              Maybe you'll need to install it:

              sudo apt-get install inotify-tools
              

              You guys can find some inspiration in this question and the first answer:
              https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes

              • Useful topics
              • joystick-selection tool
              • rpie-art tool
              • achievements I made
              SanoS 1 Reply Last reply Reply Quote 0
              • SanoS
                Sano @meleu
                last edited by Sano

                @meleu AFAIK (but I may be wrong) tail -f use inotify if no sleep interval is specified ;)

                meleuM 1 Reply Last reply Reply Quote 1
                • meleuM
                  meleu @Sano
                  last edited by

                  @sano looks like using tailf has a little advantage over tail -f

                  Look what I found on man tailf:

                         tailf  will print out the last 10 lines of the given file and then wait
                         for this file to grow.  It is similar to tail -f but  does  not  access
                         the  file  when  it  is  not  growing.  This has the side effect of not
                         updating the access time for the file, so a filesystem flush  does  not
                         occur periodically when no log activity is happening.
                  
                         tailf  is  extremely  useful  for monitoring log files on a laptop when
                         logging is infrequent and the user desires that the hard disk spin down
                         to conserve battery life.
                  

                  Buuuuut, we would need to pipe the output of that command to a grep looking for awarded cheevos and then trigger the command to do GPIO magic. I have no idea how we could do that.

                  The answer on that superuser.com link I posted makes me believe that using inotify-tools has a good solution for that. But I didn't have a chance to try it yet (away from my Linux now).

                  • Useful topics
                  • joystick-selection tool
                  • rpie-art tool
                  • achievements I made
                  1 Reply Last reply Reply Quote 0
                  • spruce_m00seS
                    spruce_m00se
                    last edited by

                    So from the looks of it, RetroArch must monitor the state fo the game, and when a criteria is met, it awards the cheevo and tries to contact the website to update your profile?
                    so it would seem that the same piece of code that causes retroarch to contact the website or display the onscreen achievment notification, could in theory toggle the GPIO pin.

                    And nope , i havent played around with the achievements yet. I will do.

                    meleuM 1 Reply Last reply Reply Quote 0
                    • meleuM
                      meleu @spruce_m00se
                      last edited by meleu

                      @spruce_m00se said in GPIO triggered by retroachievements?:

                      So from the looks of it, RetroArch must monitor the state fo the game, and when a criteria is met, it awards the cheevo and tries to contact the website to update your profile?

                      Yes. Pasting here what I said above putting in bold what I want you to pay atention:

                      • when you do what is needed to earn the cheevo, RetroArch
                        • shows a message on the screen;
                        • if you're running RetroArch with --verbose it writes that message on the log;
                        • tries to register your cheevo on the site;
                          • if RetroArch can't register you earned the cheevo on the site, it keeps trying until it succeed or RetroArch terminates.

                      so it would seem that the same piece of code that causes retroarch to contact the website or display the onscreen achievment notification, could in theory toggle the GPIO pin.

                      Well, I really think that doing what you want via bash (or maybe python), checking the log, is a way simpler than implementing a custom C code in RetroArch. But if you really feel confident for implement this in C, then go ahead. The source code file you need to edit in RetroArch is cheevos/cheevos.c.

                      • Useful topics
                      • joystick-selection tool
                      • rpie-art tool
                      • achievements I made
                      spruce_m00seS 1 Reply Last reply Reply Quote 0
                      • spruce_m00seS
                        spruce_m00se @meleu
                        last edited by

                        @meleu is that source code file available for view on a windows pc? whilst away from the pi. I will have a butchers at it, I have only dont programming in arduino, but you never know, I may be able to work it out.

                        meleuM 1 Reply Last reply Reply Quote 0
                        • meleuM
                          meleu @spruce_m00se
                          last edited by

                          @spruce_m00se said in GPIO triggered by retroachievements?:

                          @meleu is that source code file available for view on a windows pc?

                          You can see it on any device with a browser and internet access:
                          https://github.com/libretro/RetroArch/blob/master/cheevos/cheevos.c

                          But man... Look what happenned when Vegeta saw the difference in difficulty between doing what you want changing RetroArch code in C and writing a small script to check the logs:

                          over9000

                          • Useful topics
                          • joystick-selection tool
                          • rpie-art tool
                          • achievements I made
                          spruce_m00seS 2 Replies Last reply Reply Quote 0
                          • spruce_m00seS
                            spruce_m00se @meleu
                            last edited by

                            @meleu hahahahahahahaha vegetas a girl anyway

                            1 Reply Last reply Reply Quote 0
                            • spruce_m00seS
                              spruce_m00se @meleu
                              last edited by

                              @meleu do you know who wrote the code for the cheevos?

                              meleuM 1 Reply Last reply Reply Quote 0
                              • spruce_m00seS
                                spruce_m00se
                                last edited by

                                static void cheevos_unlocked(void *task_data, void *user_data, const char *error)
                                {
                                cheevo_t *cheevo = (cheevo_t *)user_data;

                                if (error == NULL)
                                {
                                RARCH_LOG("CHEEVOS awarded achievement %u.\n", cheevo->id);
                                }

                                starting at line 2126, this seems to show signs of being a good place to start looking. maybe the code needed to do the GPIO pin can be added to an IF statement somewhere.

                                1 Reply Last reply Reply Quote 0
                                • meleuM
                                  meleu @spruce_m00se
                                  last edited by meleu

                                  @spruce_m00se said in GPIO triggered by retroachievements?:

                                  @meleu do you know who wrote the code for the cheevos?

                                  @spruce_m00se yes, this guy here wrote the most part (maybe 95% or more). I wrote some small contributions (other libretro guys too). And Twinaphex is like a quality control boss of RetroArch code (the one who merge most of the PRs).

                                  If you by chance convince leiradel to insert such code in cheevos.c (wich I think very hard), I'm pretty sure that Twinaphex wouldn't merge it in the master branch.

                                  Keep in mind that RetroArch is intended to run in several platforms/architectures. Like Raspberry Pi, x86, PlayStation 3, PlayStation Vita, Nintendo 3DS, Nintendo Wii U, Android, etc... The application you want is a really really really edge case for a little niche of RetroArch users in Raspberry Pi...

                                  Please, tell me: why not bash/python?

                                  • Useful topics
                                  • joystick-selection tool
                                  • rpie-art tool
                                  • achievements I made
                                  meleuM 1 Reply Last reply Reply Quote 0
                                  • meleuM
                                    meleu @meleu
                                    last edited by meleu

                                    @meleu said in GPIO triggered by retroachievements?:

                                    Please, tell me: why not bash/python?

                                    @spruce_m00se well, you didn't give me the answer to that question but you know, this is about cheevos and shell scripting... How can I sleep when there's something related with these two subjects pending?

                                    Here is a prove of how simple is to make what you want via bash:

                                    #!/bin/bash
                                    # This script is just a proof of concept of what is being discussed here:
                                    # https://retropie.org.uk/forum/topic/11793/gpio-triggered-by-retroachievements
                                    #
                                    # Before using this script you need to install inotify-tools:
                                    #    sudo apt-get install inotify-tools
                                    #
                                    # meleu - July/2017
                                    
                                    readonly file=/dev/shm/runcommand.log
                                    
                                    while inotifywait -qq -e modify "$file" ; do
                                        if tail -1 "$file" | grep "CHEEVOS awarding cheevo"; then
                                            echo "PUT HERE THE COMMAND TO FLASH THE FANCY LIGHTS! YOU GOT A CHEEVO!!"
                                        fi
                                    done
                                    
                                    • Useful topics
                                    • joystick-selection tool
                                    • rpie-art tool
                                    • achievements I made
                                    NamErehWonN 1 Reply Last reply Reply Quote 0
                                    • NamErehWonN
                                      NamErehWon @meleu
                                      last edited by

                                      @meleu Ooh, that's nifty. I bet I could use this to trigger some kind of popup that's more akin to what you'd see on a PlayStation or X-Box.

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        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.