From fde2fefff132beb69c1cf0b732ae96c09d94a07a Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Thu, 12 Nov 2015 13:45:12 -0500 Subject: [PATCH 1/3] Fast bash >= 3 lint What? EXPR and BC? --- axpd.sh | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/axpd.sh b/axpd.sh index 871bd59..b0b9c82 100755 --- a/axpd.sh +++ b/axpd.sh @@ -1,20 +1,15 @@ -#! /bin/bash -hex2dec(){ - echo 'ibase=16; obase=A; '"$1" | bc -} +#!/bin/bash checkbit(){ - [ $(( $1 & $(( 1 << $2 )) )) != 0 ] + (( $1 & (1 << $2) )) } rmmod -f battery -modprobe i2c-dev +modprobe i2c-dev modprobe test_power -for i in 4 12 -do - if find /sys | grep axp288_charger | grep -q i2c-$i/ - then - export ADDR=$i - fi -done +case "$(find /sys | grep axp288_charger)" in + (*i2c-12*) export ADDR=12;; + (*i2c-4*) export ADDR=4;; + (*) echo "WTF?"; exit 1;; +esac while true do rmmod battery 2>/dev/null @@ -35,12 +30,10 @@ do echo off > /sys/module/test_power/parameters/usb_online echo discharging > /sys/module/test_power/parameters/battery_status fi - hex=$(i2cget -f -y $ADDR 0x34 0xb9 | cut -c 3- | tr a-z A-Z) - capacity=$(expr $(hex2dec $hex) - 128) - if [ $capacity -ge 0 ] + ((capacity = $(i2cget -f -y $ADDR 0x34 0xb9) - 128)) + if ((capacity > 0)) then echo $capacity | tee /sys/module/test_power/parameters/battery_capacity fi sleep 10 done - From c7015801a5ed8f9eb7ce70ce1a1897fa9004757b Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Thu, 12 Nov 2015 13:47:54 -0500 Subject: [PATCH 2/3] Fast POSIX.1:2013 find lint What? grep? --- axpd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axpd.sh b/axpd.sh index b0b9c82..cf7209b 100755 --- a/axpd.sh +++ b/axpd.sh @@ -5,7 +5,7 @@ checkbit(){ rmmod -f battery modprobe i2c-dev modprobe test_power -case "$(find /sys | grep axp288_charger)" in +case "$(find /sys -path '*axp288_charger*')" in (*i2c-12*) export ADDR=12;; (*i2c-4*) export ADDR=4;; (*) echo "WTF?"; exit 1;; From fa3a533e4d467ca121933bf531a60aa97a060e98 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Thu, 12 Nov 2015 13:55:08 -0500 Subject: [PATCH 3/3] Oh, I know C --- axpd.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/axpd.sh b/axpd.sh index cf7209b..96a5bb0 100755 --- a/axpd.sh +++ b/axpd.sh @@ -30,8 +30,7 @@ do echo off > /sys/module/test_power/parameters/usb_online echo discharging > /sys/module/test_power/parameters/battery_status fi - ((capacity = $(i2cget -f -y $ADDR 0x34 0xb9) - 128)) - if ((capacity > 0)) + if (( (capacity = $(i2cget -f -y $ADDR 0x34 0xb9) - 128) > 0)) then echo $capacity | tee /sys/module/test_power/parameters/battery_capacity fi