#!/system/bin/sh


while true

do

  RAW=$(cat /sys/class/power_supply/battery/voltage_now)

  VOLT=$(expr $RAW / 1000)  # Convert to millivolts


  # Map voltage to percent manually (based on 18650 profile)

  if [ $VOLT -ge 4200 ]; then

    PCT=100

  elif [ $VOLT -ge 4100 ]; then

    PCT=90

  elif [ $VOLT -ge 4000 ]; then

    PCT=80

  elif [ $VOLT -ge 3900 ]; then

    PCT=70

  elif [ $VOLT -ge 3800 ]; then

    PCT=60

  elif [ $VOLT -ge 3700 ]; then

    PCT=50

  elif [ $VOLT -ge 3600 ]; then

    PCT=40

  elif [ $VOLT -ge 3500 ]; then

    PCT=30

  elif [ $VOLT -ge 3400 ]; then

    PCT=20

  elif [ $VOLT -ge 3300 ]; then

    PCT=10

  else

    PCT=5

  fi


  echo "[Battery 18650] Voltage: ${VOLT}mV = ${PCT}%" > /dev/kmsg

  sleep 60

done


Post a Comment

0 Comments