2022-04-25 21:28:49 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <err.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <machine/apm_bios.h>
|
|
|
|
|
|
|
|
|
|
#define APM_DEV "/dev/apm"
|
|
|
|
|
|
|
|
|
|
#include "libami.h"
|
|
|
|
|
|
2022-05-14 22:08:55 -07:00
|
|
|
/* XXX should be an md method */
|
|
|
|
|
extern void (*md_periodic_func)(void);
|
|
|
|
|
|
2022-04-25 21:28:49 -07:00
|
|
|
/*
|
|
|
|
|
* Test battery module for FreeBSD, using APM.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void docmd(XEvent *e, void *callback)
|
|
|
|
|
{
|
|
|
|
|
((void (*)(Window))callback)(e->xany.window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *progname;
|
|
|
|
|
static int apm_fd = -1;
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
get_apm_info(void)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
struct apm_info info;
|
|
|
|
|
|
|
|
|
|
ret = ioctl(apm_fd, APMIO_GETINFO, &info);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
warn("ioctl (APMIO_GETINFO)");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-15 10:49:17 -07:00
|
|
|
#if 0
|
2022-04-25 21:28:49 -07:00
|
|
|
printf("Battery life: %d\n", info.ai_batt_life);
|
|
|
|
|
printf("Battery time: %d\n", info.ai_batt_time);
|
|
|
|
|
printf("Battery AC: %d\n", info.ai_acline);
|
2022-05-15 10:49:17 -07:00
|
|
|
#endif
|
2022-04-25 21:28:49 -07:00
|
|
|
|
|
|
|
|
md_update_battery(info.ai_batt_life, info.ai_batt_time,
|
|
|
|
|
info.ai_acline);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 22:08:55 -07:00
|
|
|
static void
|
|
|
|
|
periodic_func(void)
|
|
|
|
|
{
|
|
|
|
|
get_apm_info();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-15 10:49:17 -07:00
|
|
|
int
|
|
|
|
|
main(int argc, char *argv[])
|
2022-04-25 21:28:49 -07:00
|
|
|
{
|
2022-05-14 22:08:55 -07:00
|
|
|
char *arg;
|
|
|
|
|
|
|
|
|
|
arg = md_init(argc, argv);
|
2022-05-15 10:49:17 -07:00
|
|
|
(void) arg;
|
2022-04-25 21:28:49 -07:00
|
|
|
|
|
|
|
|
progname=argv[0];
|
|
|
|
|
|
2022-05-14 22:08:55 -07:00
|
|
|
md_periodic_func = periodic_func;
|
|
|
|
|
|
2022-04-25 21:28:49 -07:00
|
|
|
apm_fd = open(APM_DEV, O_RDONLY);
|
|
|
|
|
if (apm_fd < 0) {
|
|
|
|
|
err(127, "open");
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 22:08:55 -07:00
|
|
|
/* initial battery info */
|
2022-04-25 21:28:49 -07:00
|
|
|
get_apm_info();
|
|
|
|
|
|
2022-05-15 10:49:17 -07:00
|
|
|
/* Run main loop */
|
2022-04-25 21:28:49 -07:00
|
|
|
md_main_loop();
|
|
|
|
|
|
|
|
|
|
close(apm_fd);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|