1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-11 18:38:45 +00:00

Add APM support for FreeBSD.

Submitted by:	 Daniel Thiele <dthiele@gmx.net>


git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@241 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Roman Bogorodskiy 2005-08-30 04:19:16 +00:00
parent cf39637f72
commit 75032800b1
4 changed files with 158 additions and 0 deletions

View File

@ -25,6 +25,9 @@ dan-h <dan-h at users dot sourceforge dot net>
David McCabe
utime
Daniel Thiele <dthiele at gmx dot net>
APM support for FreeBSD
Dennis Frommknecht
NVCtrl, temperature monitoring for nvdia-based graphics cards

View File

@ -821,6 +821,11 @@ enum text_object_type {
OBJ_upspeedgraph,
OBJ_uptime,
OBJ_uptime_short,
#ifdef __FreeBSD__
OBJ_apm_adapter,
OBJ_apm_battery_time,
OBJ_apm_battery_life,
#endif /* __FreeBSD__ */
#ifdef SETI
OBJ_seti_prog,
OBJ_seti_progbar,
@ -1658,6 +1663,11 @@ int a = stippled_borders, b = 1;
}
END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
#ifdef __FreeBSD__
OBJ(apm_adapter, 0) END
OBJ(apm_battery_life, 0) END
OBJ(apm_battery_time, 0) END
#endif /* __FreeBSD__ */
#ifdef SETI
OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
@ -2680,6 +2690,23 @@ static void generate_text()
format_seconds(p, n, (int) cur->uptime);
}
#ifdef __FreeBSD__
OBJ(apm_adapter) {
snprintf(p, n, "%s", get_apm_adapter());
}
OBJ(apm_battery_life) {
char *msg;
msg = get_apm_battery_life();
snprintf(p, n, "%s", msg);
free(msg);
}
OBJ(apm_battery_time) {
char *msg;
msg = get_apm_battery_time();
snprintf(p, n, "%s", msg);
free(msg);
}
#endif /* __FreeBSD__ */
#ifdef SETI
OBJ(seti_prog) {
snprintf(p, n, "%.2f",

View File

@ -30,6 +30,10 @@
#endif
#endif /* X11 */
#if defined(__FreeBSD__)
#include <machine/apm_bios.h>
#endif /* __FreeBSD__ */
#define TOP_CPU 1
#define TOP_NAME 2
#define TOP_PID 3
@ -353,6 +357,13 @@ extern char *seti_dir;
void update_seti();
#endif
/* in freebsd.c */
#ifdef __FreeBSD__
int apm_getinfo(int fd, apm_info_t aip);
char *get_apm_adapter(void);
char *get_apm_battery_life(void);
char *get_apm_battery_time(void);
#endif
/* in mpd.c */
#ifdef MPD

View File

@ -587,3 +587,120 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
} else
return;
}
#define APMDEV "/dev/apm"
#define APM_UNKNOWN 255
int apm_getinfo(int fd, apm_info_t aip)
{
if (ioctl(fd, APMIO_GETINFO, aip) == -1)
return -1;
return 0;
}
char *get_apm_adapter()
{
int fd;
struct apm_info info;
fd = open(APMDEV, O_RDONLY);
if(fd < 0)
return "ERR";
if(apm_getinfo(fd, &info) != 0 ) {
close(fd);
return "ERR";
}
close(fd);
switch(info.ai_acline) {
case 0:
return "off-line";
break;
case 1:
if(info.ai_batt_stat == 3)
return "charging";
else
return "on-line";
break;
default:
return "unknown";
break;
}
}
char *get_apm_battery_life()
{
int fd;
u_int batt_life;
struct apm_info info;
char *out;
out = (char *)calloc(16, sizeof(char));
fd = open(APMDEV, O_RDONLY);
if(fd < 0) {
strncpy(out, "ERR", 16);
return out;
}
if(apm_getinfo(fd, &info) != 0 ) {
close(fd);
strncpy(out, "ERR", 16);
return out;
}
close(fd);
batt_life = info.ai_batt_life;
if (batt_life == APM_UNKNOWN)
strncpy(out, "unknown", 16);
else if (batt_life <= 100) {
snprintf(out, 20,"%d%%", batt_life);
return out;
}
else
strncpy(out, "ERR", 16);
return out;
}
char *get_apm_battery_time()
{
int fd;
int batt_time;
int h, m, s;
struct apm_info info;
char *out;
out = (char *)calloc(16, sizeof(char));
fd = open(APMDEV, O_RDONLY);
if(fd < 0) {
strncpy(out, "ERR", 16);
return out;
}
if(apm_getinfo(fd, &info) != 0 ) {
close(fd);
strncpy(out, "ERR", 16);
return out;
}
close(fd);
batt_time = info.ai_batt_time;
if (batt_time == -1)
strncpy(out, "unknown", 16);
else {
h = batt_time;
s = h % 60;
h /= 60;
m = h % 60;
h /= 60;
snprintf(out, 16, "%2d:%02d:%02d", h, m, s);
}
return out;
}