remove extra stuff

master
Bryan 2021-01-01 19:48:11 -06:00
parent d188ecb3f7
commit f881a11388
1 changed files with 17 additions and 40 deletions

View File

@ -1,19 +1,7 @@
#!/bin/bash/ #!/bin/bash/
# #
# @author Raoul R., 2016 # library based on work by: @author Raoul R., 2016
# #
# This script watches (polls) the battery state and the gpio $POWER_BUTTON_GPIO pin level.
# If pin is pulled to GND the script initiates a shut down.
#
# SHUTDOWN_MIN_BATTERY_VOLTAGE ... [mV]
SHUTDOWN_MIN_BATTERY_VOLTAGE=2100.0
# SHUTDOWN_MIN_BATTERY_VOLTAGE ... [mA]
SHUTDOWN_MIN_BATTERY_CURRENT=20.0
# see http://docs.getchip.com/#how-you-see-gpio
POWER_BUTTON_GPIO_NUMBER="414"
POWER_BUTTON_GPIO="/sys/class/gpio/gpio$POWER_BUTTON_GPIO_NUMBER"
# LOG_LEVEL ... DEBUT | INFO # LOG_LEVEL ... DEBUT | INFO
LOG_LEVEL="DEBUG" LOG_LEVEL="DEBUG"
@ -38,18 +26,6 @@ function logInfo() {
logger -t "PME" "$message" logger -t "PME" "$message"
} }
function setupGpioInputButton()
{
if [ ! -e ${POWER_BUTTON_GPIO} ] ; then
echo "$POWER_BUTTON_GPIO_NUMBER" > /sys/class/gpio/export
fi
echo "in" > ${POWER_BUTTON_GPIO}/direction > /dev/null 2>&1
echo "0" > ${POWER_BUTTON_GPIO}/active_low > /dev/null 2>&1
}
function cleanupGpioInputButton() {
echo "$POWER_BUTTON_GPIO_NUMBER" > /sys/class/gpio/unexport
}
# $1 ... message # $1 ... message
function shutdownCommand() { function shutdownCommand() {
@ -84,19 +60,21 @@ function getChargeCurrent() {
# shuts the system down if too less voltage # shuts the system down if too less voltage
function verifyBatteryVoltage() { function verifyBatteryVoltage() {
isBatteryAvailable echo "$(isBatteryAvailable)"
if [ "$?" -eq "1" ] ; then if [ "$(isBatteryAvailable)" -eq "1" ] ; then
local voltage=$(getBatteryVoltage) local voltage=$(getBatteryVoltage)
chargeCurrent=$(getChargeCurrent) local chargeCurrent=$(getChargeCurrent)
log "battery charge current [${chargeCurrent}mV] min current [${SHUTDOWN_MIN_BATTERY_CURRENT}mV]" echo "Voltage: $voltage"
if [ $(echo "$voltage <= $SHUTDOWN_MIN_BATTERY_VOLTAGE" | bc) -eq "1" ] ; then echo "Charge Current: $chargeCurrent"
log "critical battery voltage [${voltage}mV] min voltage [${SHUTDOWN_MIN_BATTERY_VOLTAGE}mV]" #log "battery charge current [${chargeCurrent}mV] min current [${SHUTDOWN_MIN_BATTERY_CURRENT}mV]"
if [ $(echo "$chargeCurrent <= $SHUTDOWN_MIN_BATTERY_CURRENT" | bc) -eq "1" ] ; then #if [ $(echo "$voltage <= $SHUTDOWN_MIN_BATTERY_VOLTAGE" | bc) -eq "1" ] ; then
shutdownCommand "shutting down due to low voltage/charge current" # log "critical battery voltage [${voltage}mV] min voltage [${SHUTDOWN_MIN_BATTERY_VOLTAGE}mV]"
fi # if [ $(echo "$chargeCurrent <= $SHUTDOWN_MIN_BATTERY_CURRENT" | bc) -eq "1" ] ; then
return # shutdownCommand "shutting down due to low voltage/charge current"
fi # fi
log "battery voltage [${voltage}mV] min voltage [${SHUTDOWN_MIN_BATTERY_VOLTAGE}mv]" # return
#fi
#log "battery voltage [${voltage}mV] min voltage [${SHUTDOWN_MIN_BATTERY_VOLTAGE}mv]"
fi fi
} }
@ -131,12 +109,11 @@ function main() {
while true ; do while true ; do
setLed 1 setLed 1
verifyBatteryVoltage verifyBatteryVoltage
verifyButton
setLed 0 setLed 0
sleep 3 sleep 3
done done
} }
# start monitoring in subshell and nonblocking # start monitoring in subshell and nonblocking
$(main)& $(main)
exit 0 #exit 0