2014-08-18 22:56:10 +00:00
|
|
|
#ifndef _LIBACPI_H_
|
|
|
|
#define _LIBACPI_H_
|
|
|
|
|
|
|
|
|
2014-08-18 22:56:28 +00:00
|
|
|
#define LIBACPI_VER "0.95"
|
2014-08-18 22:56:10 +00:00
|
|
|
|
|
|
|
/* Here because we need it for definitions in this file . . . */
|
|
|
|
#define MAX_NAME 128
|
|
|
|
#define MAXBATT 8
|
|
|
|
#define SAMPLES 50
|
2014-08-18 22:56:23 +00:00
|
|
|
#define CAP_SAMPLES (SAMPLES*10)
|
2014-08-18 22:56:10 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
REMAIN,
|
|
|
|
TIMER
|
|
|
|
} DspMode;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
AC,
|
|
|
|
BATT,
|
|
|
|
PS_ERR,
|
|
|
|
} power_state_t;
|
2014-10-05 15:29:59 +00:00
|
|
|
|
2014-08-18 22:56:10 +00:00
|
|
|
typedef enum {
|
|
|
|
HIGH,
|
|
|
|
MED,
|
|
|
|
LOW,
|
|
|
|
CRIT,
|
2014-08-18 22:56:11 +00:00
|
|
|
BS_ERR,
|
2014-08-18 22:56:10 +00:00
|
|
|
} batt_state_t;
|
|
|
|
|
2014-08-18 22:56:11 +00:00
|
|
|
typedef enum {
|
|
|
|
CHARGE,
|
|
|
|
DISCHARGE,
|
2014-08-18 22:56:28 +00:00
|
|
|
FULL,
|
|
|
|
NO_CHARGE,
|
2014-08-18 22:56:11 +00:00
|
|
|
CH_ERR,
|
|
|
|
} charge_state_t;
|
|
|
|
|
2014-08-18 22:56:10 +00:00
|
|
|
typedef enum {
|
2014-08-18 22:56:28 +00:00
|
|
|
SYSFS_CAPA_ENERGY,
|
|
|
|
SYSFS_CAPA_CHARGE,
|
|
|
|
SYSFS_CAPA_PERCENT,
|
|
|
|
SYSFS_CAPA_ERR,
|
|
|
|
} sysfs_capa_t;
|
2014-08-18 22:56:10 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* general info */
|
|
|
|
char name[MAX_NAME];
|
|
|
|
/* these two are conveniences */
|
|
|
|
char info_file[MAX_NAME];
|
|
|
|
char state_file[MAX_NAME];
|
2014-08-18 22:56:28 +00:00
|
|
|
/* sysfs capacity mode */
|
|
|
|
sysfs_capa_t sysfs_capa_mode;
|
2014-10-05 15:29:59 +00:00
|
|
|
int present;
|
2014-08-18 22:56:10 +00:00
|
|
|
int design_cap; /* assuming mAh */
|
|
|
|
int last_full_cap;
|
|
|
|
int design_voltage; /* in mV */
|
|
|
|
/* state info */
|
2014-08-18 22:56:11 +00:00
|
|
|
charge_state_t charge_state;
|
2014-08-18 22:56:10 +00:00
|
|
|
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;
|
2014-08-18 22:56:22 +00:00
|
|
|
/* number of times we've gotten bad info on this battery's present rate */
|
2014-10-05 15:29:59 +00:00
|
|
|
int bad_count;
|
2014-08-18 22:56:11 +00:00
|
|
|
} battery_t;
|
2014-10-05 15:29:59 +00:00
|
|
|
|
2014-08-18 22:56:10 +00:00
|
|
|
typedef struct {
|
2014-08-18 22:56:11 +00:00
|
|
|
char *name;
|
|
|
|
char state_file[MAX_NAME];
|
|
|
|
power_state_t power;
|
|
|
|
} adapter_t;
|
|
|
|
|
2014-08-18 22:56:21 +00:00
|
|
|
/* 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 */
|
|
|
|
};
|
|
|
|
|
2014-08-18 22:56:11 +00:00
|
|
|
typedef struct {
|
2014-08-18 22:56:10 +00:00
|
|
|
int rtime; /* remaining time */
|
|
|
|
int timer; /* how long been on battery? */
|
|
|
|
int crit_level; /* anything below this is critical low */
|
2014-08-18 22:56:19 +00:00
|
|
|
int battery_count; /* number of batteries found */
|
2014-08-18 22:56:22 +00:00
|
|
|
enum rtime_mode rt_mode; /* remaining time mode */
|
|
|
|
int rt_forced; /* was our rt_mode forced? if so, we do what we were told */
|
2014-08-18 22:56:11 +00:00
|
|
|
battery_t *binfo; /* pointer to the battery being monitored */
|
2014-08-18 22:56:19 +00:00
|
|
|
adapter_t adapter;
|
2014-08-18 22:56:13 +00:00
|
|
|
} global_t;
|
2014-08-18 22:56:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Moving percentage to the battery is right, but I think we need a global
|
2014-10-05 15:29:59 +00:00
|
|
|
* remaining capacity somewhere, too . . .
|
2014-08-18 22:56:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-10-05 15:29:59 +00:00
|
|
|
* To provide a convenient debugging function . . .
|
2014-08-18 22:56:14 +00:00
|
|
|
*
|
|
|
|
* It's a macro because I'm too lazy to deal with varargs.
|
2014-08-18 22:56:10 +00:00
|
|
|
*/
|
|
|
|
|
2014-08-18 22:56:14 +00:00
|
|
|
#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); \
|
2014-08-18 22:56:10 +00:00
|
|
|
} while (0)
|
|
|
|
|
2014-08-18 22:56:14 +00:00
|
|
|
#define perr(fmt, arg...) \
|
|
|
|
do { \
|
|
|
|
if (verbosity > 0) \
|
|
|
|
fprintf(stderr, fmt, ##arg); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define pfatal(fmt, arg...) \
|
|
|
|
fprintf(stderr, fmt, ##arg) \
|
2014-10-05 15:29:59 +00:00
|
|
|
|
2014-08-18 22:56:14 +00:00
|
|
|
|
|
|
|
/* Since these /are/ needed here . . . */
|
2014-08-18 22:56:11 +00:00
|
|
|
battery_t batteries[MAXBATT];
|
2014-08-18 22:56:15 +00:00
|
|
|
int verbosity;
|
|
|
|
|
2014-08-18 22:56:10 +00:00
|
|
|
/* check if apm/acpi is enabled, etc */
|
2014-08-18 22:56:21 +00:00
|
|
|
int power_init(global_t *globals);
|
2014-08-18 22:56:19 +00:00
|
|
|
/* reinitialise everything */
|
2014-08-18 22:56:21 +00:00
|
|
|
int power_reinit(global_t *globals);
|
|
|
|
int reinit_ac_adapters(global_t *globals);
|
|
|
|
int reinit_batteries(global_t *globals);
|
2014-08-18 22:56:19 +00:00
|
|
|
|
2014-08-18 22:56:13 +00:00
|
|
|
/* fill global_t with data */
|
2014-08-18 22:56:21 +00:00
|
|
|
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);
|
2014-08-18 22:56:10 +00:00
|
|
|
|
|
|
|
#endif /* _WMACPI_H_ */
|