Jump to content

Recommended Posts

Posted
A small patch addressing some power monitoring related issues:

 

1. The script was always writing to the "REG 82H: ADC Enable 1" register (on each login).

2. The value being written (0xC3, raising bit 6) was overwriting the old one, wiping out other bits that may have been enabled.

   On my cubietruck for instance it defaults to 0xFF, not 0x83, so that "i2cset" call was effectively disabling/zeroing the 

   /sys/class/power_supply/ac/current_now thing that I use for calculating and graphing the power usage in munin.

3. Raising that flag (bit 6, Battery current ADC enable) seems irrelevant to the bash.bashrc.custom script,

   as it doesn't appear to read that current anyway, just the voltage (bit 7), which seems already enabled by default.

   So that "i2cset" call could be entirely removed without affecting functionality.



--- /etc/bash.bashrc.custom-dist 2015-10-11 15:11:20.000000000 +0200
+++ /etc/bash.bashrc.custom 2015-11-03 16:07:41.000000000 +0100
@@ -83,7 +83,9 @@ HARDWARE=$(cat /proc/cpuinfo | grep Hard
# for root users which have acces to hw and allwinner and old kernel
if [[ "$UID" == 0 && "$(uname -r | cut -c 1-3)" == "3.4" && ($HARDWARE = "sun7i" || $HARDWARE = "Allwinner") ]]; then

-i2cset -y -f 0 0x34 0x82 0xC3
+if [ "$(printf '0x%X' $(($(i2cget -y -f 0 0x34 0x82) & 0xC3)))" != "0xC3" ]; then
+ i2cset -y -f 0 0x34 0x82 0xC3
+fi
# read power OPERATING MODE register @01h
POWER_OP_MODE=$(i2cget -y -f 0 0x34 0x01)
BAT_EXIST=$(($(($POWER_OP_MODE&0x20))/32)) # divide by 32 is like shifting rigth 5 times



Thanks,

Atanas

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines