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