public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Johan Vromans <jvromans-2pNSKKP3PSKEVqv0pETR8A@public.gmane.org>
To: acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: first shoot for smartbattery
Date: Sun, 09 Jan 2005 14:41:52 +0100	[thread overview]
Message-ID: <m2oefyzplr.fsf@phoenix.squirrel.nl> (raw)
In-Reply-To: <41DAB539.2020605-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org> (Pedro Venda's message of "Tue, 04 Jan 2005 15:24:41 +0000")

[-- Attachment #1: Type: text/plain, Size: 611 bytes --]

Pedro Venda <pjvenda-pQd4kjVL+RHfqL7NgpvPWWD2FQJk+8+b@public.gmane.org> writes:

> I actually read some of the pdf you pointed me to and implemented a
> couple of functions on the smartbattery.c. It now gets much more
> information from the battery. If you find it relevant, I'll clean it
> up a bit and post a patch for you. I know it will soon be dumped,
> but it may show useful when debugging other driver informations.

The attached program produces a nice battery status display using your
modified version of battstat. It may be temporary, but at least now I
have decent battery info at hand.

-- Johan


[-- Attachment #2: battstat.pl --]
[-- Type: application/octet-stream, Size: 3068 bytes --]

#!/usr/bin/perl -w

# Quick hack to get a battery status display.
# Uses Pedro Venda's modified version of Bruno Ducrot's version
# of the smart battery reader (not included).
#
# Copyright 2005 Johan Vromans, Squirrel Consultancy.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

use strict;
use Tk;
use Tk::ProgressBar;

################ Configuration ################

my $interval = 10;		# Poll interval
my $prog = "smartbattery2 0";	# command

# Regular output of $prog is:
#
#	status:			discharging	initialized
#	mode:			capacity in 10 mW/mWh
#	design voltage:		14800 mV
#	design charge capacity:	4400 mAh or mWh
#	absolute charge:	90%
#	full charge capacity:	4270 mAh or mWh
#	relative charge:	93%
#	current:		-908 mA
#	voltage:		16271 mV
#	remain:			3966 mA
#	average time to empty:	261 minutes
#	average time to full:	65535 minutes
#	temperature:		24.2 C
#	cycle count:		12

################ End Configuration ################

my $status = 0;

my $mw = MainWindow->new;
$mw->title("Battery: Starting");

my $p = $mw->ProgressBar
  (-troughcolor => 'LightSkyBlue3',
   -borderwidth => 0,
   -length => 120,
   -width => 8,
   -variable => \$status,
   -colors => [0 => 'red', 10 => 'yellow', 20 => 'green'],
   #	 -blocks => 10,		# default
   -anchor => 'w',
   -from => 0,
   -to => 100,
  )->pack(-expand => 1);

# Check every 10 seconds.
$mw->repeat (10000, \&update);

my $state = 0;
update();

MainLoop;

sub update {

    my $res = `smartbattery2 $smbus 2>&1`;
    return unless $res;

    my ($current, $fill, $time, $tp);
    $current = $1 if $res =~ /current:\s+(-?\d+)\s+ma/i;
    $tp = $current < 0 ? 'empty' : 'full';
    $fill = $1    if $res =~ /relative charge:\s+(\d+)%/i;
    $time = $1    if $res =~ /average time to $tp:\s+(\d+)\s+minutes/i;
    if ( $time ) {
	my ($h, $m);
	$h = int($time / 60);
	$m = $time % 60;
	$time = sprintf("%d:%02d", $h, $m);
    }

    if ( $current > 0 ) {	# charging
	$status = 0;
    }
    elsif ( $current < 0 ) {	# discharging
	$status = $fill;
    }
    else {			# fully charged
	$status = 100;
    }
    $mw->title("Battery: $time ($status%)");

    # This is a kludge to get the ProgressBar to display uniform, but
    # different colours depending on the fill status.

    if ( $status >= 30 ) {
	if ( $state < 30 ) {
	    $p->{Configure}{-colors} = [ 0, 'green' ];
	    $p->{Configure}{-troughcolor} = 'darkgreen';
	    Tk::ProgressBar::_layoutRequest($p, 1);
	    $state = 30;
	}
    }
    elsif ( $status >= 10 ) {
	if ( $state < 10 || $state >= 30 ) {
	    $p->{Configure}{-colors} = [ 0, 'yellow' ];
	    $p->{Configure}{-troughcolor} = 'orange';
	    Tk::ProgressBar::_layoutRequest($p, 1);
	    $state = 10;
	}
    }
    elsif ( $state >= 10 ) {
	$p->{Configure}{-colors} = [ 0, 'red' ];
	$p->{Configure}{-troughcolor} = 'darkred';
	Tk::ProgressBar::_layoutRequest($p, 1);
	$state = 0;
    }
}

  parent reply	other threads:[~2005-01-09 13:41 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20041231092156.GA612@phys.ethz.ch>
     [not found] ` <20041231092156.GA612-vpGm2Noi6jeZvKxeG3EEhw@public.gmane.org>
2004-12-31 14:19   ` i2c-acpi-ec.c Pedro Venda
     [not found]     ` <41D56002.5060008-aHmAgkVUFT6Joy8PIJZ9VA@public.gmane.org>
2004-12-31 15:07       ` i2c-acpi-ec.c Bruno Ducrot
     [not found]         ` <20041231150724.GK19199-kk6yZipjEM5g9hUCZPvPmw@public.gmane.org>
2004-12-31 18:16           ` first shoot for smartbattery (was Re: Re: i2c-acpi-ec.c) Bruno Ducrot
     [not found]             ` <20041231181628.GL19199-kk6yZipjEM5g9hUCZPvPmw@public.gmane.org>
2004-12-31 18:48               ` François Valenduc
     [not found]                 ` <41D59F15.2030504-IWqWACnzNjyZIoH1IeqzKA@public.gmane.org>
2004-12-31 19:09                   ` Bruno Ducrot
2005-01-01  8:26               ` Mathias Weyland
     [not found]                 ` <20050101082605.GA24896-vpGm2Noi6jeZvKxeG3EEhw@public.gmane.org>
2005-01-01 10:08                   ` first shoot for smartbattery Johan Vromans
     [not found]                     ` <m2acrth375.fsf-KjnUIgV0B0bak1Ioo/c9IoRWq/SkRNHw@public.gmane.org>
2005-01-01 22:33                       ` François Valenduc
2005-01-03 13:45                       ` Bruno Ducrot
2005-01-03 14:39                       ` Bruno Ducrot
     [not found]                         ` <20050103143902.GQ19199-kk6yZipjEM5g9hUCZPvPmw@public.gmane.org>
2005-01-03 14:55                           ` Mathias Weyland
     [not found]                             ` <41D95CDC.8050802-vpGm2Noi6jeZvKxeG3EEhw@public.gmane.org>
2005-01-03 15:05                               ` François Valenduc
     [not found]                                 ` <41D95F53.5000008-IWqWACnzNjyZIoH1IeqzKA@public.gmane.org>
2005-01-03 15:41                                   ` François Valenduc
     [not found]                                     ` <41D967B5.7040002-IWqWACnzNjyZIoH1IeqzKA@public.gmane.org>
2005-01-03 17:02                                       ` liste-9nAOAgdJVo4b1SvskN2V4Q
     [not found]                                         ` <Pine.LNX.4.60.0501031751590.5329-KnfdeQs3A3X/9pzu0YdTqQ@public.gmane.org>
2005-01-03 17:54                                           ` Bruno Ducrot
     [not found]                                             ` <20050103175449.GW19199-kk6yZipjEM5g9hUCZPvPmw@public.gmane.org>
2005-01-04  1:56                                               ` Pedro Venda
     [not found]                                                 ` <41D9F7CA.7030408-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-04 10:24                                                   ` Bruno Ducrot
     [not found]                                                     ` <20050104102424.GC19199-kk6yZipjEM5g9hUCZPvPmw@public.gmane.org>
2005-01-04 15:27                                                       ` Pedro Venda
     [not found]                                                         ` <41DAB5C7.9040605-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-06  8:51                                                           ` Bruno Ducrot
     [not found]                                                             ` <20050106085149.GJ19199-kk6yZipjEM5g9hUCZPvPmw@public.gmane.org>
2005-01-11 10:05                                                               ` Pedro Venda
2005-01-03 15:08                               ` Bruno Ducrot
2005-01-03 17:03                           ` Pedro Venda
     [not found]                             ` <41D97AF3.7000409-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-03 17:34                               ` Bruno Ducrot
2005-01-03 17:35                               ` Pedro Venda
     [not found]                                 ` <41D98251.9020002-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-03 18:02                                   ` Bruno Ducrot
     [not found]                                     ` <20050103180219.GX19199-kk6yZipjEM5g9hUCZPvPmw@public.gmane.org>
2005-01-03 19:50                                       ` Pedro Venda
     [not found]                                         ` <41D9A1F5.1060508-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-03 20:30                                           ` Johan Vromans
     [not found]                                             ` <m2mzvq5k7u.fsf-KjnUIgV0B0bak1Ioo/c9IoRWq/SkRNHw@public.gmane.org>
2005-01-13 12:44                                               ` Johannes Kuhlmann
     [not found]                                                 ` <47e0449d05011304446094c8b-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2005-01-16 20:44                                                   ` Johan Vromans
     [not found]                                                     ` <m2fz11gl3c.fsf-KjnUIgV0B0bak1Ioo/c9IoRWq/SkRNHw@public.gmane.org>
2005-01-17  9:31                                                       ` Fionn Behrens
2005-01-17  9:55                                                         ` Johan Vromans
     [not found]                                                           ` <m2pt04qt1j.fsf-KjnUIgV0B0bak1Ioo/c9IoRWq/SkRNHw@public.gmane.org>
2005-01-17 11:49                                                             ` Johannes Kuhlmann
     [not found]                                                               ` <47e0449d050117034912fb9ae3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2005-01-17 12:37                                                                 ` Fernando Gómez
2005-01-17 19:41                                                       ` Johannes Kuhlmann
     [not found]                                                         ` <47e0449d050117114113973694-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2005-01-18  9:49                                                           ` Johan Vromans
2005-01-04  7:47                                           ` Jeroen Wijnhout
2005-01-04 10:08                                           ` Bruno Ducrot
     [not found]                                             ` <20050104100844.GA19199-kk6yZipjEM5g9hUCZPvPmw@public.gmane.org>
2005-01-04 14:33                                               ` François Valenduc
     [not found]                                                 ` <41DAA92C.4080605-IWqWACnzNjyZIoH1IeqzKA@public.gmane.org>
2005-01-04 14:45                                                   ` Johannes Kuhlmann
     [not found]                                                     ` <47e0449d05010406454e59b16a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2005-01-05 18:14                                                       ` Pavel Machek
2005-01-04 15:24                                               ` Pedro Venda
     [not found]                                                 ` <41DAB539.2020605-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-09 13:41                                                   ` Johan Vromans [this message]
     [not found]                                                     ` <m2oefyzplr.fsf-KjnUIgV0B0bak1Ioo/c9IoRWq/SkRNHw@public.gmane.org>
2005-01-10 13:51                                                       ` Zdzisław A. Kaleta
     [not found]                                                         ` <200501101451.36702.sanskryt-FWhLrETftxM@public.gmane.org>
2005-01-11 10:12                                                           ` Pedro Venda
     [not found]                                                             ` <41E3A69B.2020506-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-11 10:49                                                               ` z.a.kaleta
     [not found]                                                                 ` <200501111149.55615.sanskryt-h7QdYz1kt/Q@public.gmane.org>
2005-01-11 11:44                                                                   ` Pedro Venda
     [not found]                                                                     ` <41E3BC06.30408-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-11 12:30                                                                       ` Zdzisław A. Kaleta
2005-01-10 14:24                                                       ` Zdzisław A. Kaleta
     [not found]                                                         ` <200501101524.58077.sanskryt-FWhLrETftxM@public.gmane.org>
2005-01-10 14:57                                                           ` Johan Vromans
     [not found]                                                             ` <m28y71fi1s.fsf-KjnUIgV0B0bak1Ioo/c9IoRWq/SkRNHw@public.gmane.org>
2005-01-10 15:43                                                               ` Pedro Venda
2005-01-10 19:44                                                                 ` Johan Vromans
2005-01-10 16:36                                                               ` Zdzisław A. Kaleta
     [not found]                                                                 ` <200501101736.24293.sanskryt-FWhLrETftxM@public.gmane.org>
2005-01-10 19:34                                                                   ` Johan Vromans
     [not found]                                                                     ` <m27jmlf57y.fsf-KjnUIgV0B0bak1Ioo/c9IoRWq/SkRNHw@public.gmane.org>
2005-01-10 22:41                                                                       ` Zdzisław A. Kaleta
     [not found]                                                                         ` <200501102341.07731.sanskryt-FWhLrETftxM@public.gmane.org>
2005-01-11  9:29                                                                           ` Johan Vromans
     [not found]                                                                             ` <m2sm58mhzg.fsf-KjnUIgV0B0bak1Ioo/c9IoRWq/SkRNHw@public.gmane.org>
2005-01-11 10:10                                                                               ` Pedro Venda
2005-01-01 17:05                   ` first shoot for smartbattery (was Re: Re: i2c-acpi-ec.c) Pedro Venda
2005-01-01 12:35               ` Hendrik Jürgens
2005-01-01 19:21               ` John Belmonte
     [not found]                 ` <41D6F826.8090906-wanGne27zNesTnJN9+BGXg@public.gmane.org>
2005-01-03 13:13                   ` Bruno Ducrot
2005-01-09  3:08               ` ultrakorne
     [not found]                 ` <41E0A01C.6060607-XtQPfPCVGG7srOwW+9ziJQ@public.gmane.org>
2005-01-09 12:04                   ` Pedro Venda
     [not found]                     ` <41E11DD0.2090809-pQd4kjVL+REh2FBCd0jGRA@public.gmane.org>
2005-01-09 16:12                       ` Ultrakorne
2005-01-09 17:08                       ` ultrakorne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2oefyzplr.fsf@phoenix.squirrel.nl \
    --to=jvromans-2pnskkp3pskevqv0petr8a@public.gmane.org \
    --cc=acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox