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

    [IDEA AND START OF DEVELOPMENT]Battery Check For All Controllers

    Scheduled Pinned Locked Moved Ideas and Development
    batterycheckcontrollerwirelessdevelopment
    5 Posts 2 Posters 1.3k 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.
    • retroprogrammerR
      retroprogrammer
      last edited by

      Hey guys, I am trying to make a script which basically tells you how much battery is left of your wireless controller, Because I don't have all controllers I am going to need some help.
      I got this idea off this post: https://retropie.org.uk/forum/topic/12945/wireless-battery-indicator-ps3
      if any one does have some screen shots of how sixad log file path: /var/log/sixad
      looks like please post :)

      But instead of getting the battery level from the sixad log file path: /var/log/sixad
      we get it from: /sys/class/power_supply/what_ever_controller_ac:fd:21:d1:7c:24/capacity

      Here is an example script:

      #!/bin/bash
      
      # Specify log file path
      logPath='sys/class/power_supply/what_ever_controller_ac:fd:21:d1:7c:24/capacity'
      
      # Create array of controller position names
      ctrlPosition=('First' 'Second' 'Third' 'Fourth')
      ctrlIndex=0
      
      # Create array to store battery levels
      batLevels=('dead' 'low' '25%' '50%' '75%' '100%')
      
      # Create a container to store message text
      dialogTxt=$""
      
      
      # Extract and loop through the most recent lines of the log file which contain the word 'Battery'
      tac $logPath | grep -m 1 -B1000 "Watching" | tac | grep "Battery" | 
      {
      while read -r line ; do
      
      	# Print out raw info (for debugging)
      	#echo "$line"
      
      	# Extract PID values from battery print-outs
      	chkPID=$(echo "$line" | grep -oP '(?<=[).*(?=]:)')
      
      	# Check if PID is still running. If so, get the battery value
      	if ps -p "$chkPID" > /dev/null ; then
      		# Extract battery value (0-5)
      		batIndex=$(echo "$line" | grep -oP '(?<=Battery 0).*(?=])')
      
      		# Append battery level text to any existing text
      		dialogTxt+=$"${ctrlPosition[ctrlIndex]} controller battery level is at ${batLevels[batIndex]}\n\n"
      
      		# Increment the controller index, in case there are multiple controller PIDs
      		((ctrlIndex++))
      	fi	
      	
      done
      
      
      # Check to see if no controllers were detected (ctrlIndex wasn't incremented above)
      if [[ "$ctrlIndex" -eq "0" ]] ; then
      	dialogTxt=$"No wireless controllers detected!"
      fi
      
      # Create message box containing battery info
      dialog --no-mouse --ok-label "OK" --backtitle "Battery Check" --msgbox "$dialogTxt" 12 60 2>&1 > /dev/tty
      }
      

      I practically copyed and pasted the https://retropie.org.uk/forum/topic/12945/wireless-battery-indicator-ps3 code that was there and made a few adjustments I didn't do
      to much[changed a few word ;)] as I am not the best with this type of stuff but will try my best!

      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 1
      • retroprogrammerR
        retroprogrammer
        last edited by

        the example does not work, I just put it their as well a 'example' for us to base of :)

        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
        • retroprogrammerR
          retroprogrammer
          last edited by

          Any one have any ideas?

          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
          • cyperghostC
            cyperghost
            last edited by cyperghost

            @retroprogrammer
            Your suggestion does not work in general. The powerlevel-feature via /sys/class is a design in the joypad firmware and can change from company to company :(

            Maybe the hcidump-method introduced by @psyke83 is a more valueable way. If you want you can make a script collection to read out known controllers.

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

              @cyperghost yeah, I will try to do that

              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
              • 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.