2009-07-28 21:44:22 +00:00
|
|
|
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
2009-09-12 10:50:51 +00:00
|
|
|
* vim: ts=4 sw=4 noet ai cindent syntax=c
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2009-05-04 19:19:44 +00:00
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
|
|
|
* Copyright (c) 2009 Yeon-Hyeong Yang <lbird94@gmail.com>
|
|
|
|
* (see AUTHORS)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2009-05-04 19:15:46 +00:00
|
|
|
/* conky support for information from sony_laptop kernel module
|
|
|
|
* information from sony_laptop kernel module
|
|
|
|
* /sys/devices/platform/sony-laptop
|
|
|
|
* I mimicked the methods from ibm.c
|
|
|
|
* Yeon-Hyeong Yang <lbird94@gmail.com> */
|
|
|
|
|
|
|
|
#include "conky.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "sony.h"
|
|
|
|
#include "logging.h"
|
2009-11-15 23:59:39 +00:00
|
|
|
#include "text_object.h"
|
2009-05-04 19:15:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define SONY_LAPTOP_DIR "/sys/devices/platform/sony-laptop"
|
|
|
|
|
|
|
|
/* fanspeed in SONY_LAPTOP_DIR contains an integer value for fanspeed (0~255).
|
|
|
|
* I don't know the exact measurement unit, though. I may assume that 0 for
|
|
|
|
* 'fan stopped' and 255 for 'maximum fan speed'. */
|
2009-11-15 23:59:39 +00:00
|
|
|
void get_sony_fanspeed(struct text_object *obj, char *p_client_buffer, int client_buffer_size)
|
2009-05-04 19:15:46 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
unsigned int speed = 0;
|
|
|
|
char fan[128];
|
|
|
|
|
2009-11-15 23:59:39 +00:00
|
|
|
(void)obj;
|
|
|
|
|
2009-05-04 19:15:46 +00:00
|
|
|
if (!p_client_buffer || client_buffer_size <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(fan, 127, "%s/fanspeed", SONY_LAPTOP_DIR);
|
|
|
|
|
|
|
|
fp = fopen(fan, "r");
|
|
|
|
if (fp != NULL) {
|
|
|
|
while (!feof(fp)) {
|
|
|
|
char line[256];
|
|
|
|
|
|
|
|
if (fgets(line, 255, fp) == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sscanf(line, "%u", &speed)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2009-07-16 18:28:23 +00:00
|
|
|
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nEnable sony support or remove "
|
2009-05-04 19:15:46 +00:00
|
|
|
"sony* from your "PACKAGE_NAME" config file.",
|
|
|
|
fan, strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
snprintf(p_client_buffer, client_buffer_size, "%d", speed);
|
|
|
|
}
|
|
|
|
|