Skip to content

Instantly share code, notes, and snippets.

@Jooshboy
Created January 7, 2016 18:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jooshboy/68793914490b90b1cdd8 to your computer and use it in GitHub Desktop.
Save Jooshboy/68793914490b90b1cdd8 to your computer and use it in GitHub Desktop.
Returns AC connection status from an AXP209 PMU via I2C
#!/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