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/>.
38 /* Here come the IBM ACPI-specific things. For reference, see
39 * http://ibm-acpi.sourceforge.net/README
40 * If IBM ACPI is installed, /proc/acpi/ibm contains the following files:
56 * The content of these files is described in detail in the aforementioned
57 * README - some of them also in the following functions accessing them.
58 * Peter Tarjan (ptarjan@citromail.hu) */
60 #define IBM_ACPI_DIR "/proc/acpi/ibm"
62 /* get fan speed on IBM/Lenovo laptops running the ibm acpi.
63 * /proc/acpi/ibm/fan looks like this (3 lines):
66 commands: enable, disable
67 * Peter Tarjan (ptarjan@citromail.hu) */
69 void get_ibm_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
72 unsigned int speed = 0;
75 if (!p_client_buffer || client_buffer_size <= 0) {
79 snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR);
86 if (fgets(line, 255, fp) == NULL) {
89 if (sscanf(line, "speed: %u", &speed)) {
94 CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
95 "ibm* from your "PACKAGE_NAME" config file.", fan, strerror(errno));
99 snprintf(p_client_buffer, client_buffer_size, "%d", speed);
102 /* get the measured temperatures from the temperature sensors
103 * on IBM/Lenovo laptops running the ibm acpi.
104 * There are 8 values in /proc/acpi/ibm/thermal, and according to
105 * http://ibm-acpi.sourceforge.net/README
106 * these mean the following (at least on an IBM R51...)
107 * 0: CPU (also on the T series laptops)
108 * 1: Mini PCI Module (?)
110 * 3: GPU (also on the T series laptops)
115 * I'm not too sure about those with the question mark, but the values I'm
116 * reading from *my* thermal file (on a T42p) look realistic for the
117 * hdd and the battery.
118 * #5 and #7 are always -128.
119 * /proc/acpi/ibm/thermal looks like this (1 line):
120 temperatures: 41 43 31 46 33 -128 29 -128
121 * Peter Tarjan (ptarjan@citromail.hu) */
123 static double last_ibm_acpi_temp_time;
124 void get_ibm_acpi_temps(void)
130 /* don't update too often */
131 if (current_update_time - last_ibm_acpi_temp_time < 10.00) {
134 last_ibm_acpi_temp_time = current_update_time;
136 /* if (!p_client_buffer || client_buffer_size <= 0) {
140 snprintf(thermal, 127, "%s/thermal", IBM_ACPI_DIR);
141 fp = fopen(thermal, "r");
147 if (fgets(line, 255, fp) == NULL) {
150 if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
151 &ibm_acpi.temps[0], &ibm_acpi.temps[1], &ibm_acpi.temps[2],
152 &ibm_acpi.temps[3], &ibm_acpi.temps[4], &ibm_acpi.temps[5],
153 &ibm_acpi.temps[6], &ibm_acpi.temps[7])) {
158 CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
159 "ibm* from your "PACKAGE_NAME" config file.", thermal, strerror(errno));
165 /* get volume (0-14) on IBM/Lenovo laptops running the ibm acpi.
166 * "Volume" here is none of the mixer volumes, but a "master of masters"
167 * volume adjusted by the IBM volume keys.
168 * /proc/acpi/ibm/fan looks like this (4 lines):
171 commands: up, down, mute
172 commands: level <level> (<level> is 0-15)
173 * Peter Tarjan (ptarjan@citromail.hu) */
175 void get_ibm_acpi_volume(char *p_client_buffer, size_t client_buffer_size)
179 unsigned int vol = -1;
182 if (!p_client_buffer || client_buffer_size <= 0) {
186 snprintf(volume, 127, "%s/volume", IBM_ACPI_DIR);
188 fp = fopen(volume, "r");
192 unsigned int read_vol = -1;
194 if (fgets(line, 255, fp) == NULL) {
197 if (sscanf(line, "level: %u", &read_vol)) {
201 if (sscanf(line, "mute: %s", mute)) {
206 CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
207 "ibm* from your "PACKAGE_NAME" config file.", volume, strerror(errno));
212 if (strcmp(mute, "on") == 0) {
213 snprintf(p_client_buffer, client_buffer_size, "%s", "mute");
216 snprintf(p_client_buffer, client_buffer_size, "%d", vol);
221 /* static FILE *fp = NULL; */
223 /* get LCD brightness on IBM/Lenovo laptops running the ibm acpi.
224 * /proc/acpi/ibm/brightness looks like this (3 lines):
227 commands: level <level> (<level> is 0-7)
228 * Peter Tarjan (ptarjan@citromail.hu) */
230 void get_ibm_acpi_brightness(char *p_client_buffer, size_t client_buffer_size)
233 unsigned int brightness = 0;
236 if (!p_client_buffer || client_buffer_size <= 0) {
240 snprintf(filename, 127, "%s/brightness", IBM_ACPI_DIR);
242 fp = fopen(filename, "r");
247 if (fgets(line, 255, fp) == NULL) {
250 if (sscanf(line, "level: %u", &brightness)) {
255 CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
256 "ibm* from your "PACKAGE_NAME" config file.", filename, strerror(errno));
261 snprintf(p_client_buffer, client_buffer_size, "%d", brightness);