File: libacpi.h

package info (click to toggle)
wmacpi 2.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 204 kB
  • ctags: 182
  • sloc: ansic: 1,403; makefile: 87
file content (144 lines) | stat: -rw-r--r-- 3,450 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef _LIBACPI_H_
#define _LIBACPI_H_


#define LIBACPI_VER "0.92"

/* Here because we need it for definitions in this file . . . */
#define MAX_NAME 128
#define MAXBATT 8
#define SAMPLES 50
#define CAP_SAMPLES (SAMPLES*10)

typedef enum {
    REMAIN,
    TIMER
} DspMode;

typedef enum {
    AC,
    BATT,
    PS_ERR,
} power_state_t;
    
typedef enum {
    HIGH,
    MED,
    LOW,
    CRIT,
    HARD_CRIT,
    BS_ERR,
} batt_state_t;

typedef enum {
    CHARGE,
    DISCHARGE,
    CH_ERR,
} charge_state_t;

typedef enum {
    OK,
    CRITICAL,
    CS_ERR,
} cap_state_t;

typedef struct {
    /* general info */
    char name[MAX_NAME];
    /* these two are conveniences */
    char info_file[MAX_NAME];
    char state_file[MAX_NAME];
    int present; 
    int design_cap;		/* assuming mAh */
    int last_full_cap;
    int design_voltage;		/* in mV */
    /* state info */
    cap_state_t capacity_state;
    charge_state_t charge_state;
    int present_rate;		/* in mAh */
    int remaining_cap;		/* in mAh */
    int present_voltage;	/* in mV */
    /* calculated states */
    batt_state_t state;
    int percentage;		/* stored here because this is a per battery thing */
    int charge_time;		/* time left to charge this battery */
    /* and a flag to indicate that this is valid . . . */
    int valid;
    /* number of times we've gotten bad info on this battery's present rate */
    int bad_count;		
} battery_t;
    
typedef struct {
    char *name;
    char state_file[MAX_NAME];
    power_state_t power;
} adapter_t;

/* how to calculate the time remaining */
enum rtime_mode {
    RT_RATE,			/* using the current rate, as per the ACPI spec */
    RT_CAP,			/* using the remaining capacity over time */
};

typedef struct {
    int rtime;			/* remaining time */
    int timer;			/* how long been on battery? */
    int crit_level;		/* anything below this is critical low */
    int battery_count;		/* number of batteries found */
    enum rtime_mode rt_mode;	/* remaining time mode */
    int rt_forced;		/* was our rt_mode forced? if so, we do what we were told */
    battery_t *binfo;		/* pointer to the battery being monitored */
    adapter_t adapter;
} global_t;

/*
 * Moving percentage to the battery is right, but I think we need a global
 * remaining capacity somewhere, too . . . 
 */

/*
 * To provide a convenient debugging function . . . 
 *
 * It's a macro because I'm too lazy to deal with varargs.
 */

#define pdebug(fmt, arg...)				\
    do {						\
	if (verbosity > 2)				\
	    fprintf(stderr, fmt, ##arg);		\
    } while (0)

#define pinfo(fmt, arg...)				\
    do {						\
	if (verbosity > 1)				\
	    fprintf(stderr, fmt, ##arg);		\
    } while (0)

#define perr(fmt, arg...)				\
    do {						\
	if (verbosity > 0)				\
	    fprintf(stderr, fmt, ##arg);		\
    } while (0)

#define pfatal(fmt, arg...)				\
    fprintf(stderr, fmt, ##arg)				\
	

/* Since these /are/ needed here . . . */
battery_t batteries[MAXBATT];
int verbosity;

/* check if apm/acpi is enabled, etc */
int power_init(global_t *globals);
/* reinitialise everything */
int power_reinit(global_t *globals);
int reinit_ac_adapters(global_t *globals);
int reinit_batteries(global_t *globals);

/* fill global_t with data */
void acquire_batt_info(global_t *globals, int batt);
void acquire_all_batt_info(global_t *globals);
void acquire_global_info(global_t *globals);
void acquire_all_info(global_t *globals);

#endif /* _WMACPI_H_ */