General TC > Programming & Scripting - Unofficial
acpid scripts for laptop Fn+F2/3/6/7/8 functions
nick65go:
--- Quote from: Rich on May 20, 2020, 02:08:21 PM ---
Or you could just launch a script in the background that sleeps 99.9999% of the time and occasionally reads the remaining
battery capacity directly:
--- Code: ---#!/bin/sh
# Short script to monitor remaining percent of battery power.
# Check /sys/class/power_supply to find how your battery is named.
#
# Usage:
# BatteryMonitor.sh BatteryName &
#
# Example:
# BatteryMonitor.sh BAT0 &
[ -z "$1" ] && exit
# The percentage that triggers a warning.
WarningLevel=5
# Number of minutes to sleep before checking capacity again.
SleepMinutes=5
PowerPath="/sys/class/power_supply"
BatteryName="$1"
Capacity="$PowerPath/$BatteryName/capacity"
SleepTime="60 * $SleepMinutes"
while true
do
sleep "$SleepTime"
RemainingCapacity="`cat $Capacity`"
[ "$RemainingCapacity" -gt "$WarningLevel" ] && continue
popup "Remaining battery capacity is $RemainingCapacity%%"
done
--- End code ---
--- End quote ---
I think SleepTime="60 * $SleepMinutes" is not working, because " ", and multiplication not allowed, only sum/diff
--- Code: ---sleep: invalid number '60 * 5'
--- End code ---
--- Code: ---tc@box:~$ echo `expr 60 + 5`
65
tc@box:~$ echo `expr 60 * 5`
expr: syntax error
tc@box:~$ calc 60 + 5
65
tc@box:~$ calc 60 * 5
awk: cmd. line:1: Unexpected token
tc@box:~$ calc 60*5
300
--- End code ---
so, it should be
--- Code: ---SleepTime=`calc 60*$SleepMinutes`
--- End code ---
Rich:
Hi nick65go
You caught me. I didn't test that part of the script. I set SleepTime directly equal to 5 because I wasn't going to wait 5 minutes.
However, you can do multiplication without using calc. I know, because I've seen roberts use it in the tc-config script. I just
checked his script and the correct syntax is:
--- Code: ---SleepTime=$((60 * $SleepMinutes))
--- End code ---
This shows up in the waitusb section of tc-config. He also uses the same syntax for division.
nick65go:
Thank you. Good catch. I tested , it works :)
Rich:
Hi nick65go
The text and the attachment in reply #22 have been corrected. Thank you for bringing this issue to my attention. :)
nick65go:
This is just a remainder to myself. It is a good practice to first kill a daemon then start it again, if the daemon is in /home/tc/.X.d/*. Otherwise if I get out of Xorg (with Ctrl+Alt+Backspace), and then start it again (with starrtx), few pairs of zombie daemons processes can be seen with top.The BatteryMonitor.sh should be sent in the background (with &) otherwise nothing will run after it (it is a infinite loop).
my /home/tc/.X.d/myacpi.sh
--- Code: ---#!/bin/sh
# lower brightness, from default 255 to 32
echo 32 | sudo tee /sys/class/backlight/radeon_bl0/brightness &
#start acpid daemon for F2/3(brightness), F6/7/8(sound), and LID
sudo kill `pidof acpid`
echo 1
sudo /usr/local/sbin/acpid
echo 2
echo powersupersave | sudo tee /sys/module/pcie_aspm/parameters/policy
echo 3
#stop wire-network if we use wifi
[ -e /var/run/udhcpc.eth0.pid ] && sudo kill `cat /var/run/udhcpc.eth0.pid`
echo 4
#stop orfans daemons (/sbin/udevd --daemon) for firmware
sudo kill `pidof udevd`
echo 5
#start crond daemon for battery low 2%
#sudo kill `pidof crond`
#sudo /usr/local/sbin/crond &
sudo kill `pidof BatteryMonitor.sh` `pidof sleep`
/home/tc/.acpi/BatteryMonitor.sh BAT0 &
echo 6
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version