Final energytrace commits. #98

This commit is contained in:
Travis Goodspeed 2018-08-29 12:12:09 -04:00
parent 8c4519aafa
commit d403231821
3 changed files with 57 additions and 3 deletions

42
bin/batterylife.py Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/python3
## This is a quick little python script that takes the output of
## energytrace-util, averages the current consumption for all samples
## after ten seconds, and then predicts battery life from a 100mAH
## CR2016 battery.
## Usage: et 60 | python3 batterylife.py
import sys;
capacity=100 #mAH
ampsum=0.0;
ampcount=0;
#Ugly shotgun parser to ignore comments and early records.
for line in sys.stdin:
if line[0]=='#':
pass;
else:
words=line.split();
time=float(words[0]);
amps=float(words[1]);
milliamps=amps*1000.0;
#We only count after the first 10 seconds, as booting takes 5 seconds.
if time>10.0:
ampcount=ampcount+1;
ampsum=ampsum+amps;
if ampcount>0:
ampavg=ampsum/(ampcount*1.0);
milliamp=ampavg*1000.0;
microamp=ampavg*1000000.0;
print("%f µA average consumption"%microamp);
hours=100/milliamp;
days=hours/24.0;
years=days/365.2425;
months=years*12.0;
print("%f months of CR2016 battery life."%months);

View File

@ -125,7 +125,8 @@ dump:
energytrace.txt: goodwatch.hex sbwflash
et 30 > energytrace.txt
energytrace.png: energytrace.txt energytrace.gnuplot
et 60 > energytrace.txt #This will take a minute.
gnuplot energytrace.gnuplot
gnuplot energytrace-txt.gnuplot
../bin/batterylife.py <energytrace.txt

View File

@ -0,0 +1,11 @@
set terminal dumb
set title "GoodWatch Current Consumption" font ",20"
set xlabel "Seconds"
set ylabel "Current"
set yrange [0:10e-06]
set xrange [20:25]
plot "energytrace.txt" with lines;