2
KSysGuard, the KDE System Guard
4
Copyright (c) 1999 - 2001 Chris Schlaeger <cs@kde.org>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of version 2 of the GNU General Public
8
License as published by the Free Software Foundation.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include <sys/types.h>
28
#include "ksysguardd.h"
33
static int BatFill, BatTime;
35
#define APMBUFSIZE 128
36
static char ApmBuf[ APMBUFSIZE ];
39
static void processApm( void )
41
sscanf( ApmBuf, "%*f %*f %*x %*x %*x %*x %d%% %d min",
47
================================ public part =================================
50
void initApm( struct SensorModul* sm )
52
if ( updateApm() < 0 ) {
58
registerMonitor( "apm/batterycharge", "integer", printApmBatFill, printApmBatFillInfo, sm );
59
registerMonitor( "apm/remainingtime", "integer", printApmBatTime, printApmBatTimeInfo, sm );
75
if ( ( fd = open( "/proc/apm", O_RDONLY ) ) < 0 ) {
77
print_error( "Cannot open file \'/proc/apm\'!\n"
78
"The kernel needs to be compiled with support\n"
79
"for /proc file system enabled!\n" );
83
n = read( fd, ApmBuf, APMBUFSIZE - 1 );
84
if ( n == APMBUFSIZE - 1 ) {
85
log_error( "Internal buffer too small to read \'/proc/apm\'" );
97
void printApmBatFill( const char* cmd )
104
output( "%d\n", BatFill );
107
void printApmBatFillInfo( const char* cmd )
110
output( "Battery charge\t0\t100\t%%\n" );
113
void printApmBatTime( const char* cmd )
120
output( "%d\n", BatTime );
123
void printApmBatTimeInfo( const char* cmd )
126
output( "Remaining battery time\t0\t0\tmin\n" );