General TC > Programming & Scripting - Unofficial
acpid scripts for laptop Fn+F2/3/6/7/8 functions
Rich:
Hi nick65go
Attached is a modified version of the script. It now also shows percent of charge remaining in a little display in the lower right
corner of the screen. The display gets updated every 5 minutes. The text is normally white. When remaining charge drops
to 20%, it turns yellow. When it drops to 10%, it turns red. When it drops to 5%, you get a popup just like before. There are
variables for setting the percentages at which the colors change. You can also change the XY coordinates of the display as
well as the font.
nick65go:
Hi Rich, Thank you!
Remarks regarding my acpid daemon, the default path for configuration events are:
in TC11_x64, /etc/acpi/events,
but in TC11_x86 they are in /usr/local/etc/acpi/events:
--- Code: ---tc@box:~$ uname -a
Linux box 5.4.3-tinycore #2020 SMP Tue Dec 17 17:00:50 UTC 2019 i686 GNU/Linux
tc@box:~$ sudo acpid -d
Deprecated /proc/acpi/event was not found. Trying netlink and the input layer...input layer /dev/input/event0 opened successfully
input layer /dev/input/event1 opened successfully
input layer /dev/input/event2 opened successfully
input layer /dev/input/event3 opened successfully
input layer /dev/input/event6 opened successfully
input layer /dev/input/event7 opened successfully
inotify fd: 9
inotify wd: 1
netlink opened successfully
acpid: starting up with netlink and the input layer
parsing conf file /usr/local/etc/acpi/events/all
acpid: 1 rule loaded
acpid: waiting for events: event logging is off
^Cacpid: exiting
tc@box:~$
--- End code ---
so, the command should be sudo acpid -c your/path/to/acpi/events/folder
nick65go:
@Rich: BatteryMonitorDisplay.sh works nice.
But using "top" is see 4 processes: aterm -geometry..; sh -..; cat /dev/..; slepp ..; and {BatteryMonitorD}..;
I propose to add few instructions to "sudo kill" two of them, so it will remain only sleep and aterm -geometry. Is it OK?
--- Code: ---tc@box:~$ BatteryMonitorDisplay.sh BAT0 &
tc@box:~$
--- End code ---
--- Code: ---tc@box:~$ top
.. 7927 7926 tc S 3716 0.1 2 0.0 aterm -geometry 4x1+1860+1060 -fn 10x20 -bl -si -sb -sk -sl 0 -fade 100 -e sh -c MyTTY=`tty`; while true; do cat
7533 7532 tc S 3320 0.1 2 0.0 sh
7884 7883 tc S 3320 0.1 1 0.0 sh
2958 1 tc S 3316 0.1 3 0.0 -sh
1 0 root S 3248 0.1 0 0.0 /sbin/init
7926 7884 tc S 3248 0.1 0 0.0 {BatteryMonitorD} /bin/sh /home/tc/.local/bin/BatteryMonitorDisplay.sh BAT0
7934 7927 tc S 3248 0.1 1 0.0 sh -c MyTTY=`tty`; while true; do cat $MyTTY; done
7936 7934 tc S 3112 0.1 0 0.0 cat /dev/pts/2
7953 7926 tc S 3112 0.1 2 0.0 sleep 300
7705 1 root S 1792 0.0 2 0.0 /usr/local/sbin/acpid
6849 2 root SW< 0 0.0 1 0.0 [loop108]
--- End code ---
Rich:
Hi nick65go
--- Quote from: nick65go on May 27, 2020, 06:50:10 PM --- ... I propose to add few instructions to "sudo kill" two of them, so it will remain only sleep and aterm -geometry. Is it OK? ...
--- End quote ---
I'm not sure what you want to kill, but I think you'll break it if you try.
Take a look at what's really happening and see if you still think you can kill something.
When you open a terminal, here is what you get:
--- Code: ---tc@ASUS:~$ pstree -p 12953
aterm(12953)---sh(12954)
tc@ASUS:~$
--- End code ---
A terminal and a shell.
Now I launch BatteryMonitorDisplay.sh from that terminal into the background:
--- Code: ---tc@ASUS:~$ BatteryMonitorDisplay.sh BATC &
tc@ASUS:~$ pstree -p 12953
aterm(12953)---sh(12954)---BatteryMonitorD(12973)-+-aterm(12974)---sh(12981)---cat(12983)
`-sleep(13015)
tc@ASUS:~$
--- End code ---
BatteryMonitorDisplay.sh launches a terminal in the background that runs cat on its tty.
BatteryMonitorDisplay.sh sends the value of $RemainingCapacity to the terminals tty.
BatteryMonitorDisplay.sh executes a 5 minute sleep command. The script will do nothing for 5 minutes.
As long as nothing is being sent to the terminals tty , it will block cat from executing. The cat command sleeps until data is available.
When sleep times out and exits, BatteryMonitorDisplay.sh is allowed to run.
BatteryMonitorDisplay.sh sends the value of $RemainingCapacity to the terminals tty.
Then sleep 5 minutes, send $RemainingCapacity, sleep 5 minutes, send $RemainingCapacity ........
Now I close the original terminal that I started with and we are left with this:
--- Code: ---tc@ASUS:~$ pstree -p 12973
BatteryMonitorD(12973)-+-aterm(12974)---sh(12981)---cat(12983)
`-sleep(13015)
tc@ASUS:~$
--- End code ---
With the original terminal gone, BatteryMonitorDisplay.sh now belongs to init , also known as PID #1.
Navigation
[0] Message Index
[*] Previous page
Go to full version