1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2 * vim: ts=4 sw=4 noet ai cindent syntax=c
4 * Conky, a system monitor, based on torsmo
6 * Any original torsmo code is licensed under the BSD license
8 * All code written since the fork of torsmo is licensed under the GPL
10 * Please see COPYING for details
12 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
13 * Copyright (c) 2007 Toni Spets
14 * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
16 * All rights reserved.
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 #include "text_object.h"
36 #include "temphelper.h"
44 char *left_fan_status;
45 char *right_fan_status;
52 /* FIXME: there should be an ioctl interface to request specific data */
53 #define PROC_I8K "/proc/i8k"
55 static char *i8k_procbuf = NULL;
61 i8k_procbuf = (char *) malloc(128 * sizeof(char));
63 if ((fp = fopen(PROC_I8K, "r")) == NULL) {
66 NORM_ERR("/proc/i8k doesn't exist! use insmod to make sure the kernel "
67 "driver is loaded...");
68 clean_up_without_threads(NULL, NULL);
69 free(current_mail_spool);
73 memset(&i8k_procbuf[0], 0, 128);
74 if (fread(&i8k_procbuf[0], sizeof(char), 128, fp) == 0) {
75 NORM_ERR("something wrong with /proc/i8k...");
80 DBGP("read `%s' from /proc/i8k\n", i8k_procbuf);
82 i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
83 i8k.bios = strtok(NULL, I8K_DELIM);
84 i8k.serial = strtok(NULL, I8K_DELIM);
85 i8k.cpu_temp = strtok(NULL, I8K_DELIM);
86 i8k.left_fan_status = strtok(NULL, I8K_DELIM);
87 i8k.right_fan_status = strtok(NULL, I8K_DELIM);
88 i8k.left_fan_rpm = strtok(NULL, I8K_DELIM);
89 i8k.right_fan_rpm = strtok(NULL, I8K_DELIM);
90 i8k.ac_status = strtok(NULL, I8K_DELIM);
91 i8k.buttons_status = strtok(NULL, I8K_DELIM);
95 static void print_i8k_fan_status(char *p, int p_max_size, const char *status)
97 static const char *status_arr[] = { "off", "low", "high", "error" };
99 int i = status ? atoi(status) : 3;
103 snprintf(p, p_max_size, "%s", status_arr[i]);
106 void print_i8k_left_fan_status(struct text_object *obj, char *p, int p_max_size)
109 print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
112 void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
118 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
119 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
122 void print_i8k_right_fan_status(struct text_object *obj, char *p, int p_max_size)
125 print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
128 void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size)
134 sscanf(i8k.ac_status, "%d", &ac_status);
135 if (ac_status == -1) {
136 snprintf(p, p_max_size, "disabled (read i8k docs)");
138 if (ac_status == 0) {
139 snprintf(p, p_max_size, "off");
141 if (ac_status == 1) {
142 snprintf(p, p_max_size, "on");
146 #define I8K_PRINT_GENERATOR(name) \
147 void print_i8k_##name(struct text_object *obj, char *p, int p_max_size) \
150 snprintf(p, p_max_size, "%s", i8k.name); \
153 I8K_PRINT_GENERATOR(version)
154 I8K_PRINT_GENERATOR(bios)
155 I8K_PRINT_GENERATOR(serial)
156 I8K_PRINT_GENERATOR(left_fan_rpm)
157 I8K_PRINT_GENERATOR(right_fan_rpm)
158 I8K_PRINT_GENERATOR(buttons_status)
160 #undef I8K_PRINT_GENERATOR