2018-05-12 16:03:00 +00:00
|
|
|
/*
|
2009-11-16 19:58:26 +00:00
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
|
|
|
*
|
|
|
|
* Any original torsmo code is licensed under the BSD license
|
|
|
|
*
|
|
|
|
* All code written since the fork of torsmo is licensed under the GPL
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
|
|
|
* Copyright (c) 2007 Toni Spets
|
2021-02-27 15:14:19 +00:00
|
|
|
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
2009-11-16 19:58:26 +00:00
|
|
|
* (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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-05-05 23:24:30 +00:00
|
|
|
#include "conky.h"
|
2009-11-16 19:58:26 +00:00
|
|
|
#include "logging.h"
|
|
|
|
#include "temphelper.h"
|
|
|
|
#include "text_object.h"
|
|
|
|
|
2010-01-04 17:06:14 +00:00
|
|
|
struct _i8k {
|
2018-05-12 16:03:00 +00:00
|
|
|
char *version;
|
|
|
|
char *bios;
|
|
|
|
char *serial;
|
|
|
|
char *cpu_temp;
|
|
|
|
char *left_fan_status;
|
|
|
|
char *right_fan_status;
|
|
|
|
char *left_fan_rpm;
|
|
|
|
char *right_fan_rpm;
|
|
|
|
char *ac_status;
|
|
|
|
char *buttons_status;
|
2009-11-16 19:58:26 +00:00
|
|
|
} i8k;
|
|
|
|
|
|
|
|
/* FIXME: there should be an ioctl interface to request specific data */
|
|
|
|
#define PROC_I8K "/proc/i8k"
|
|
|
|
#define I8K_DELIM " "
|
2018-05-12 23:26:31 +00:00
|
|
|
static char *i8k_procbuf = nullptr;
|
2018-05-12 16:03:00 +00:00
|
|
|
int update_i8k(void) {
|
|
|
|
FILE *fp;
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
if ((fp = fopen(PROC_I8K, "r")) == nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
NORM_ERR(
|
|
|
|
"/proc/i8k doesn't exist! use insmod to make sure the kernel driver is "
|
|
|
|
"loaded...");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-05-05 00:48:51 +00:00
|
|
|
if (!i8k_procbuf) { i8k_procbuf = (char *)malloc(128 * sizeof(char)); }
|
2018-05-12 16:03:00 +00:00
|
|
|
memset(&i8k_procbuf[0], 0, 128);
|
|
|
|
if (fread(&i8k_procbuf[0], sizeof(char), 128, fp) == 0) {
|
|
|
|
NORM_ERR("something wrong with /proc/i8k...");
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
DBGP("read `%s' from /proc/i8k\n", i8k_procbuf);
|
|
|
|
|
|
|
|
i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
|
2018-05-12 23:26:31 +00:00
|
|
|
i8k.bios = strtok(nullptr, I8K_DELIM);
|
|
|
|
i8k.serial = strtok(nullptr, I8K_DELIM);
|
|
|
|
i8k.cpu_temp = strtok(nullptr, I8K_DELIM);
|
|
|
|
i8k.left_fan_status = strtok(nullptr, I8K_DELIM);
|
|
|
|
i8k.right_fan_status = strtok(nullptr, I8K_DELIM);
|
|
|
|
i8k.left_fan_rpm = strtok(nullptr, I8K_DELIM);
|
|
|
|
i8k.right_fan_rpm = strtok(nullptr, I8K_DELIM);
|
|
|
|
i8k.ac_status = strtok(nullptr, I8K_DELIM);
|
|
|
|
i8k.buttons_status = strtok(nullptr, I8K_DELIM);
|
2018-05-12 16:03:00 +00:00
|
|
|
return 0;
|
2009-11-16 19:58:26 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static void print_i8k_fan_status(char *p, int p_max_size, const char *status) {
|
|
|
|
static const char *status_arr[] = {"off", "low", "high", "error"};
|
2010-08-20 10:07:21 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
int i = status ? atoi(status) : 3;
|
|
|
|
if (i < 0 || i > 3) i = 3;
|
2010-08-20 10:07:21 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
snprintf(p, p_max_size, "%s", status_arr[i]);
|
2009-11-16 19:58:26 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
void print_i8k_left_fan_status(struct text_object *obj, char *p,
|
2018-08-07 23:22:23 +00:00
|
|
|
unsigned int p_max_size) {
|
2018-05-12 16:03:00 +00:00
|
|
|
(void)obj;
|
|
|
|
print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
|
2009-11-16 19:58:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 19:40:34 +00:00
|
|
|
void print_i8k_cpu_temp(struct text_object *obj, char *p,
|
|
|
|
unsigned int p_max_size) {
|
2018-05-12 16:03:00 +00:00
|
|
|
int cpu_temp;
|
2009-11-16 19:58:26 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
(void)obj;
|
2009-11-16 19:58:26 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
sscanf(i8k.cpu_temp, "%d", &cpu_temp);
|
2018-08-04 19:01:28 +00:00
|
|
|
temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS, 1);
|
2009-11-16 19:58:26 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
void print_i8k_right_fan_status(struct text_object *obj, char *p,
|
2018-08-07 23:22:23 +00:00
|
|
|
unsigned int p_max_size) {
|
2018-05-12 16:03:00 +00:00
|
|
|
(void)obj;
|
|
|
|
print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
|
2009-11-16 19:58:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 19:40:34 +00:00
|
|
|
void print_i8k_ac_status(struct text_object *obj, char *p,
|
|
|
|
unsigned int p_max_size) {
|
2018-05-12 16:03:00 +00:00
|
|
|
int ac_status;
|
|
|
|
|
|
|
|
(void)obj;
|
|
|
|
|
|
|
|
sscanf(i8k.ac_status, "%d", &ac_status);
|
|
|
|
if (ac_status == -1) {
|
2018-08-02 15:15:16 +00:00
|
|
|
snprintf(p, p_max_size, "%s", "disabled (read i8k docs)");
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2019-02-23 19:40:34 +00:00
|
|
|
if (ac_status == 0) { snprintf(p, p_max_size, "%s", "off"); }
|
|
|
|
if (ac_status == 1) { snprintf(p, p_max_size, "%s", "on"); }
|
2009-11-16 19:58:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 19:40:34 +00:00
|
|
|
#define I8K_PRINT_GENERATOR(name) \
|
|
|
|
void print_i8k_##name(struct text_object *obj, char *p, \
|
|
|
|
unsigned int p_max_size) { \
|
|
|
|
(void)obj; \
|
2023-05-05 00:49:43 +00:00
|
|
|
const char *str = i8k.name ? i8k.name : "error"; \
|
|
|
|
snprintf(p, p_max_size, "%s", str); \
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2009-11-16 19:58:26 +00:00
|
|
|
|
|
|
|
I8K_PRINT_GENERATOR(version)
|
|
|
|
I8K_PRINT_GENERATOR(bios)
|
|
|
|
I8K_PRINT_GENERATOR(serial)
|
|
|
|
I8K_PRINT_GENERATOR(left_fan_rpm)
|
|
|
|
I8K_PRINT_GENERATOR(right_fan_rpm)
|
|
|
|
I8K_PRINT_GENERATOR(buttons_status)
|
|
|
|
|
|
|
|
#undef I8K_PRINT_GENERATOR
|