bug correction in low_bat_check
This commit is contained in:
parent
d95fba5154
commit
4dd0ad57d6
|
@ -1,11 +1,11 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# General constants declaration
|
# General constants declaration
|
||||||
THRESHOLD_PERCENT_LOW_BAT=5
|
THRESHOLD_PERCENT_LOW_BAT=105
|
||||||
THRESHOLD_PERCENT_EXTREMELY_LOW_BAT=2
|
THRESHOLD_PERCENT_EXTREMELY_LOW_BAT=2
|
||||||
MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN=5
|
MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN=5
|
||||||
SLEEP_SECS=2
|
SLEEP_SECS=2
|
||||||
RESCALE_MAX_PERCENTAGE=110
|
RESCALE_MAX_PERCENTAGE=112
|
||||||
|
|
||||||
# Blink Low bat constants declaration
|
# Blink Low bat constants declaration
|
||||||
BLINK_ICON=0
|
BLINK_ICON=0
|
||||||
|
@ -33,9 +33,9 @@ echo 0 > ${LOW_BAT_ICON}
|
||||||
|
|
||||||
# Check low bat #
|
# Check low bat #
|
||||||
while true; do
|
while true; do
|
||||||
#echo "Bat present: "$(cat ${BAT_PRESENT_FILE})"
|
#echo "Bat present: $(cat ${BAT_PRESENT_FILE})"
|
||||||
#echo "USB present: "$(cat ${USB_PRESENT_FILE})"
|
#echo "USB present: $(cat ${USB_PRESENT_FILE})"
|
||||||
#echo "Bat percentage: "$(cat ${BAT_PERCENT_FILE})"
|
#echo "Bat percentage: $(cat ${BAT_PERCENT_FILE})"
|
||||||
|
|
||||||
# Get current bat percentage here once
|
# Get current bat percentage here once
|
||||||
cur_bat_percent=$(cat ${BAT_PERCENT_FILE})
|
cur_bat_percent=$(cat ${BAT_PERCENT_FILE})
|
||||||
|
@ -55,64 +55,64 @@ while true; do
|
||||||
# Low bat status detection
|
# Low bat status detection
|
||||||
if [ "$(cat ${USB_PRESENT_FILE})" -eq "0" ]; then
|
if [ "$(cat ${USB_PRESENT_FILE})" -eq "0" ]; then
|
||||||
|
|
||||||
# Value of 0 means wrong i2c reading
|
# Value of 0 means wrong i2c reading
|
||||||
if [ "${cur_bat_percent}" -ne "0" ]; then
|
if [ "${cur_bat_percent}" -ne "0" ]; then
|
||||||
|
|
||||||
# Check if we must change state
|
# Check if we must change state
|
||||||
if [ {$cur_bat_percent} -le ${THRESHOLD_PERCENT_LOW_BAT} -a ${low_bat_status} -eq 0 ]; then
|
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_LOW_BAT} -a ${low_bat_status} -eq 0 ]; then
|
||||||
|
|
||||||
# Set Low Bat status
|
# Set Low Bat status
|
||||||
low_bat_status=1
|
low_bat_status=1
|
||||||
low_bat_displayed=1
|
low_bat_displayed=1
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
echo 1 > ${LOW_BAT_ICON}
|
echo 1 > ${LOW_BAT_ICON}
|
||||||
|
|
||||||
elif [ ${cur_bat_percent} -gt ${THRESHOLD_PERCENT_LOW_BAT} -a ${low_bat_status} -eq 1 ]; then
|
elif [ ${cur_bat_percent} -gt ${THRESHOLD_PERCENT_LOW_BAT} -a ${low_bat_status} -eq 1 ]; then
|
||||||
|
|
||||||
# Reset status
|
# Reset status
|
||||||
low_bat_status=0
|
low_bat_status=0
|
||||||
cur_nb_extremely_low_bat_before_shutdown=0
|
cur_nb_extremely_low_bat_before_shutdown=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ ${low_bat_status} -eq 1 ]; then
|
if [ ${low_bat_status} -eq 1 ]; then
|
||||||
|
|
||||||
# Reset status
|
# Reset status
|
||||||
low_bat_status=0
|
low_bat_status=0
|
||||||
cur_nb_extremely_low_bat_before_shutdown=0
|
cur_nb_extremely_low_bat_before_shutdown=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Low bat processing
|
# Low bat processing
|
||||||
if [ ${low_bat_status} -eq 1 ]; then
|
if [ ${low_bat_status} -eq 1 ]; then
|
||||||
|
|
||||||
# Check extremely low bat for clean shutdown
|
# Check extremely low bat for clean shutdown
|
||||||
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_EXTREMELY_LOW_BAT} ]; then
|
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_EXTREMELY_LOW_BAT} ]; then
|
||||||
let cur_nb_extremely_low_bat_before_shutdown++
|
let cur_nb_extremely_low_bat_before_shutdown++
|
||||||
echo "cur_nb_extremely_low_bat_before_shutdown = ${cur_nb_extremely_low_bat_before_shutdown}"
|
echo "cur_nb_extremely_low_bat_before_shutdown = ${cur_nb_extremely_low_bat_before_shutdown}"
|
||||||
|
|
||||||
# Clean shutdown
|
# Clean shutdown
|
||||||
if [ ${cur_nb_extremely_low_bat_before_shutdown} -ge ${MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN} ]; then
|
if [ ${cur_nb_extremely_low_bat_before_shutdown} -ge ${MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN} ]; then
|
||||||
echo "Battery extremely low, shutting down now..."
|
echo "Battery extremely low, shutting down now..."
|
||||||
sched_shutdown 1 & signal_usr1_to_emulators
|
sched_shutdown 1 & signal_usr1_to_emulators
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Blinking process
|
# Blinking process
|
||||||
if [ ${BLINK_ICON} -eq 1 ]; then
|
if [ ${BLINK_ICON} -eq 1 ]; then
|
||||||
if [ ${low_bat_displayed} -eq 1 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_DISPLAYED} ]; then
|
if [ ${low_bat_displayed} -eq 1 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_DISPLAYED} ]; then
|
||||||
low_bat_displayed=0
|
low_bat_displayed=0
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
elif [ ${low_bat_displayed} -eq 0 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_NOT_DISPLAYED} ]; then
|
elif [ ${low_bat_displayed} -eq 0 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_NOT_DISPLAYED} ]; then
|
||||||
low_bat_displayed=1
|
low_bat_displayed=1
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
echo 1 > ${LOW_BAT_ICON}
|
echo 1 > ${LOW_BAT_ICON}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Sleep before next check
|
# Sleep before next check
|
||||||
|
|
Loading…
Reference in New Issue