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-2009 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/>.
41 static int ibm_acpi_temps[8];
43 /* Here come the IBM ACPI-specific things. For reference, see
44 * http://ibm-acpi.sourceforge.net/README
45 * If IBM ACPI is installed, /proc/acpi/ibm contains the following files:
61 * The content of these files is described in detail in the aforementioned
62 * README - some of them also in the following functions accessing them.
63 * Peter Tarjan (ptarjan@citromail.hu) */
65 #define IBM_ACPI_DIR "/proc/acpi/ibm"
67 /* get fan speed on IBM/Lenovo laptops running the ibm acpi.
68 * /proc/acpi/ibm/fan looks like this (3 lines):
71 commands: enable, disable
72 * Peter Tarjan (ptarjan@citromail.hu) */
74 void get_ibm_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
77 unsigned int speed = 0;
80 if (!p_client_buffer || client_buffer_size <= 0) {
84 snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR);
91 if (fgets(line, 255, fp) == NULL) {
94 if (sscanf(line, "speed: %u", &speed)) {
99 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
100 "ibm* from your "PACKAGE_NAME" config file.", fan, strerror(errno));
104 snprintf(p_client_buffer, client_buffer_size, "%d", speed);
107 /* get the measured temperatures from the temperature sensors
108 * on IBM/Lenovo laptops running the ibm acpi.
109 * There are 8 values in /proc/acpi/ibm/thermal, and according to
110 * http://ibm-acpi.sourceforge.net/README
111 * these mean the following (at least on an IBM R51...)
112 * 0: CPU (also on the T series laptops)
113 * 1: Mini PCI Module (?)
115 * 3: GPU (also on the T series laptops)
120 * I'm not too sure about those with the question mark, but the values I'm
121 * reading from *my* thermal file (on a T42p) look realistic for the
122 * hdd and the battery.
123 * #5 and #7 are always -128.
124 * /proc/acpi/ibm/thermal looks like this (1 line):
125 temperatures: 41 43 31 46 33 -128 29 -128
126 * Peter Tarjan (ptarjan@citromail.hu) */
128 void get_ibm_acpi_temps(void)
134 snprintf(thermal, 127, "%s/thermal", IBM_ACPI_DIR);
135 fp = fopen(thermal, "r");
141 if (fgets(line, 255, fp) == NULL) {
144 if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
145 &ibm_acpi_temps[0], &ibm_acpi_temps[1], &ibm_acpi_temps[2],
146 &ibm_acpi_temps[3], &ibm_acpi_temps[4], &ibm_acpi_temps[5],
147 &ibm_acpi_temps[6], &ibm_acpi_temps[7])) {
152 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
153 "ibm* from your "PACKAGE_NAME" config file.", thermal, strerror(errno));
159 /* get volume (0-14) on IBM/Lenovo laptops running the ibm acpi.
160 * "Volume" here is none of the mixer volumes, but a "master of masters"
161 * volume adjusted by the IBM volume keys.
162 * /proc/acpi/ibm/fan looks like this (4 lines):
165 commands: up, down, mute
166 commands: level <level> (<level> is 0-15)
167 * Peter Tarjan (ptarjan@citromail.hu) */
169 void get_ibm_acpi_volume(char *p_client_buffer, size_t client_buffer_size)
173 unsigned int vol = -1;
176 if (!p_client_buffer || client_buffer_size <= 0) {
180 snprintf(volume, 127, "%s/volume", IBM_ACPI_DIR);
182 fp = fopen(volume, "r");
186 unsigned int read_vol = -1;
188 if (fgets(line, 255, fp) == NULL) {
191 if (sscanf(line, "level: %u", &read_vol)) {
195 if (sscanf(line, "mute: %s", mute)) {
200 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
201 "ibm* from your "PACKAGE_NAME" config file.", volume, strerror(errno));
206 if (strcmp(mute, "on") == 0) {
207 snprintf(p_client_buffer, client_buffer_size, "%s", "mute");
210 snprintf(p_client_buffer, client_buffer_size, "%d", vol);
215 /* static FILE *fp = NULL; */
217 /* get LCD brightness on IBM/Lenovo laptops running the ibm acpi.
218 * /proc/acpi/ibm/brightness looks like this (3 lines):
221 commands: level <level> (<level> is 0-7)
222 * Peter Tarjan (ptarjan@citromail.hu) */
224 void get_ibm_acpi_brightness(char *p_client_buffer, size_t client_buffer_size)
227 unsigned int brightness = 0;
230 if (!p_client_buffer || client_buffer_size <= 0) {
234 snprintf(filename, 127, "%s/brightness", IBM_ACPI_DIR);
236 fp = fopen(filename, "r");
241 if (fgets(line, 255, fp) == NULL) {
244 if (sscanf(line, "level: %u", &brightness)) {
249 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
250 "ibm* from your "PACKAGE_NAME" config file.", filename, strerror(errno));
255 snprintf(p_client_buffer, client_buffer_size, "%d", brightness);
258 void parse_ibm_temps_arg(struct text_object *obj, const char *arg)
260 if (!isdigit(arg[0]) || strlen(arg) > 1 || atoi(&arg[0]) >= 8) {
262 NORM_ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
263 "Using 0 (CPU temp sensor).");
265 obj->data.l = atoi(arg);
268 void print_ibm_temps(struct text_object *obj, char *p, int p_max_size)
270 temp_print(p, p_max_size, ibm_acpi_temps[obj->data.l], TEMP_CELSIUS);