add emacs indentation variables to source files in line with current vim settings
[monky] / src / sony.c
1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2  *
3  * Conky, a system monitor, based on torsmo
4  *
5  * Please see COPYING for details
6  *
7  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
8  * Copyright (c) 2009 Yeon-Hyeong Yang <lbird94@gmail.com>
9  *      (see AUTHORS)
10  * All rights reserved.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  * vim: ts=4 sw=4 noet ai cindent syntax=c
25  *
26  */
27 /* conky support for information from sony_laptop kernel module
28  *   information from sony_laptop kernel module
29  *   /sys/devices/platform/sony-laptop
30  *   I mimicked the methods from ibm.c
31  * Yeon-Hyeong Yang <lbird94@gmail.com> */
32
33 #include "conky.h"
34 #include "config.h"
35 #include "sony.h"
36 #include "logging.h"
37 #include <stdio.h>
38 #include <errno.h>
39 #include <string.h>
40 #include <stdlib.h>
41
42 #define SONY_LAPTOP_DIR "/sys/devices/platform/sony-laptop"
43
44 /* fanspeed in SONY_LAPTOP_DIR contains an integer value for fanspeed (0~255).
45  * I don't know the exact measurement unit, though. I may assume that 0 for
46  * 'fan stopped' and 255 for 'maximum fan speed'. */
47 void get_sony_fanspeed(char *p_client_buffer, size_t client_buffer_size)
48 {
49         FILE *fp;
50         unsigned int speed = 0;
51         char fan[128];
52
53         if (!p_client_buffer || client_buffer_size <= 0) {
54                 return;
55         }
56
57         snprintf(fan, 127, "%s/fanspeed", SONY_LAPTOP_DIR);
58
59         fp = fopen(fan, "r");
60         if (fp != NULL) {
61                 while (!feof(fp)) {
62                         char line[256];
63
64                         if (fgets(line, 255, fp) == NULL) {
65                                 break;
66                         }
67                         if (sscanf(line, "%u", &speed)) {
68                                 break;
69                         }
70                 }
71         } else {
72                 CRIT_ERR(NULL, NULL, "can't open '%s': %s\nEnable sony support or remove "
73                         "sony* from your "PACKAGE_NAME" config file.",
74                         fan, strerror(errno));
75         }
76
77         fclose(fp);
78         snprintf(p_client_buffer, client_buffer_size, "%d", speed);
79 }
80