Created
January 7, 2016 18:16
-
-
Save Jooshboy/68793914490b90b1cdd8 to your computer and use it in GitHub Desktop.
Returns AC connection status from an AXP209 PMU via I2C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This program gets the power status (AC IN or BAT) | |
# I2C interface with AXP209 | |
# | |
####################################################################### | |
# Copyright (c) 2014 by RzBo, Bellesserre, France | |
# | |
# Permission is granted to use the source code within this | |
# file in whole or in part for any use, personal or commercial, | |
# without restriction or limitation. | |
# | |
# No warranties, either explicit or implied, are made as to the | |
# suitability of this code for any purpose. Use at your own risk. | |
####################################################################### | |
#read Power status register @00h | |
POWER_STATUS=$(i2cget -y -f 0 0x34 0x00) | |
#echo $POWER_STATUS | |
# bit 7 : Indicates ACIN presence 0: ACIN does not exist; 1: ACIN present | |
#echo " bit 7 : Indicates ACIN presence 0: ACIN does not exist; 1: ACIN present " | |
#echo " bit 2 : Indicates that the battery current direction 0: battery discharge; 1: The battery is charged " | |
AC_STATUS=$(($(($POWER_STATUS&0x80))/128)) # divide by 128 is like shifting rigth 8 times | |
#echo $(($POWER_STATUS&0x80)) | |
echo " AC_STATUS= "$AC_STATUS | |
# echo $AC_STATUS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment