Skip to content

Instantly share code, notes, and snippets.

@maluta
Last active December 21, 2015 13:08
Show Gist options
  • Select an option

  • Save maluta/6310364 to your computer and use it in GitHub Desktop.

Select an option

Save maluta/6310364 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
import threading
INTERVALO=1 #segundos
def open_uevent():
# abrimos o arquivo e vemos
uevent = open("/sys/class/power_supply/mc13892_bat/uevent",'r')
# a saida é num vetor, escolhemos a posição que nos interessa, no caso 9
linha = uevent.readlines()[9]
# filtramos e convertermos para inteiro
status = int(linha.split('=')[1])
return status
def check_battery_status():
global s
ns = open_uevent()
if s > ns:
s = ns
t = time.ctime()
print "bateria: " + str(s) + " " + t
threading.Timer(INTERVALO, check_battery_status).start()
# main
if __name__=="__main__":
s = open_uevent()
#print s
check_battery_status()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment