From 030f55fa2e77436afdb7daf675b7695f3bccda4e Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Sat, 14 May 2022 22:08:55 -0700 Subject: [PATCH] [battery] Tie into the periodic function to update APM info Tie into the periodic function so we can get the APM info. For now it's not checking that some time has elapsed, the hope is that it'll just be driven by md_main_loop() / 5 second select timeout. --- battery_module.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/battery_module.c b/battery_module.c index 272b4a6..1b4959e 100644 --- a/battery_module.c +++ b/battery_module.c @@ -11,6 +11,9 @@ #include "libami.h" +/* XXX should be an md method */ +extern void (*md_periodic_func)(void); + /* * Test battery module for FreeBSD, using APM. */ @@ -45,21 +48,29 @@ get_apm_info(void) return true; } +static void +periodic_func(void) +{ + fprintf(stderr, "Ha!\n"); + get_apm_info(); +} + int main(int argc, char *argv[]) { - char *arg=md_init(argc, argv); + char *arg; + + arg = md_init(argc, argv); progname=argv[0]; + md_periodic_func = periodic_func; + apm_fd = open(APM_DEV, O_RDONLY); if (apm_fd < 0) { err(127, "open"); } - /* - * XXX TODO: how do I actually get this to run once - * a second in the main loop? - */ + /* initial battery info */ get_apm_info(); md_main_loop();