summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-09-12 15:40:55 +0200
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-09-12 15:40:55 +0200
commite4e7b019fe5266d2d8f7b106871da2fed5910c88 (patch)
treefa406fd2f887a47b08c1eb1e38503ee3887586e9
downloadcoreboot-battery-threshold-e4e7b019fe5266d2d8f7b106871da2fed5910c88.tar.gz
coreboot-battery-threshold-e4e7b019fe5266d2d8f7b106871da2fed5910c88.tar.bz2
coreboot-battery-threshold-e4e7b019fe5266d2d8f7b106871da2fed5910c88.zip
Initial commit
-rw-r--r--coreboot-battery-threshold49
-rw-r--r--coreboot-battery-threshold.service9
2 files changed, 58 insertions, 0 deletions
diff --git a/coreboot-battery-threshold b/coreboot-battery-threshold
new file mode 100644
index 0000000..0511cc6
--- /dev/null
+++ b/coreboot-battery-threshold
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+if [ "$EUID" -ne 0 ]
+  then echo "This script needs to be run as root."
+  exit 1
+fi
+
+START_CHARGE_THRESH=""
+STOP_CHARGE_THRESH=""
+
+print_usage() {
+  echo "Usage: coreboot-battery-threshold [FLAG]"
+  echo "  Flags:"
+  echo "    [-s]: NEEDED   : start % for the battery to start charging"
+  echo "    [-p]: NEEDED   : stop % for the battery to stop charging"
+  echo "    [-h]: OPTIONAL : print help message"
+}
+
+while getopts 's:p:h' flag; do
+  case "${flag}" in
+    s) START_CHARGE_THRESH="${OPTARG}"    ;;
+    p) STOP_CHARGE_THRESH="${OPTARG}"     ;;
+    h) print_usage
+       exit 0                             ;;
+    *) print_usage
+       exit 1                             ;;
+  esac
+done
+
+if [ "$START_CHARGE_THRESH" == "" ]; then
+  print_usage
+  exit 1
+fi
+
+if [ "$STOP_CHARGE_THRESH" == "" ]; then
+  print_usage
+  exit 1
+fi
+
+
+#convert to hex
+START_CHARGE_HEX=$(printf '%x\n' $START_CHARGE_THRESH)
+STOP_CHARGE_HEX=$(printf '%x\n' $STOP_CHARGE_THRESHi)
+
+#Set start charge
+ectool -w 0xb0 -z 0x$START_CHARGE_HEX &>/dev/null
+
+#Set stop charge
+ectool -w 0xb1 -z 0x$STOP_CHARGE_HEX &>/dev/null
diff --git a/coreboot-battery-threshold.service b/coreboot-battery-threshold.service
new file mode 100644
index 0000000..4f03888
--- /dev/null
+++ b/coreboot-battery-threshold.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Set battery thresholds on corebooted devices
+
+[Service]
+Type=simple
+ExecStart=/data/bin/coreboot-battery-threshold -s 67 -p 100
+
+[Install]
+WantedBy=multi-user.target