1998-12-20 16:54:03 +00:00
|
|
|
/*
|
|
|
|
proc.c - Part of libsensors, a Linux library for reading sensor data.
|
1999-02-08 22:50:29 +00:00
|
|
|
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
1998-12-20 16:54:03 +00:00
|
|
|
|
|
|
|
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 2 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, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
1998-12-21 14:14:25 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2006-01-23 07:48:38 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
1998-12-20 16:54:03 +00:00
|
|
|
#include "data.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "access.h"
|
|
|
|
|
2007-06-25 13:32:27 +00:00
|
|
|
/* This reads a feature from a sysfs file.
|
2003-12-13 19:01:43 +00:00
|
|
|
Sysfs uses a one-value-per file system...
|
|
|
|
*/
|
1998-12-20 16:54:03 +00:00
|
|
|
int sensors_read_proc(sensors_chip_name name, int feature, double *value)
|
|
|
|
{
|
2003-11-17 14:22:05 +00:00
|
|
|
const sensors_chip_feature *the_feature;
|
2005-09-10 20:27:20 +00:00
|
|
|
int mag;
|
2007-06-28 18:19:58 +00:00
|
|
|
char n[NAME_MAX];
|
2007-06-25 13:32:27 +00:00
|
|
|
FILE *f;
|
2007-06-28 18:19:58 +00:00
|
|
|
int dummy;
|
|
|
|
char check;
|
|
|
|
const char *suffix = "";
|
2003-11-16 17:57:29 +00:00
|
|
|
|
2007-06-28 12:09:00 +00:00
|
|
|
if (!(the_feature = sensors_lookup_feature_nr(&name, feature)))
|
2003-11-16 17:57:29 +00:00
|
|
|
return -SENSORS_ERR_NO_ENTRY;
|
2007-06-25 13:32:27 +00:00
|
|
|
|
2007-06-28 18:19:58 +00:00
|
|
|
/* REVISIT: this is a ugly hack */
|
|
|
|
if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1
|
|
|
|
|| sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1
|
|
|
|
|| sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1)
|
|
|
|
suffix = "_input";
|
|
|
|
|
|
|
|
snprintf(n, NAME_MAX, "%s/%s%s", name.busname, the_feature->data.name,
|
|
|
|
suffix);
|
|
|
|
if ((f = fopen(n, "r"))) {
|
2007-06-25 13:32:27 +00:00
|
|
|
int res = fscanf(f, "%lf", value);
|
|
|
|
fclose(f);
|
|
|
|
if (res != 1)
|
2003-11-16 17:57:29 +00:00
|
|
|
return -SENSORS_ERR_PROC;
|
2007-06-28 18:19:58 +00:00
|
|
|
for (mag = the_feature->scaling; mag > 0; mag --)
|
2003-11-16 17:57:29 +00:00
|
|
|
*value /= 10.0;
|
2007-06-25 13:32:27 +00:00
|
|
|
} else
|
|
|
|
return -SENSORS_ERR_PROC;
|
|
|
|
|
2003-11-16 17:57:29 +00:00
|
|
|
return 0;
|
1998-12-20 16:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sensors_write_proc(sensors_chip_name name, int feature, double value)
|
|
|
|
{
|
2003-11-17 14:22:05 +00:00
|
|
|
const sensors_chip_feature *the_feature;
|
|
|
|
int mag;
|
2007-06-28 18:19:58 +00:00
|
|
|
char n[NAME_MAX];
|
2007-06-25 13:32:27 +00:00
|
|
|
FILE *f;
|
2007-06-28 18:19:58 +00:00
|
|
|
int dummy;
|
|
|
|
char check;
|
|
|
|
const char *suffix = "";
|
1998-12-20 16:54:03 +00:00
|
|
|
|
2007-06-28 12:09:00 +00:00
|
|
|
if (!(the_feature = sensors_lookup_feature_nr(&name, feature)))
|
2003-11-17 14:22:05 +00:00
|
|
|
return -SENSORS_ERR_NO_ENTRY;
|
2007-06-25 13:32:27 +00:00
|
|
|
|
2007-06-28 18:19:58 +00:00
|
|
|
/* REVISIT: this is a ugly hack */
|
|
|
|
if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1
|
|
|
|
|| sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1
|
|
|
|
|| sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1)
|
|
|
|
suffix = "_input";
|
|
|
|
|
|
|
|
snprintf(n, NAME_MAX, "%s/%s%s", name.busname, the_feature->data.name,
|
|
|
|
suffix);
|
|
|
|
if ((f = fopen(n, "w"))) {
|
|
|
|
for (mag = the_feature->scaling; mag > 0; mag --)
|
2003-11-17 14:22:05 +00:00
|
|
|
value *= 10.0;
|
2007-06-25 13:32:27 +00:00
|
|
|
fprintf(f, "%d", (int) value);
|
|
|
|
fclose(f);
|
|
|
|
} else
|
|
|
|
return -SENSORS_ERR_PROC;
|
|
|
|
|
2003-11-17 14:22:05 +00:00
|
|
|
return 0;
|
1998-12-20 16:54:03 +00:00
|
|
|
}
|