You are not logged in.
Pages: 1
Hi.
First, an absolutely necessary foreword:
I'm planning to buy a ThinkPad T410s. It has a nice special battery chip, making it possible to have much better means of power management.
For instance, one can put in an additional (so called "Ultrabay") battery and the special kernel module "tp_smapi"
(read more about it here: http://www.thinkwiki.org/wiki/Tp_smapi) lets one take control of how it is handled (see below)
The thing is, the default behavior is to drain ultrabay completely, but this causes its capacity to deplete quickly. That's why there are certain tp_smapi's options like "force_discharge" which tell the laptop to ex. drain main battery first, the use ultrabay battery. But it is quite a hassle to manually switch to ultrabay when main runs out, etc.
That's why such script has been created:
http://www.thinkwiki.org/wiki/Talk:Code/tp-bat-balance
It's supposed to manually switch main and ultrabay back and forth to ensure exual discharge all the time, as I understand it.
But I cannot use it in my laptop if I am not 100% sure what it does! It is not really documented, and I'm not a coder.
Understanding bash scripts isn't really rocket science, but with Perl, it is much different.
So I kindly ask you:
Could you please, in normal english describe what it does? (ex. which condition needs to be met to execute a specific command)
Thanks in advance!
PS.: And if you do, I could put the description into ThinkWiki's tp-bat-balance site, so that everybody (not only Perl programmers) know what it does
Offline
Could you please, in normal english describe what it does?
# while true, also known as "loop forever"
while (1) {
# Read battery status from tp_smapi sysfs interface
read_status;
# Print status to stdout (ASCII graphics)
print_status;
# Choose which battery to discharge
choose_discharge;
# wait 5 seconds and start again
sleep(5);
}
pretty straight forward script .
edit: actually the in-script comments say it better...
Last edited by brisbin33 (2010-06-14 19:10:33)
//github/
Offline
That's an idea I had about this script. It was quite predictable
Can you tell me something more about this?
my $thresh = 3; # difference between battery charge levels that justifies switching (hysteresis)
I'm interested how it compares batteries. Does it use the percentage? And what difference does it need to be to trigger the change?
PS.:
I've read this:
http://en.wikipedia.org/wiki/Histeresis
and my physics teacher tried to teach my class about histeresis, but we're all biological/chemistry class, so good luck with that. Could You please expain it in simpler words?
I presume it has something to do with the charge percentage difference
(the one which is required to trigger the battery change)
to change over time, as both percentages change.
Pretty confusing, no? Sorry, english is not my mother tongue.
I judge this only by the following graph:
http://en.wikipedia.org/wiki/File:B-H_loop.png
so this was just a pure guess of mine. Feel free to correct
Last edited by warnec (2010-06-14 19:14:29)
Offline
get the remaining percentage (it appears) for each battery
$bat_remaining[$b] = read_chomp_file("$smapi_dir/BAT$b/remaining_percent");
compare them and decide based on the threshold
if ($bat_remaining[0] > $bat_remaining[1] + $thresh) {
set_force_discharge(0,1);
set_force_discharge(1,0);
} elsif ($bat_remaining[1] > $bat_remaining[0] + $thresh) {
set_force_discharge(0,0);
set_force_discharge(1,1);
}
//github/
Offline
1) how is $thresh defined? What is it supposed to do in these two funtions? Why is it added? :
$bat_remaining[0] > $bat_remaining[1] + $thresh
&
$bat_remaining[1] > $bat_remaining[0] + $thresh
2) why such a weird (at least to me) syntax?
set_force_discharge(0,1);
set_force_discharge(1,0);
&
set_force_discharge(0,0);
set_force_discharge(1,1);
if I understood correctly, force_discharge just accepts one argument - 0 (main battery) or 1 (ultrabay battery)
so how does this work?
Last edited by warnec (2010-06-14 21:21:05)
Offline
i no longer have the script open (and i don't feel like reopening) so this is from memory...
1) how is $thresh defined? What is it supposed to do in these two funtions? Why is it added?
$thresh is defined by the simple `my $thresh = 3` line that you quoted to me. I assume it's there so that the script doesn't switch batteries the instance that BAT0 hits 99.999%, then back when BAT1 hits 99.998%, then back again when BAT0 hits 99.997% and so on, and so on.
$bat_remaining[0] > $bat_remaining[1] + $thresh & $bat_remaining[1] > $bat_remaining[0] + $thresh
the first statement means if battery zero's remaining percent is greater than (battery one's remaining percent plus 3), then...; and the second statement is just the reverse, if battery one's remaining percent is greater than (battery zero's remaining percent plus 3), then.... if neither of these statements are true, then the threshold his not met (the two battery's percentages are within 3% of each other) and no battery switching should happen.
2) why such a weird (at least to me) syntax?
set_force_discharge(0,1); set_force_discharge(1,0); & set_force_discharge(0,0); set_force_discharge(1,1);
set_force_discharge takes two arguments. the battery to set (BAT0 or BAT1) and the value to set it to (0 = don't discharge, 1 = discharge).
so, the above statements would be equivalent to:
tell BAT0 to discharge
tell BAT1 to not discharge
&
tell BAT0 to not discharge
tell BAT1 to discharge
which is exactly what you need to do depending on the results of your if statements.
Last edited by brisbin33 (2010-06-14 21:48:57)
//github/
Offline
Thanks! I think it explains it all.
Offline
Pages: 1