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 i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
81 i8k.bios = strtok(NULL, I8K_DELIM);
82 i8k.serial = strtok(NULL, I8K_DELIM);
83 i8k.cpu_temp = strtok(NULL, I8K_DELIM);
84 i8k.left_fan_status = strtok(NULL, I8K_DELIM);
85 i8k.right_fan_status = strtok(NULL, I8K_DELIM);
86 i8k.left_fan_rpm = strtok(NULL, I8K_DELIM);
87 i8k.right_fan_rpm = strtok(NULL, I8K_DELIM);
88 i8k.ac_status = strtok(NULL, I8K_DELIM);
89 i8k.buttons_status = strtok(NULL, I8K_DELIM);
93 static const char *fan_status_to_string(int status)
98 case 2: return "high";
103 void print_i8k_left_fan_status(struct text_object *obj, char *p, int p_max_size)
106 snprintf(p, p_max_size, "%s",
107 fan_status_to_string(atoi(i8k.left_fan_status)));
110 void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
116 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
117 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
120 void print_i8k_right_fan_status(struct text_object *obj, char *p, int p_max_size)
123 snprintf(p, p_max_size, "%s",
124 fan_status_to_string(atoi(i8k.right_fan_status)));
127 void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size)
133 sscanf(i8k.ac_status, "%d", &ac_status);
134 if (ac_status == -1) {
135 snprintf(p, p_max_size, "disabled (read i8k docs)");
137 if (ac_status == 0) {
138 snprintf(p, p_max_size, "off");
140 if (ac_status == 1) {
141 snprintf(p, p_max_size, "on");
145 #define I8K_PRINT_GENERATOR(name) \
146 void print_i8k_##name(struct text_object *obj, char *p, int p_max_size) \
149 snprintf(p, p_max_size, "%s", i8k.name); \
152 I8K_PRINT_GENERATOR(version)
153 I8K_PRINT_GENERATOR(bios)
154 I8K_PRINT_GENERATOR(serial)
155 I8K_PRINT_GENERATOR(left_fan_rpm)
156 I8K_PRINT_GENERATOR(right_fan_rpm)
157 I8K_PRINT_GENERATOR(buttons_status)
159 #undef I8K_PRINT_GENERATOR