1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 20:11:11 +00:00

i8k: outsource code

This commit is contained in:
Phil Sutter 2009-11-16 20:58:26 +01:00
parent fe1d7da3d5
commit b6d1ff6c42
8 changed files with 213 additions and 97 deletions

View File

@ -65,7 +65,7 @@ ibm = ibm.c ibm.h smapi.c smapi.h
mpd = mpd.c mpd.h libmpdclient.c libmpdclient.h
moc = moc.c moc.h
xmms2 = xmms2.c xmms2.h
linux = linux.c linux.h top.c top.h users.c sony.c sony.h
linux = linux.c linux.h top.c top.h users.c sony.c sony.h i8k.c i8k.h
solaris = solaris.c
freebsd = freebsd.c freebsd.h
netbsd = netbsd.c netbsd.h

View File

@ -27,7 +27,6 @@ void update_total_processes(void);
void update_uname(void);
void update_threads(void);
void update_running_processes(void);
void update_i8k(void);
void update_stuff(void);
char get_freq(char *, size_t, const char *, int, unsigned int);
char get_voltage(char *, size_t, const char *, int, unsigned int); /* ptarjan */

View File

@ -80,6 +80,7 @@
#include "diskio.h"
#include "entropy.h"
#include "exec.h"
#include "i8k.h"
#include "proc.h"
#include "user.h"
#ifdef X11
@ -1002,70 +1003,34 @@ void generate_text_internal(char *p, int p_max_size,
get_disk_protect_queue(obj->data.s));
}
OBJ(i8k_version) {
snprintf(p, p_max_size, "%s", i8k.version);
print_i8k_version(obj, p, p_max_size);
}
OBJ(i8k_bios) {
snprintf(p, p_max_size, "%s", i8k.bios);
print_i8k_bios(obj, p, p_max_size);
}
OBJ(i8k_serial) {
snprintf(p, p_max_size, "%s", i8k.serial);
print_i8k_serial(obj, p, p_max_size);
}
OBJ(i8k_cpu_temp) {
int cpu_temp;
sscanf(i8k.cpu_temp, "%d", &cpu_temp);
temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
print_i8k_cpu_temp(obj, p, p_max_size);
}
OBJ(i8k_left_fan_status) {
int left_fan_status;
sscanf(i8k.left_fan_status, "%d", &left_fan_status);
if (left_fan_status == 0) {
snprintf(p, p_max_size, "off");
}
if (left_fan_status == 1) {
snprintf(p, p_max_size, "low");
}
if (left_fan_status == 2) {
snprintf(p, p_max_size, "high");
}
print_i8k_left_fan_status(obj, p, p_max_size);
}
OBJ(i8k_right_fan_status) {
int right_fan_status;
sscanf(i8k.right_fan_status, "%d", &right_fan_status);
if (right_fan_status == 0) {
snprintf(p, p_max_size, "off");
}
if (right_fan_status == 1) {
snprintf(p, p_max_size, "low");
}
if (right_fan_status == 2) {
snprintf(p, p_max_size, "high");
}
print_i8k_right_fan_status(obj, p, p_max_size);
}
OBJ(i8k_left_fan_rpm) {
snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
print_i8k_left_fan_rpm(obj, p, p_max_size);
}
OBJ(i8k_right_fan_rpm) {
snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
print_i8k_right_fan_rpm(obj, p, p_max_size);
}
OBJ(i8k_ac_status) {
int ac_status;
sscanf(i8k.ac_status, "%d", &ac_status);
if (ac_status == -1) {
snprintf(p, p_max_size, "disabled (read i8k docs)");
}
if (ac_status == 0) {
snprintf(p, p_max_size, "off");
}
if (ac_status == 1) {
snprintf(p, p_max_size, "on");
}
print_i8k_ac_status(obj, p, p_max_size);
}
OBJ(i8k_buttons_status) {
snprintf(p, p_max_size, "%s", i8k.buttons_status);
print_i8k_buttons_status(obj, p, p_max_size);
}
#if defined(IBM)
OBJ(ibm_fan) {

View File

@ -38,6 +38,7 @@
#include "diskio.h"
#include "entropy.h"
#include "exec.h"
#include "i8k.h"
#include "proc.h"
#ifdef X11
#include "fonts.h"

153
src/i8k.c Normal file
View File

@ -0,0 +1,153 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
* vim: ts=4 sw=4 noet ai cindent syntax=c
*
* Conky, a system monitor, based on torsmo
*
* Any original torsmo code is licensed under the BSD license
*
* All code written since the fork of torsmo is licensed under the GPL
*
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2007 Toni Spets
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "logging.h"
#include "temphelper.h"
#include "text_object.h"
struct {
char *version;
char *bios;
char *serial;
char *cpu_temp;
char *left_fan_status;
char *right_fan_status;
char *left_fan_rpm;
char *right_fan_rpm;
char *ac_status;
char *buttons_status;
} i8k;
/* FIXME: there should be an ioctl interface to request specific data */
#define PROC_I8K "/proc/i8k"
#define I8K_DELIM " "
static char *i8k_procbuf = NULL;
void update_i8k(void)
{
FILE *fp;
if (!i8k_procbuf) {
i8k_procbuf = (char *) malloc(128 * sizeof(char));
}
if ((fp = fopen(PROC_I8K, "r")) == NULL) {
CRIT_ERR(NULL, NULL, "/proc/i8k doesn't exist! use insmod to make sure the kernel "
"driver is loaded...");
}
memset(&i8k_procbuf[0], 0, 128);
if (fread(&i8k_procbuf[0], sizeof(char), 128, fp) == 0) {
NORM_ERR("something wrong with /proc/i8k...");
}
fclose(fp);
i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
i8k.bios = strtok(NULL, I8K_DELIM);
i8k.serial = strtok(NULL, I8K_DELIM);
i8k.cpu_temp = strtok(NULL, I8K_DELIM);
i8k.left_fan_status = strtok(NULL, I8K_DELIM);
i8k.right_fan_status = strtok(NULL, I8K_DELIM);
i8k.left_fan_rpm = strtok(NULL, I8K_DELIM);
i8k.right_fan_rpm = strtok(NULL, I8K_DELIM);
i8k.ac_status = strtok(NULL, I8K_DELIM);
i8k.buttons_status = strtok(NULL, I8K_DELIM);
}
static const char *fan_status_to_string(int status)
{
switch(status) {
case 0: return "off";
case 1: return "low";
case 2: return "high";
}
return "error";
}
void print_i8k_left_fan_status(struct text_object *obj, char *p, int p_max_size)
{
(void)obj;
snprintf(p, p_max_size, "%s",
fan_status_to_string(atoi(i8k.left_fan_status)));
}
void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
{
int cpu_temp;
(void)obj;
sscanf(i8k.cpu_temp, "%d", &cpu_temp);
temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
}
void print_i8k_right_fan_status(struct text_object *obj, char *p, int p_max_size)
{
(void)obj;
snprintf(p, p_max_size, "%s",
fan_status_to_string(atoi(i8k.right_fan_status)));
}
void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size)
{
int ac_status;
(void)obj;
sscanf(i8k.ac_status, "%d", &ac_status);
if (ac_status == -1) {
snprintf(p, p_max_size, "disabled (read i8k docs)");
}
if (ac_status == 0) {
snprintf(p, p_max_size, "off");
}
if (ac_status == 1) {
snprintf(p, p_max_size, "on");
}
}
#define I8K_PRINT_GENERATOR(name) \
void print_i8k_##name(struct text_object *obj, char *p, int p_max_size) \
{ \
(void)obj; \
snprintf(p, p_max_size, "%s", i8k.name); \
}
I8K_PRINT_GENERATOR(version)
I8K_PRINT_GENERATOR(bios)
I8K_PRINT_GENERATOR(serial)
I8K_PRINT_GENERATOR(left_fan_rpm)
I8K_PRINT_GENERATOR(right_fan_rpm)
I8K_PRINT_GENERATOR(buttons_status)
#undef I8K_PRINT_GENERATOR

47
src/i8k.h Normal file
View File

@ -0,0 +1,47 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
* vim: ts=4 sw=4 noet ai cindent syntax=c
*
* Conky, a system monitor, based on torsmo
*
* Any original torsmo code is licensed under the BSD license
*
* All code written since the fork of torsmo is licensed under the GPL
*
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2007 Toni Spets
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _I8K_H
#define _I8K_H
void update_i8k(void);
void print_i8k_left_fan_status(struct text_object *, char *, int);
void print_i8k_cpu_temp(struct text_object *, char *, int);
void print_i8k_right_fan_status(struct text_object *, char *, int);
void print_i8k_ac_status(struct text_object *, char *, int);
void print_i8k_version(struct text_object *, char *, int);
void print_i8k_bios(struct text_object *, char *, int);
void print_i8k_serial(struct text_object *, char *, int);
void print_i8k_left_fan_rpm(struct text_object *, char *, int);
void print_i8k_right_fan_rpm(struct text_object *, char *, int);
void print_i8k_buttons_status(struct text_object *, char *, int);
#endif /* _I8K_H */

View File

@ -819,40 +819,6 @@ void update_load_average(void)
}
}
#define PROC_I8K "/proc/i8k"
#define I8K_DELIM " "
static char *i8k_procbuf = NULL;
void update_i8k(void)
{
FILE *fp;
if (!i8k_procbuf) {
i8k_procbuf = (char *) malloc(128 * sizeof(char));
}
if ((fp = fopen(PROC_I8K, "r")) == NULL) {
CRIT_ERR(NULL, NULL, "/proc/i8k doesn't exist! use insmod to make sure the kernel "
"driver is loaded...");
}
memset(&i8k_procbuf[0], 0, 128);
if (fread(&i8k_procbuf[0], sizeof(char), 128, fp) == 0) {
NORM_ERR("something wrong with /proc/i8k...");
}
fclose(fp);
i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
i8k.bios = strtok(NULL, I8K_DELIM);
i8k.serial = strtok(NULL, I8K_DELIM);
i8k.cpu_temp = strtok(NULL, I8K_DELIM);
i8k.left_fan_status = strtok(NULL, I8K_DELIM);
i8k.right_fan_status = strtok(NULL, I8K_DELIM);
i8k.left_fan_rpm = strtok(NULL, I8K_DELIM);
i8k.right_fan_rpm = strtok(NULL, I8K_DELIM);
i8k.ac_status = strtok(NULL, I8K_DELIM);
i8k.buttons_status = strtok(NULL, I8K_DELIM);
}
/***********************************************************/
/***********************************************************/
/***********************************************************/

View File

@ -7,21 +7,6 @@
const char *get_disk_protect_queue(const char *);
struct i8k_struct {
char *version;
char *bios;
char *serial;
char *cpu_temp;
char *left_fan_status;
char *right_fan_status;
char *left_fan_rpm;
char *right_fan_rpm;
char *ac_status;
char *buttons_status;
};
struct i8k_struct i8k;
char *get_ioscheduler(char *);
int get_laptop_mode(void);