E17: add temperature module for OpenBSD

Patch by Laurent Fanis <laurent@openbsd.org>


SVN revision: 64574
This commit is contained in:
Vincent Torri 2011-10-31 15:52:42 +00:00
parent d5247cd243
commit 7fd3d55bf2
4 changed files with 69 additions and 2 deletions

View File

@ -6,6 +6,13 @@
#include <sys/sysctl.h>
#endif
#ifdef __OpenBSD__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/sensors.h>
#endif
/* gadcon requirements */
static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
static void _gc_shutdown(E_Gadcon_Client *gcc);

View File

@ -45,7 +45,7 @@ struct _Config_Face
Ecore_Event_Handler *tempget_del_handler;
Eina_Bool have_temp:1;
#ifdef __FreeBSD__
#if defined (__FreeBSD__) || defined (__OpenBSD__)
int mib[5];
#endif
};

View File

@ -5,6 +5,7 @@ typedef enum _Sensor_Type
{
SENSOR_TYPE_NONE,
SENSOR_TYPE_FREEBSD,
SENSOR_TYPE_OPENBSD,
SENSOR_TYPE_OMNIBOOK,
SENSOR_TYPE_LINUX_MACMINI,
SENSOR_TYPE_LINUX_I2C,

View File

@ -11,6 +11,14 @@
# include <sys/sysctl.h>
#endif
#ifdef __OpenBSD__
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/sensors.h>
#include <errno.h>
#include <err.h>
#endif
#include <Ecore.h>
#include <Ecore_File.h>
@ -22,9 +30,18 @@ static int poll_interval = 32;
static int cur_poll_interval = 32;
static char *sensor_path = NULL;
#ifdef __FreeBSD__
#if defined (__FreeBSD__) || defined (__OpenBSD__)
static int mib[5];
#endif
#ifdef __OpenBSD__
static int dev, numt;
static struct sensordev snsrdev;
static size_t sdlen = sizeof(snsrdev);
static struct sensor snsr;
static size_t slen = sizeof(snsr);
#endif
static Ecore_Poller *poller = NULL;
static int ptemp = 0;
@ -93,6 +110,24 @@ init(void)
/* TODO: FreeBSD can also have more temperature sensors! */
sensor_type = SENSOR_TYPE_FREEBSD;
sensor_name = strdup("tz0");
#elif __OpenBSD__
mib[0] = CTL_HW;
mib[1] = HW_SENSORS;
for (dev = 0; ; dev++) {
mib[2] = dev;
if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) {
if (errno == ENOENT) /* no further sensors */
break;
else
continue;
}
if (strcmp(snsrdev.xname, "cpu0") == 0) {
sensor_type = SENSOR_TYPE_OPENBSD;
sensor_name = strdup("cpu0");
break;
}
}
#else
therms = ecore_file_ls("/proc/acpi/thermal_zone");
if (therms)
@ -235,6 +270,20 @@ init(void)
sysctlnametomib(sensor_path, mib, &len);
#endif
break;
case SENSOR_TYPE_OPENBSD:
#ifdef __OpenBSD__
for (numt = 0; numt < snsrdev.maxnumt[SENSOR_TEMP]; numt++) {
mib[4] = numt;
slen = sizeof(snsr);
if (sysctl(mib, 5, &snsr, &slen, NULL, 0) == -1)
continue;
if (slen > 0 && (snsr.flags & SENSOR_FINVALID) == 0) {
break;
}
}
#endif
break;
case SENSOR_TYPE_OMNIBOOK:
sensor_path = strdup("/proc/omnibook/temperature");
break;
@ -333,6 +382,16 @@ check(void)
}
else
goto error;
#endif
break;
case SENSOR_TYPE_OPENBSD:
#ifdef __OpenBSD__
if (sysctl(mib, 5, &snsr, &slen, NULL, 0) != -1) {
temp = (snsr.value - 273150000) / 1000000.0;
ret = 1;
}
else
goto error;
#endif
break;
case SENSOR_TYPE_OMNIBOOK: