Mednafen Members Members   Search Search   Help Help   Register Register   Login Login   Home Home
Home » Other » General » Dualshock DS4 led colour to show batery status - linux
Show: Today's Messages  :: Show Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
icon1.gif  Dualshock DS4 led colour to show batery status - linux [message #6184] Sat, 09 May 2020 08:16
mobius  [PM]
Hello,

I want to share with you all a small utility I created.

As you probably know, when using DS4 controllers, the first one will have the led colour be blue, the second will have the colour be red, and so on.

I wanted three things:
A. To have the colour be green (it feels more personalized).
B. To be dimmer (uses less battery and thus increases use time)
C. Indicate battery level and alert when it was almost depleted.

So I came up with this small script. It reads the battery capacity and then sets the led brightness accordingly at green colour. When the battery capacity reaches 10%, it will flash the light several times as a way to indicate that it is time to charge it.

Currently it only does this for the first joystick/controller. If you have connected/paired more than one, the others are not changed.

1. Save the attached file (a bash shell script) somewhere, eg. ~/Downloads
2. Copy this file to '/usr/local/sbin' with ownership root:root, and set the execute atributes
sudo cp Downloads/ds4leds.sh /usr/local/sbin
sudo chmod a+x /usr/local/sbin/ds4leds.sh

If you now run it from the command line by issuing 'sudo ds4leds.sh' you will see the led brightness dim and set to green, while also reporting some information.

3. What is needed now, is for this script to run periodically every minute. We do this by adding a crontab entry for the root user.
sudo crontab -e

You will be opening an editor to modify the current crontab for root.
In there, add a new line at the very end of that file, and that line should be exactly like this:

* * * * * /usr/local/sbin/ds4leds.sh | logger

4. Exit the editor saving the file. Verify that all was saved properly with the command:
sudo crontab -l

You should see what you just edited in the editor above.
And that's it.

If you check the syslog, you should find there every minute the same reporting lines that you saw when you ran the script manually.

Sample run:
mx@seagmx:~:$ ls -l /usr/local/sbin/ds4leds.sh 
-rwxr-xr-- 1 root root 2534 May  7 00:46 /usr/local/sbin/ds4leds.sh
mx@seagmx:~:$
mx@seagmx:~:$ sudo ds4leds.sh
[sudo] password for mx: 
There is joystick device present
DS4 device is: 0005:054C:09CC.0003 ; unique identifier: dc:af:68:ef:28:92
Batery at: 90%. We will now change to: red=0 , green=4 , blue=0
mx@seagmx:~:$
mx@seagmx:~:$ sudo tail /var/log/syslog
May  9 17:08:01 seagmx root: DS4 device is: 0005:054C:09CC.0003 ; unique identifier: dc:af:68:ef:28:92
May  9 17:08:02 seagmx root: Batery at: 90%. We will now change to: red=0 , green=4 , blue=0
May  9 17:09:02 seagmx CRON[10100]: (root) CMD (/usr/local/sbin/ds4leds.sh | logger)
May  9 17:09:02 seagmx root: There is joystick device present
May  9 17:09:02 seagmx root: DS4 device is: 0005:054C:09CC.0003 ; unique identifier: dc:af:68:ef:28:92
May  9 17:09:02 seagmx root: Batery at: 90%. We will now change to: red=0 , green=4 , blue=0
May  9 17:10:01 seagmx CRON[10291]: (root) CMD (/usr/local/sbin/ds4leds.sh | logger)
May  9 17:10:01 seagmx root: There is joystick device present
May  9 17:10:01 seagmx root: DS4 device is: 0005:054C:09CC.0003 ; unique identifier: dc:af:68:ef:28:92
May  9 17:10:01 seagmx root: Batery at: 90%. We will now change to: red=0 , green=4 , blue=0
mx@seagmx:~:$
mx@seagmx:~:$
mx@seagmx:~:$ sudo crontab -l
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command

* * * * * /usr/local/sbin/ds4leds.sh | logger
mx@seagmx:~:$

  • Attachment: ds4leds.sh
    (Size: 2.34KB, Downloaded 123 time(s))

[Updated on: Sat, 09 May 2020 09:29]

  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic:sushi
Next Topic:Quick Question about some Abbrevations
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ ]

Current Time: Fri May 17 02:07:24 CDT 2024
.:: Contact :: Home ::.

Powered by FUDforum.
Copyright © FUDforum Bulletin Board Software