1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2007 Toni Spets
11 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
13 * All rights reserved.
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 * vim: ts=4 sw=4 noet ai cindent syntax=c
40 /* Here come the IBM ACPI-specific things. For reference, see
41 * http://ibm-acpi.sourceforge.net/README
42 * If IBM ACPI is installed, /proc/acpi/ibm contains the following files:
58 * The content of these files is described in detail in the aforementioned
59 * README - some of them also in the following functions accessing them.
60 * Peter Tarjan (ptarjan@citromail.hu) */
62 #define IBM_ACPI_DIR "/proc/acpi/ibm"
64 /* get fan speed on IBM/Lenovo laptops running the ibm acpi.
65 * /proc/acpi/ibm/fan looks like this (3 lines):
68 commands: enable, disable
69 * Peter Tarjan (ptarjan@citromail.hu) */
71 void get_ibm_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
74 unsigned int speed = 0;
77 if (!p_client_buffer || client_buffer_size <= 0) {
81 snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR);
88 if (fgets(line, 255, fp) == NULL) {
91 if (sscanf(line, "speed: %u", &speed)) {
96 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
97 "ibm* from your "PACKAGE_NAME" config file.", fan, strerror(errno));
101 snprintf(p_client_buffer, client_buffer_size, "%d", speed);
104 /* get the measured temperatures from the temperature sensors
105 * on IBM/Lenovo laptops running the ibm acpi.
106 * There are 8 values in /proc/acpi/ibm/thermal, and according to
107 * http://ibm-acpi.sourceforge.net/README
108 * these mean the following (at least on an IBM R51...)
109 * 0: CPU (also on the T series laptops)
110 * 1: Mini PCI Module (?)
112 * 3: GPU (also on the T series laptops)
117 * I'm not too sure about those with the question mark, but the values I'm
118 * reading from *my* thermal file (on a T42p) look realistic for the
119 * hdd and the battery.
120 * #5 and #7 are always -128.
121 * /proc/acpi/ibm/thermal looks like this (1 line):
122 temperatures: 41 43 31 46 33 -128 29 -128
123 * Peter Tarjan (ptarjan@citromail.hu) */
125 static double last_ibm_acpi_temp_time;
126 void get_ibm_acpi_temps(void)
132 /* don't update too often */
133 if (current_update_time - last_ibm_acpi_temp_time < 10.00) {
136 last_ibm_acpi_temp_time = current_update_time;
138 /* if (!p_client_buffer || client_buffer_size <= 0) {
142 snprintf(thermal, 127, "%s/thermal", IBM_ACPI_DIR);
143 fp = fopen(thermal, "r");
149 if (fgets(line, 255, fp) == NULL) {
152 if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
153 &ibm_acpi.temps[0], &ibm_acpi.temps[1], &ibm_acpi.temps[2],
154 &ibm_acpi.temps[3], &ibm_acpi.temps[4], &ibm_acpi.temps[5],
155 &ibm_acpi.temps[6], &ibm_acpi.temps[7])) {
160 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
161 "ibm* from your "PACKAGE_NAME" config file.", thermal, strerror(errno));
167 /* get volume (0-14) on IBM/Lenovo laptops running the ibm acpi.
168 * "Volume" here is none of the mixer volumes, but a "master of masters"
169 * volume adjusted by the IBM volume keys.
170 * /proc/acpi/ibm/fan looks like this (4 lines):
173 commands: up, down, mute
174 commands: level <level> (<level> is 0-15)
175 * Peter Tarjan (ptarjan@citromail.hu) */
177 void get_ibm_acpi_volume(char *p_client_buffer, size_t client_buffer_size)
181 unsigned int vol = -1;
184 if (!p_client_buffer || client_buffer_size <= 0) {
188 snprintf(volume, 127, "%s/volume", IBM_ACPI_DIR);
190 fp = fopen(volume, "r");
194 unsigned int read_vol = -1;
196 if (fgets(line, 255, fp) == NULL) {
199 if (sscanf(line, "level: %u", &read_vol)) {
203 if (sscanf(line, "mute: %s", mute)) {
208 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
209 "ibm* from your "PACKAGE_NAME" config file.", volume, strerror(errno));
214 if (strcmp(mute, "on") == 0) {
215 snprintf(p_client_buffer, client_buffer_size, "%s", "mute");
218 snprintf(p_client_buffer, client_buffer_size, "%d", vol);
223 /* static FILE *fp = NULL; */
225 /* get LCD brightness on IBM/Lenovo laptops running the ibm acpi.
226 * /proc/acpi/ibm/brightness looks like this (3 lines):
229 commands: level <level> (<level> is 0-7)
230 * Peter Tarjan (ptarjan@citromail.hu) */
232 void get_ibm_acpi_brightness(char *p_client_buffer, size_t client_buffer_size)
235 unsigned int brightness = 0;
238 if (!p_client_buffer || client_buffer_size <= 0) {
242 snprintf(filename, 127, "%s/brightness", IBM_ACPI_DIR);
244 fp = fopen(filename, "r");
249 if (fgets(line, 255, fp) == NULL) {
252 if (sscanf(line, "level: %u", &brightness)) {
257 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
258 "ibm* from your "PACKAGE_NAME" config file.", filename, strerror(errno));
263 snprintf(p_client_buffer, client_buffer_size, "%d", brightness);