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

    Wireless Battery Indicator (PS3)

    Scheduled Pinned Locked Moved Ideas and Development
    batterywirelessps3
    22 Posts 11 Posters 9.4k 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.
    • H
      Heyoeyo
      last edited by Heyoeyo

      Quick update:

      So far, I haven't been able to find a nice way of obtaining battery level information after the controller initially connects. However, I did manage to find a way to display a pop-up indicator image (over top of emulation station) when the controller first connects, thanks to AndrewFromMelbourne's raspidmx library. I think this is probably preferable to the system I had before, even without the up-to-date battery level information. Here's what it looks like (on top of the minimal theme):

      0_1506814792759_batteryExample_lowRes.png

      When a controller is connected, the icon slides in from the left, pauses for a moment and then slides out (example). The timing, positioning and icon graphics can all be changed. It works in more or less the same way as the previous script (checking the sixad log).

      Getting this running is a bit more involved than the menu script from my previous post. If anyone is interested, I've set up a github page with instructions for 'installing' the required code:
      https://github.com/heyoeyo/batteryCheck

      An additional thank you goes to this thread discussing the layering issue. That problem was driving me insane haha.

      Edit: Added link to example of the display animation

      1 Reply Last reply Reply Quote 2
      • P
        psyke83 Global Moderator
        last edited by

        The next kernel firmware will have support for rumble & battery information in the sony-hid driver (which will be used if you don't install the ps3controller driver).

        You will be able to query via:
        /sys/class/power_supply/sony_controller_battery_xx:xx:xx:xx:xx:xx/capacity

        Unfortunately, the native driver has one big downside in that it ignores the bluetooth IdleTimeout setting. If you leave your Pi on 24/7 and forget to manually turn off the controller, it will stay paired indefinitely and drain battery quite quickly.

        1 Reply Last reply Reply Quote 0
        • P
          psyke83 Global Moderator
          last edited by psyke83

          Here's a very rough way to read the current battery status when ps3controller is used. Feel free to clean it up and incorporate it in your stuff:

          #!/bin/bash
          
          function read_sixaxis_battery () {
          while read -r line; do
            if [[ "$line" == *"L2CAP"* ]]; then
               read -r line
               read -r line
               echo "$line" | awk '{ print $12 }'
               return
            fi
          done
          }
          
          hcidump -x | read_sixaxis_battery &
          sleep 5
          pkill hcidump
          

          You need to install bluez-hcidump and run the script with root privileges.

          If you want to incorporate it into python, here's what you're looking for from the output:

          hcidump -x
          > ACL data: handle 11 flags 0x02 dlen 54
              L2CAP(d): cid 0x0041 len 50 [psm 0]
                A1 01 00 00 00 00 00 87 82 7E 7D 00 00 00 00 00 00 00 00 00
                00 00 00 00 00 00 00 00 00 00 03 05 16 00 00 00 00 33 FD 77
                01 C0 02 09 01 F1 01 93 00 02
          

          The battery value is the 31st in the array, shown as 05 in the above log.

          1 Reply Last reply Reply Quote 1
          • H
            Heyoeyo
            last edited by

            Awesome, thanks!

            I'll give this a try and let you know how it goes!

            1 Reply Last reply Reply Quote 0
            • Z
              zerojay
              last edited by

              Anyone have this functional at all right now?

              H 1 Reply Last reply Reply Quote 0
              • retroprogrammerR
                retroprogrammer
                last edited by

                can we incorporate it into other controllers

                Here is me converting the original Xbox for a case:
                https://retropie.org.uk/forum/topic/15232/converting-original-xbox-into-case-for-raspberrypi/15
                Check out my GitHub: https://github.com/retro-programmer

                1 Reply Last reply Reply Quote 0
                • E
                  ezra84
                  last edited by

                  Very cool feature!

                  Would be fantastic if the indicator could function similarly as the overheating or power shortage icons on the top right of the screen.

                  1 Reply Last reply Reply Quote 0
                  • H
                    Heyoeyo @zerojay
                    last edited by Heyoeyo

                    @zerojay said in Wireless Battery Indicator (PS3):

                    Anyone have this functional at all right now?

                    I haven't had a chance to use the newer hcidump method since I gifted my pi to a friend a while back. Now I have another one, so I might give it a shot this weekend!

                    @retroprogrammer said in Wireless Battery Indicator (PS3):

                    can we incorporate it into other controllers

                    Maybe, depending on how the other controllers work/connect to the pi. I get the feeling it's not a standardised system, so it probably needs to be tailored to each controller type (though once each implementation is figured out, a single script could check for all known types).

                    @ezra84 said in Wireless Battery Indicator (PS3):

                    Very cool feature!

                    Would be fantastic if the indicator could function similarly as the overheating or power shortage icons on the top right of the screen.

                    Do you mean a similar look/graphics of the icons, or similar in the sense of having a (low battery) warning?

                    E 1 Reply Last reply Reply Quote 0
                    • Z
                      zerojay
                      last edited by

                      @Heyoeyo Let me know if you need anyone to help with testing.

                      1 Reply Last reply Reply Quote 0
                      • E
                        ezra84 @Heyoeyo
                        last edited by

                        @heyoeyo I mean in the sense of having a low battery warning. That should be more important than the looks, but of course it would be nice if it can be implemented in the same style as the other warning icons.

                        1 Reply Last reply Reply Quote 0
                        • L
                          Lore88
                          last edited by

                          Hello,
                          i tried to install this https://github.com/heyoeyo/batteryCheck
                          on my Raspberry Pi3 running Retropie v4.3 but once i try to run batteryCheck.py i obtain the following error

                          Traceback (most recent call last):
                          File "batCheck.py", line 98, in <module>
                          time_stamp = os.stat(logPath).st_mtime;
                          OSError: [Errno 2] No such file or directory: '/var/log/sixad'

                          infact /var/log/sixad does not exists

                          S 1 Reply Last reply Reply Quote 0
                          • E
                            eviltrooper
                            last edited by

                            dont work with latest retropie Version :(

                            1 Reply Last reply Reply Quote 0
                            • madmodder123M
                              madmodder123
                              last edited by

                              If someone wants to get real fancy they could use pngview to make something like this : https://github.com/d-rez/gbz_overlay

                              1 Reply Last reply Reply Quote 1
                              • S
                                silverbullet @Lore88
                                last edited by

                                @Heyoeyo do you know if the BatteryCheck script can be updated to work on the newer release of RetroPie?

                                madmodder123M 1 Reply Last reply Reply Quote 0
                                • madmodder123M
                                  madmodder123 @silverbullet
                                  last edited by

                                  @silverbullet
                                  You would have to check the log files for whatever PS3 driver is running by default and then possible edit the lines of code it is searching for.
                                  /var/log/sixad is the old one for the sixad driver, not sure where the other drivers logs are at.

                                  S 1 Reply Last reply Reply Quote 0
                                  • S
                                    silverbullet @madmodder123
                                    last edited by

                                    @madmodder123 I tried looking for that, but I don't see that sixad is logging on my system anymore. It looks like the logrotate is setup to rotate the logs in that /var/log/sixad file, but that file doesn't exist. I looked through the documentation and I don't see any mention of logging. I am not sure if the logging was removed and the remnants of the log rotation weren't removed? If you have any suggestions of where the logs are now stored, I would appreciate it.

                                    Thanks!

                                    madmodder123M 1 Reply Last reply Reply Quote 0
                                    • madmodder123M
                                      madmodder123 @silverbullet
                                      last edited by

                                      @silverbullet
                                      So I did a little detective work.
                                      It looks like in RetroPie 4.4/Stretch the /var/log/sixad file was removed and the logs for sixad are sent to journald ("/run/log/journal/44377289e4ad47738189eab7cbdb463a/system.journal" on my Pi) and i'm not sure if the script can read from that file as it contains a bunch of different logs.

                                      to test this you can try changing batCheck.py from
                                      "logPath='/var/log/sixad'" to "logPath='/run/log/journal/44377289e4ad47738189eab7cbdb463a/system.journal'" (note the big string of characters in the file path is probably different on your Pi!) and then running the script

                                      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.