parent
bd6e9a4ad6
commit
82e972ffa7
@ -0,0 +1,64 @@
|
||||
# Battery Status LED
|
||||
Battery (low/critical) status indication by making a (the capslock) LED blink
|
||||
|
||||
## Prerequisites:
|
||||
Make sure you have your laptop's ACPI module compiled into your kernel:
|
||||
```
|
||||
Device Drivers > X86 Platform Specific Device Drivers
|
||||
```
|
||||
|
||||
For example: Asus laptop extras, ThinkPad ACPI Laptop Extras, etc.
|
||||
|
||||
## Usage:
|
||||
Execute the script as a root user:
|
||||
```
|
||||
/usr/bin/battery-status-led.sh
|
||||
```
|
||||
|
||||
Or start with systemd:
|
||||
```
|
||||
systemctl start battery-status-led
|
||||
systemctl enable battery-status-led
|
||||
```
|
||||
|
||||
The LED device can be changed by editing the systemd service file's line:
|
||||
```
|
||||
Environment="BATTERY_STATUS_LED_DEV=/sys/class/leds/input4\:\:capslock"
|
||||
```
|
||||
|
||||
## Manual install on gentoo:
|
||||
```
|
||||
cd DIR
|
||||
git clone https://github.com/dmatetelki/battery-status-led
|
||||
cd /usr/local/portage/app-misc/
|
||||
ln -s DIR/battery-status-led/app-misc/battery-status-led battery-status-led
|
||||
ebuild battery-status-led-0.1.ebuild digest
|
||||
emerge battery-status-led
|
||||
```
|
||||
|
||||
## Creating a debian package and installing it:
|
||||
```
|
||||
cd DIR
|
||||
git clone https://github.com/dmatetelki/battery-status-led
|
||||
cd battery-status-led/debian
|
||||
./package.deb
|
||||
sudo dpkg -i ./batterystatusled_0.1-1.deb
|
||||
```
|
||||
|
||||
## Creating RPM package and installing it:
|
||||
```
|
||||
cd DIR
|
||||
git clone https://github.com/dmatetelki/battery-status-led
|
||||
cd battery-status-led/redhat
|
||||
./package.rpm
|
||||
sudo rpm -i ./battery-status-led-0.1-1.noarch.rpm
|
||||
```
|
||||
|
||||
## Note:
|
||||
Did you know that the CapsLock key can be turned into another Ctrl?
|
||||
Add the following lines to `~/.Xmodmap` :
|
||||
```
|
||||
remove Lock = Caps_Lock
|
||||
keycode 0x42 = Control_L
|
||||
add Control = Control_L
|
||||
```
|
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2018 Denes Matetelki
|
||||
|
||||
# This file is part of battery-status-led.
|
||||
|
||||
# battery-status-led is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License v3 as published by the Free
|
||||
# Software Foundation.
|
||||
|
||||
# battery-status-led is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License v3 for
|
||||
# more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License v3 along
|
||||
# with battery-status-led. If not, see
|
||||
# https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
|
||||
# limits in percentages
|
||||
LOW=10 # flip LED every 2s
|
||||
CRIT=5 # flip led every 0.5s
|
||||
|
||||
BAT_FULL_DEV=/sys/class/power_supply/BAT0/energy_full_design
|
||||
BAT_STATUS_DEV=/sys/class/power_supply/BAT0/status
|
||||
BAT_NOW_DEV=/sys/class/power_supply/BAT0/energy_now
|
||||
CAPSLOCK_LED_DEV=/sys/class/leds/input4\:\:capslock/brightness
|
||||
|
||||
# If not set by the systemd service file
|
||||
LED_DEV=${BATTERY_STATUS_LED_DEV:-$CAPSLOCK_LED_DEV}
|
||||
|
||||
BAT_FULL=$(cat $BAT_FULL_DEV)
|
||||
|
||||
LED=0
|
||||
while :
|
||||
do
|
||||
# If charging, sleep 1m, then restart the cycle
|
||||
STATUS=$(cat $BAT_STATUS_DEV)
|
||||
if [ $STATUS == "Charging" ] ; then
|
||||
echo 0 > $LED_DEV
|
||||
sleep 1m
|
||||
continue
|
||||
fi
|
||||
|
||||
BAT_NOW=$(cat $BAT_NOW_DEV)
|
||||
BAT_PCT=$(($BAT_NOW * 100 / $BAT_FULL))
|
||||
|
||||
# If battery has more than >10% left, sleep 1m then restart the cycle
|
||||
if (($BAT_PCT >= $LOW )) ; then
|
||||
sleep 1m
|
||||
continue
|
||||
fi
|
||||
|
||||
# If battery is on low, but not crytical, flip LED every 2s
|
||||
if (( $BAT_PCT < $LOW )) && (( $BAT_PCT >= $CRIT)) ; then
|
||||
LED=$((1 ^ $LED))
|
||||
echo $LED > $LED_DEV
|
||||
sleep 2s
|
||||
continue
|
||||
fi
|
||||
|
||||
# If battery is on crytical flip capslock LED every 0.5s
|
||||
if (( $BAT_PCT < $CRIT )) ; then
|
||||
LED=$((1 ^ $LED))
|
||||
echo $LED > $LED_DEV
|
||||
sleep 0.5s
|
||||
continue
|
||||
fi
|
||||
done
|
||||
|
@ -0,0 +1,38 @@
|
||||
.TH BATTERY-STATUS-LED 1 LOCAL
|
||||
|
||||
.SH NAME
|
||||
.B battery-status-led
|
||||
\- Blink a LED on low battery
|
||||
|
||||
.SH SYNOPSIS
|
||||
battery-status-led
|
||||
|
||||
.SH DESCRIPTION
|
||||
Battery (low/critical) status indication by making a (the capslock) LED blink
|
||||
|
||||
Takes no argument. To pick another LED device, edit
|
||||
.I /lib/systemd/system/battery-status-led.service
|
||||
and modify
|
||||
.I BATTERY_STATUS_LED_DEV
|
||||
to something else. The default value is
|
||||
.I /sys/class/leds/input4\:\:capslock
|
||||
|
||||
.SH AUTHOR
|
||||
.MT denes.matetelki@gmail.com
|
||||
Denes Matetelki
|
||||
.ME
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
Homepage:
|
||||
.UR https://github.com/dmatetelki/battery-status-led/
|
||||
.UE
|
||||
|
||||
.br
|
||||
Copyright © 2018 Denes Matetelki.
|
||||
.br
|
||||
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
|
||||
.br
|
||||
This is free software: you are free to change and redistribute it.
|
||||
.br
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Battery monitoring on CapsLock LED
|
||||
|
||||
[Service]
|
||||
Environment="BATTERY_STATUS_LED_DEV=/sys/class/leds/input4\:\:capslock"
|
||||
ExecStart="/usr/bin/battery-status-led.sh"
|
||||
Type=idle
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -0,0 +1,46 @@
|
||||
Name: battery-status-led
|
||||
Version: 0.1
|
||||
Release: 1%{?dist}
|
||||
URL: https://github.com/dmatetelki/battery-status-led
|
||||
Packager: Denes Matetelki <denes.matetelki@gmail.com>
|
||||
|
||||
Summary: Battery status indication on an LED
|
||||
|
||||
Group: Utilities
|
||||
License: GPLv3
|
||||
BuildArch: noarch
|
||||
|
||||
Source0: battery-status-led.service
|
||||
Source1: battery-status-led
|
||||
Source2: README.md
|
||||
Source3: battery-status-led.1
|
||||
|
||||
%description
|
||||
Battery (low/critical) status indication by making a (the caps-lock) LED blink
|
||||
|
||||
# %prep
|
||||
|
||||
%install
|
||||
mkdir -p %{buildroot}%{_unitdir}
|
||||
install -p -m 0644 %{SOURCE0} %{buildroot}%{_unitdir}
|
||||
mkdir -p %{buildroot}/%{_bindir}
|
||||
install -p -m 755 %{SOURCE1} %{buildroot}/%{_bindir}
|
||||
mkdir -p %{buildroot}/%{_docdir}/battery-status-led
|
||||
install -p -m 0644 %{SOURCE2} %{buildroot}%{_docdir}/battery-status-led/
|
||||
mkdir -p %{buildroot}/%{_mandir}/man1
|
||||
install -p -m 0644 %{SOURCE3} %{buildroot}%{_mandir}/man1/
|
||||
|
||||
%clean
|
||||
rm -rf %{buildroot}
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%{_unitdir}/battery-status-led.service
|
||||
%{_bindir}/battery-status-led
|
||||
%{_docdir}/battery-status-led/README.md
|
||||
%{_mandir}/man1/battery-status-led.1.*
|
||||
|
||||
%changelog
|
||||
* Fri Aug 31 2018 Denes Matetelki <denes.matetelki@gmail.com> - 0.1-1
|
||||
- Initial release
|
||||
|
Loading…
Reference in new issue