remove extra stuff
parent
d188ecb3f7
commit
f881a11388
|
|
@ -1,19 +1,7 @@
|
|||
#!/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="DEBUG"
|
||||
|
|
@ -38,18 +26,6 @@ function logInfo() {
|
|||
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
|
||||
function shutdownCommand() {
|
||||
|
|
@ -84,19 +60,21 @@ function getChargeCurrent() {
|
|||
|
||||
# shuts the system down if too less voltage
|
||||
function verifyBatteryVoltage() {
|
||||
isBatteryAvailable
|
||||
if [ "$?" -eq "1" ] ; then
|
||||
echo "$(isBatteryAvailable)"
|
||||
if [ "$(isBatteryAvailable)" -eq "1" ] ; then
|
||||
local voltage=$(getBatteryVoltage)
|
||||
chargeCurrent=$(getChargeCurrent)
|
||||
log "battery charge current [${chargeCurrent}mV] min current [${SHUTDOWN_MIN_BATTERY_CURRENT}mV]"
|
||||
if [ $(echo "$voltage <= $SHUTDOWN_MIN_BATTERY_VOLTAGE" | bc) -eq "1" ] ; then
|
||||
log "critical battery voltage [${voltage}mV] min voltage [${SHUTDOWN_MIN_BATTERY_VOLTAGE}mV]"
|
||||
if [ $(echo "$chargeCurrent <= $SHUTDOWN_MIN_BATTERY_CURRENT" | bc) -eq "1" ] ; then
|
||||
shutdownCommand "shutting down due to low voltage/charge current"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
log "battery voltage [${voltage}mV] min voltage [${SHUTDOWN_MIN_BATTERY_VOLTAGE}mv]"
|
||||
local chargeCurrent=$(getChargeCurrent)
|
||||
echo "Voltage: $voltage"
|
||||
echo "Charge Current: $chargeCurrent"
|
||||
#log "battery charge current [${chargeCurrent}mV] min current [${SHUTDOWN_MIN_BATTERY_CURRENT}mV]"
|
||||
#if [ $(echo "$voltage <= $SHUTDOWN_MIN_BATTERY_VOLTAGE" | bc) -eq "1" ] ; then
|
||||
# log "critical battery voltage [${voltage}mV] min voltage [${SHUTDOWN_MIN_BATTERY_VOLTAGE}mV]"
|
||||
# if [ $(echo "$chargeCurrent <= $SHUTDOWN_MIN_BATTERY_CURRENT" | bc) -eq "1" ] ; then
|
||||
# shutdownCommand "shutting down due to low voltage/charge current"
|
||||
# fi
|
||||
# return
|
||||
#fi
|
||||
#log "battery voltage [${voltage}mV] min voltage [${SHUTDOWN_MIN_BATTERY_VOLTAGE}mv]"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -131,12 +109,11 @@ function main() {
|
|||
while true ; do
|
||||
setLed 1
|
||||
verifyBatteryVoltage
|
||||
verifyButton
|
||||
setLed 0
|
||||
sleep 3
|
||||
done
|
||||
}
|
||||
|
||||
# start monitoring in subshell and nonblocking
|
||||
$(main)&
|
||||
exit 0
|
||||
$(main)
|
||||
#exit 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue