SENSOR_ATTACH(9)

NAME
sensor_attach, sensor_detach, sensor_find, sensordev_install, sensordev_deinstall, sensordev_get, sensor_task_register, sensor_task_unregister - sensors framework

SYNOPSIS
#include <sys/sensors.h>
void
sensordev_install(struct ksensordev *sensdev);
void
sensordev_deinstall(struct ksensordev *sensdev);
struct ksensordev *
sensordev_get(int devnum);

void
sensor_attach(struct ksensordev *sensdev, struct ksensor *sens);
void
sensor_detach(struct ksensordev *sensdev, struct ksensor *sens);
struct ksensor *
sensor_find(int devnum, enum sensor_type stype, int numt);

struct sensor_task *
sensor_task_register(void *arg, void (*func)(void *), int period);
void
sensor_task_unregister(struct sensor_task *st);

DESCRIPTION
The sensors framework API provides a mechanism for manipulation of hardware sensors that are available under the hw.sensors sysctl(8) tree.

sensor_attach() adds the sensor specified by the sens argument to the sensor device specified by the sensdev argument. sensor_detach() can be used to remove sensors previously added by sensor_attach().

sensordev_install() registers the sensor device specified by the sensdev argument so that all sensors that are attached to the device become accessible via the sysctl interface. sensordev_deinstall() can be used to remove sensor devices previously registered by sensordev_install().

sensordev_get() takes ordinal number devnum specifying a sensor device and returns a pointer to the corresponding struct ksensordev, or NULL if no such sensor device exists.

sensor_find() takes ordinal number devnum specifying a sensor device, sensor type stype and ordinal number of sensor of such type numt, and returns a pointer to the corresponding struct ksensor, or NULL if no such sensor exists. sensor_find() will always return NULL if the corresponding sensor devices are not registered by sensordev_install().

Drivers are responsible for retrieving, interpreting, and normalising sensor values and updating the sensor struct periodically. If the driver needs process context, for example to sleep, it can register a task with the sensor framework.

sensor_task_register() is used to register a periodic task to update sensors. The func argument is a pointer to the function to run with an interval of period seconds. The arg parameter is the argument given to the func function. sensor_task_unregister() ensures that the task specified by the st argument is no longer running, and then removes it from the queue.

All the functions in the sensor framework must be called during autoconf(9) or from a process context. Additionally, sensor_task_unregister() must not be called from the sensor task that it is about to remove.

SEE ALSO
sysctl(8), autoconf(9)

HISTORY
The sensor framework was written by Alexander Yurchenko <grange@openbsd.org> and first appeared in OpenBSD 3.4. David Gwynne <dlg@openbsd.org> later extended it for OpenBSD 3.8. Constantine A. Murenin <cnst+openbsd@bugmail.mojo.ru> extended it even further by introducing the concept of sensor devices in OpenBSD 4.1.