Verificar status de carga da bateria do notebook
Publicado por Sandro Marcell (última atualização em 07/03/2014)
[ Hits: 14.968 ]
Homepage: http://sanmarcell.wordpress.com
Download 1381087011.battery_status (versão 2)
Download 1394198886.battery_status (versão 3)
De férias do trampo e sem ter muito o que fazer por enquanto :), criei esse simples Shell Script que mostra o status da carga da bateria do notebook, em forma de barra, porcentagem e tempo estimado restante para o fim total de carga da mesma. Não é lá essas coisas, mas funciona! Sugestões e melhorias serão bem-vindas. ;)
Versão 2 - Enviado por Sandro Marcell em 06/10/2013
Changelog: Remoção do POG! ;)
Download 1381087011.battery_status
Versão 3 - Enviado por Sandro Marcell em 07/03/2014
Changelog: Remoção da POG e algumas melhorias sutis... =)
Download 1394198886.battery_status
#!/bin/bash
#
# Copyright 2013 Sandro Marcell <smarcell@myopera.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
PATH='/bin:/usr/bin:/usr/local/bin'
bateria='BAT0'
# Codigo UTF-8 para 'seta para cima' e 'seta para baixo'
seta_cima='\u2191'
seta_baixo='\u2193'
exec 3< /sys/class/power_supply/${bateria}/energy_now; read -u3 capacidade_restante; exec 3<&-
exec 3< /sys/class/power_supply/${bateria}/energy_full; read -u3 capacidade_total; exec 3<&-
exec 3< /sys/class/power_supply/${bateria}/status; read -u3 estado_bateria; exec 3<&-
exec 3< /sys/class/power_supply/${bateria}/power_now; read -u3 taxa_bateria; exec 3<&-
((carga = capacidade_restante * 100 / capacidade_total))
# Tempo restante estimado de carga
((taxa_bateria == 0)) && taxa_bateria=1 # POG!!! :P 100% de carga
horas=$(bc <<< "(1.0 * $capacidade_restante) / (1.0 * $taxa_bateria)")
minutos=$(bc <<< "(60.0 * $capacidade_restante) / $taxa_bateria - ($horas * 60)")
case "$estado_bateria" in
'Full')
status_bateria="{FONTE}33[1m=={FONTE}33[0m"
info='Bateria recarregada';;
'Charging')
status_bateria="{FONTE}33[1m${seta_cima}${seta_cima}{FONTE}33[0m"
info='Bateria carregando...';;
'Discharging')
status_bateria="{FONTE}33[1m${seta_baixo}${seta_baixo}{FONTE}33[0m"
info="Tempo restante estimado = ${horas}h:${minutos}m"
esac
cor=32 # Codigo ANSI para cor verde
if ((carga < 15)); then
cor=31 # Vermelho
elif ((carga <= 50)); then
cor=33 # Amarelo
fi
# Mostra a barra
while ((i++ < carga)); do
(($i % 2 == 0)) && echo -ne "{FONTE}33[7;${cor}m {FONTE}33[0m"
done
echo -e " {FONTE}33[1;${cor}m${carga}%{FONTE}33[0m\n$status_bateria $info"
ListPkg [Procura de pacote no Slackware]
createrootkde - programas do KDE 5 como root
Freeradius 2.x.x - Monitoração
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Instalando partes faltantes do Plasma 6
Adicionar botão "mostrar área de trabalho" no Zorin OS
Como montar um servidor de backup no linux
Estou tentando ser legalista, mas tá complicado! (9)
espelhar monitores nao funciona (2)
SQLITE não quer funcionar no LINUX LMDE6 64 com Lazaruz 4.2 64bit (n... (1)









