View Single Post
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#49
Ok, I dug up my python code and here it is. I couldn't find my newest version of it, though I have no idea where it went...

Code:
#!/bin/env python

# Copyright (C) 2009, Brent Chiodo

import commands
import time
import dbus, dbus.service

def average(list):
	total = 0
	count = 0

	for each in list:
		count = count + 1
		total = total + float(each)
	return total / count

date_stamp = commands.getoutput('date +"%-m-%-d-%-Y"' + '.csv')
cycle = 0
battery_log = []

commands.getoutput("mkdir pybattery_logs/")

while(cycle < 480):

   add_time = commands.getoutput('date +"%l:%M %p"')
   battery_level = commands.getoutput('sudo ./check_retu 8 9')
   battery_log.append(battery_level)

   if len(battery_log) > 120:
      del battery_log[0]

   logfile = open('pybattery_logs/' + date_stamp, 'a')
   logfile.write('"%s","%s"\n' % (add_time, battery_level))
   logfile.close()

   if len(battery_log) < 11:
      battery_average = average(battery_log)

   else:
      battery_average = average(battery_log[-10:-1])

   if ((battery_average - 300) / 200 > 1):
      print "Battery: 100%"

   else:
      print "Battery: %.1f%s" % ((((battery_average - 300) / 200) * 100), '%')

   cycle + 1

   print battery_log[-1]

   time.sleep(60)
check_retu is a hacked version of Matan's retu-adc. It is attached.

This program basically just polls the retu every minute and writes it to a log file. It then uses that data to calculate (albeit completely unrefined) the battery level. Feel free to use this code

Edit: The forum messed up th indenting. You'll need to fix it.
Attached Files
File Type: gz check_retu.tar.gz (3.2 KB, 147 views)

Last edited by BrentDC; 2009-01-29 at 04:33.
 

The Following User Says Thank You to BrentDC For This Useful Post: