2019-06-04 01:11:33 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-02-13 02:25:34 -07:00
|
|
|
/* Industrialio event test code.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2012 Lars-Peter Clausen <lars@metafoo.de>
|
|
|
|
*
|
|
|
|
* This program is primarily intended as an example application.
|
|
|
|
* Reads the current buffer setup from sysfs and starts a short capture
|
|
|
|
* from the specified device, pretty printing the result after appropriate
|
|
|
|
* conversion.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* iio_event_monitor <device_name>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
2015-02-26 01:49:24 -07:00
|
|
|
#include <stdlib.h>
|
2021-03-19 06:53:01 -07:00
|
|
|
#include <dirent.h>
|
2012-02-13 02:25:34 -07:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "iio_utils.h"
|
2012-04-25 07:54:58 -07:00
|
|
|
#include <linux/iio/events.h>
|
2015-02-26 01:49:23 -07:00
|
|
|
#include <linux/iio/types.h>
|
2012-02-13 02:25:34 -07:00
|
|
|
|
|
|
|
static const char * const iio_chan_type_name_spec[] = {
|
|
|
|
[IIO_VOLTAGE] = "voltage",
|
|
|
|
[IIO_CURRENT] = "current",
|
|
|
|
[IIO_POWER] = "power",
|
|
|
|
[IIO_ACCEL] = "accel",
|
|
|
|
[IIO_ANGL_VEL] = "anglvel",
|
|
|
|
[IIO_MAGN] = "magn",
|
|
|
|
[IIO_LIGHT] = "illuminance",
|
|
|
|
[IIO_INTENSITY] = "intensity",
|
|
|
|
[IIO_PROXIMITY] = "proximity",
|
|
|
|
[IIO_TEMP] = "temp",
|
|
|
|
[IIO_INCLI] = "incli",
|
|
|
|
[IIO_ROT] = "rot",
|
|
|
|
[IIO_ANGL] = "angl",
|
|
|
|
[IIO_TIMESTAMP] = "timestamp",
|
|
|
|
[IIO_CAPACITANCE] = "capacitance",
|
2012-06-15 10:25:26 -07:00
|
|
|
[IIO_ALTVOLTAGE] = "altvoltage",
|
2014-12-05 23:00:00 -07:00
|
|
|
[IIO_CCT] = "cct",
|
|
|
|
[IIO_PRESSURE] = "pressure",
|
|
|
|
[IIO_HUMIDITYRELATIVE] = "humidityrelative",
|
iio: event_monitor: Add support for new channel types
We have the following testing scenario:
$ insmod iio_dummy_evgen.ko
$ insmod iio_dummy.ko
./iio_event_monitor /dev/iio:device0
Event: time: 1412786467971335337, type: activity(running), channel: 0,
evtype: thresh, direction: rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0,
evtype: thresh, direction: falling
Event: time: 1412764319184761765, type: steps, channel: 0, evtype: instance
$ echo 1 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 2 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 3 > /sys/bus/iio/devices/iio_evgen/poke_ev0
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-11-10 05:45:35 -07:00
|
|
|
[IIO_ACTIVITY] = "activity",
|
|
|
|
[IIO_STEPS] = "steps",
|
2015-06-20 14:52:31 -07:00
|
|
|
[IIO_ENERGY] = "energy",
|
|
|
|
[IIO_DISTANCE] = "distance",
|
|
|
|
[IIO_VELOCITY] = "velocity",
|
2016-03-15 14:54:51 -07:00
|
|
|
[IIO_CONCENTRATION] = "concentration",
|
|
|
|
[IIO_RESISTANCE] = "resistance",
|
|
|
|
[IIO_PH] = "ph",
|
2016-03-20 08:20:23 -07:00
|
|
|
[IIO_UVINDEX] = "uvindex",
|
2017-01-05 03:24:03 -07:00
|
|
|
[IIO_GRAVITY] = "gravity",
|
2018-05-22 00:52:32 -07:00
|
|
|
[IIO_POSITIONRELATIVE] = "positionrelative",
|
2018-07-20 10:34:25 -07:00
|
|
|
[IIO_PHASE] = "phase",
|
2018-12-14 11:28:01 -07:00
|
|
|
[IIO_MASSCONCENTRATION] = "massconcentration",
|
2023-08-08 00:50:57 -07:00
|
|
|
[IIO_DELTA_ANGL] = "deltaangl",
|
2023-08-08 00:50:58 -07:00
|
|
|
[IIO_DELTA_VELOCITY] = "deltavelocity",
|
2023-09-19 01:10:47 -07:00
|
|
|
[IIO_COLORTEMP] = "colortemp",
|
2023-09-19 01:10:51 -07:00
|
|
|
[IIO_CHROMATICITY] = "chromaticity",
|
2012-02-13 02:25:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const iio_ev_type_text[] = {
|
|
|
|
[IIO_EV_TYPE_THRESH] = "thresh",
|
|
|
|
[IIO_EV_TYPE_MAG] = "mag",
|
|
|
|
[IIO_EV_TYPE_ROC] = "roc",
|
|
|
|
[IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
|
|
|
|
[IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
|
2015-01-11 12:10:11 -07:00
|
|
|
[IIO_EV_TYPE_CHANGE] = "change",
|
2022-02-14 00:38:06 -07:00
|
|
|
[IIO_EV_TYPE_MAG_REFERENCED] = "mag_referenced",
|
2022-08-30 23:31:16 -07:00
|
|
|
[IIO_EV_TYPE_GESTURE] = "gesture",
|
2012-02-13 02:25:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const iio_ev_dir_text[] = {
|
|
|
|
[IIO_EV_DIR_EITHER] = "either",
|
|
|
|
[IIO_EV_DIR_RISING] = "rising",
|
2022-08-30 23:31:16 -07:00
|
|
|
[IIO_EV_DIR_FALLING] = "falling",
|
|
|
|
[IIO_EV_DIR_SINGLETAP] = "singletap",
|
|
|
|
[IIO_EV_DIR_DOUBLETAP] = "doubletap",
|
2012-02-13 02:25:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const iio_modifier_names[] = {
|
|
|
|
[IIO_MOD_X] = "x",
|
|
|
|
[IIO_MOD_Y] = "y",
|
|
|
|
[IIO_MOD_Z] = "z",
|
2014-10-22 06:50:17 -07:00
|
|
|
[IIO_MOD_X_AND_Y] = "x&y",
|
|
|
|
[IIO_MOD_X_AND_Z] = "x&z",
|
|
|
|
[IIO_MOD_Y_AND_Z] = "y&z",
|
|
|
|
[IIO_MOD_X_AND_Y_AND_Z] = "x&y&z",
|
|
|
|
[IIO_MOD_X_OR_Y] = "x|y",
|
|
|
|
[IIO_MOD_X_OR_Z] = "x|z",
|
|
|
|
[IIO_MOD_Y_OR_Z] = "y|z",
|
|
|
|
[IIO_MOD_X_OR_Y_OR_Z] = "x|y|z",
|
2012-02-13 02:25:34 -07:00
|
|
|
[IIO_MOD_LIGHT_BOTH] = "both",
|
|
|
|
[IIO_MOD_LIGHT_IR] = "ir",
|
2012-07-01 03:20:13 -07:00
|
|
|
[IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)",
|
|
|
|
[IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2",
|
|
|
|
[IIO_MOD_LIGHT_CLEAR] = "clear",
|
|
|
|
[IIO_MOD_LIGHT_RED] = "red",
|
|
|
|
[IIO_MOD_LIGHT_GREEN] = "green",
|
|
|
|
[IIO_MOD_LIGHT_BLUE] = "blue",
|
2016-03-20 08:20:22 -07:00
|
|
|
[IIO_MOD_LIGHT_UV] = "uv",
|
2023-11-27 10:34:28 -07:00
|
|
|
[IIO_MOD_LIGHT_UVA] = "uva",
|
|
|
|
[IIO_MOD_LIGHT_UVB] = "uvb",
|
2018-07-19 13:26:24 -07:00
|
|
|
[IIO_MOD_LIGHT_DUV] = "duv",
|
2014-10-22 06:50:17 -07:00
|
|
|
[IIO_MOD_QUATERNION] = "quaternion",
|
|
|
|
[IIO_MOD_TEMP_AMBIENT] = "ambient",
|
|
|
|
[IIO_MOD_TEMP_OBJECT] = "object",
|
|
|
|
[IIO_MOD_NORTH_MAGN] = "from_north_magnetic",
|
|
|
|
[IIO_MOD_NORTH_TRUE] = "from_north_true",
|
|
|
|
[IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
|
|
|
|
[IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
|
iio: event_monitor: Add support for new channel types
We have the following testing scenario:
$ insmod iio_dummy_evgen.ko
$ insmod iio_dummy.ko
./iio_event_monitor /dev/iio:device0
Event: time: 1412786467971335337, type: activity(running), channel: 0,
evtype: thresh, direction: rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0,
evtype: thresh, direction: falling
Event: time: 1412764319184761765, type: steps, channel: 0, evtype: instance
$ echo 1 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 2 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 3 > /sys/bus/iio/devices/iio_evgen/poke_ev0
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-11-10 05:45:35 -07:00
|
|
|
[IIO_MOD_RUNNING] = "running",
|
|
|
|
[IIO_MOD_JOGGING] = "jogging",
|
|
|
|
[IIO_MOD_WALKING] = "walking",
|
|
|
|
[IIO_MOD_STILL] = "still",
|
2015-06-20 14:52:31 -07:00
|
|
|
[IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)",
|
2016-03-15 14:54:51 -07:00
|
|
|
[IIO_MOD_I] = "i",
|
|
|
|
[IIO_MOD_Q] = "q",
|
|
|
|
[IIO_MOD_CO2] = "co2",
|
2018-12-13 07:43:22 -07:00
|
|
|
[IIO_MOD_ETHANOL] = "ethanol",
|
|
|
|
[IIO_MOD_H2] = "h2",
|
2016-03-15 14:54:51 -07:00
|
|
|
[IIO_MOD_VOC] = "voc",
|
2018-12-14 11:28:01 -07:00
|
|
|
[IIO_MOD_PM1] = "pm1",
|
|
|
|
[IIO_MOD_PM2P5] = "pm2p5",
|
|
|
|
[IIO_MOD_PM4] = "pm4",
|
|
|
|
[IIO_MOD_PM10] = "pm10",
|
2020-07-22 23:29:43 -07:00
|
|
|
[IIO_MOD_O2] = "o2",
|
2022-09-07 06:21:54 -07:00
|
|
|
[IIO_MOD_LINEAR_X] = "linear_x",
|
|
|
|
[IIO_MOD_LINEAR_Y] = "linear_y",
|
|
|
|
[IIO_MOD_LINEAR_Z] = "linear_z",
|
2022-09-07 06:21:57 -07:00
|
|
|
[IIO_MOD_PITCH] = "pitch",
|
|
|
|
[IIO_MOD_YAW] = "yaw",
|
|
|
|
[IIO_MOD_ROLL] = "roll",
|
2012-02-13 02:25:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool event_is_known(struct iio_event_data *event)
|
|
|
|
{
|
|
|
|
enum iio_chan_type type = IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event->id);
|
|
|
|
enum iio_modifier mod = IIO_EVENT_CODE_EXTRACT_MODIFIER(event->id);
|
|
|
|
enum iio_event_type ev_type = IIO_EVENT_CODE_EXTRACT_TYPE(event->id);
|
|
|
|
enum iio_event_direction dir = IIO_EVENT_CODE_EXTRACT_DIR(event->id);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case IIO_VOLTAGE:
|
|
|
|
case IIO_CURRENT:
|
|
|
|
case IIO_POWER:
|
|
|
|
case IIO_ACCEL:
|
|
|
|
case IIO_ANGL_VEL:
|
|
|
|
case IIO_MAGN:
|
|
|
|
case IIO_LIGHT:
|
|
|
|
case IIO_INTENSITY:
|
|
|
|
case IIO_PROXIMITY:
|
|
|
|
case IIO_TEMP:
|
|
|
|
case IIO_INCLI:
|
|
|
|
case IIO_ROT:
|
|
|
|
case IIO_ANGL:
|
|
|
|
case IIO_TIMESTAMP:
|
|
|
|
case IIO_CAPACITANCE:
|
2012-06-15 10:25:26 -07:00
|
|
|
case IIO_ALTVOLTAGE:
|
2014-12-05 23:00:00 -07:00
|
|
|
case IIO_CCT:
|
|
|
|
case IIO_PRESSURE:
|
|
|
|
case IIO_HUMIDITYRELATIVE:
|
iio: event_monitor: Add support for new channel types
We have the following testing scenario:
$ insmod iio_dummy_evgen.ko
$ insmod iio_dummy.ko
./iio_event_monitor /dev/iio:device0
Event: time: 1412786467971335337, type: activity(running), channel: 0,
evtype: thresh, direction: rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0,
evtype: thresh, direction: falling
Event: time: 1412764319184761765, type: steps, channel: 0, evtype: instance
$ echo 1 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 2 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 3 > /sys/bus/iio/devices/iio_evgen/poke_ev0
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-11-10 05:45:35 -07:00
|
|
|
case IIO_ACTIVITY:
|
|
|
|
case IIO_STEPS:
|
2015-06-20 14:52:31 -07:00
|
|
|
case IIO_ENERGY:
|
|
|
|
case IIO_DISTANCE:
|
|
|
|
case IIO_VELOCITY:
|
2016-03-15 14:54:51 -07:00
|
|
|
case IIO_CONCENTRATION:
|
|
|
|
case IIO_RESISTANCE:
|
|
|
|
case IIO_PH:
|
2016-03-20 08:20:23 -07:00
|
|
|
case IIO_UVINDEX:
|
2017-01-05 03:24:03 -07:00
|
|
|
case IIO_GRAVITY:
|
2018-05-22 00:52:32 -07:00
|
|
|
case IIO_POSITIONRELATIVE:
|
2018-07-20 10:34:25 -07:00
|
|
|
case IIO_PHASE:
|
2018-12-14 11:28:01 -07:00
|
|
|
case IIO_MASSCONCENTRATION:
|
2023-08-08 00:50:57 -07:00
|
|
|
case IIO_DELTA_ANGL:
|
2023-08-08 00:50:58 -07:00
|
|
|
case IIO_DELTA_VELOCITY:
|
2023-09-19 01:10:47 -07:00
|
|
|
case IIO_COLORTEMP:
|
2023-09-19 01:10:51 -07:00
|
|
|
case IIO_CHROMATICITY:
|
2012-02-13 02:25:34 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mod) {
|
|
|
|
case IIO_NO_MOD:
|
|
|
|
case IIO_MOD_X:
|
|
|
|
case IIO_MOD_Y:
|
|
|
|
case IIO_MOD_Z:
|
2014-10-22 06:50:17 -07:00
|
|
|
case IIO_MOD_X_AND_Y:
|
|
|
|
case IIO_MOD_X_AND_Z:
|
|
|
|
case IIO_MOD_Y_AND_Z:
|
|
|
|
case IIO_MOD_X_AND_Y_AND_Z:
|
|
|
|
case IIO_MOD_X_OR_Y:
|
|
|
|
case IIO_MOD_X_OR_Z:
|
|
|
|
case IIO_MOD_Y_OR_Z:
|
|
|
|
case IIO_MOD_X_OR_Y_OR_Z:
|
2012-02-13 02:25:34 -07:00
|
|
|
case IIO_MOD_LIGHT_BOTH:
|
|
|
|
case IIO_MOD_LIGHT_IR:
|
2012-07-01 03:20:13 -07:00
|
|
|
case IIO_MOD_ROOT_SUM_SQUARED_X_Y:
|
|
|
|
case IIO_MOD_SUM_SQUARED_X_Y_Z:
|
|
|
|
case IIO_MOD_LIGHT_CLEAR:
|
|
|
|
case IIO_MOD_LIGHT_RED:
|
|
|
|
case IIO_MOD_LIGHT_GREEN:
|
|
|
|
case IIO_MOD_LIGHT_BLUE:
|
2016-03-20 08:20:22 -07:00
|
|
|
case IIO_MOD_LIGHT_UV:
|
2018-07-19 13:26:24 -07:00
|
|
|
case IIO_MOD_LIGHT_DUV:
|
2014-10-22 06:50:17 -07:00
|
|
|
case IIO_MOD_QUATERNION:
|
|
|
|
case IIO_MOD_TEMP_AMBIENT:
|
|
|
|
case IIO_MOD_TEMP_OBJECT:
|
|
|
|
case IIO_MOD_NORTH_MAGN:
|
|
|
|
case IIO_MOD_NORTH_TRUE:
|
|
|
|
case IIO_MOD_NORTH_MAGN_TILT_COMP:
|
|
|
|
case IIO_MOD_NORTH_TRUE_TILT_COMP:
|
iio: event_monitor: Add support for new channel types
We have the following testing scenario:
$ insmod iio_dummy_evgen.ko
$ insmod iio_dummy.ko
./iio_event_monitor /dev/iio:device0
Event: time: 1412786467971335337, type: activity(running), channel: 0,
evtype: thresh, direction: rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0,
evtype: thresh, direction: falling
Event: time: 1412764319184761765, type: steps, channel: 0, evtype: instance
$ echo 1 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 2 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 3 > /sys/bus/iio/devices/iio_evgen/poke_ev0
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-11-10 05:45:35 -07:00
|
|
|
case IIO_MOD_RUNNING:
|
|
|
|
case IIO_MOD_JOGGING:
|
|
|
|
case IIO_MOD_WALKING:
|
|
|
|
case IIO_MOD_STILL:
|
2015-06-20 14:52:31 -07:00
|
|
|
case IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z:
|
2016-03-15 14:54:51 -07:00
|
|
|
case IIO_MOD_I:
|
|
|
|
case IIO_MOD_Q:
|
|
|
|
case IIO_MOD_CO2:
|
2018-12-13 07:43:22 -07:00
|
|
|
case IIO_MOD_ETHANOL:
|
|
|
|
case IIO_MOD_H2:
|
2016-03-15 14:54:51 -07:00
|
|
|
case IIO_MOD_VOC:
|
2018-12-14 11:28:01 -07:00
|
|
|
case IIO_MOD_PM1:
|
|
|
|
case IIO_MOD_PM2P5:
|
|
|
|
case IIO_MOD_PM4:
|
|
|
|
case IIO_MOD_PM10:
|
2020-07-22 23:29:43 -07:00
|
|
|
case IIO_MOD_O2:
|
2012-02-13 02:25:34 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ev_type) {
|
|
|
|
case IIO_EV_TYPE_THRESH:
|
|
|
|
case IIO_EV_TYPE_MAG:
|
|
|
|
case IIO_EV_TYPE_ROC:
|
|
|
|
case IIO_EV_TYPE_THRESH_ADAPTIVE:
|
|
|
|
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
2015-01-11 12:10:11 -07:00
|
|
|
case IIO_EV_TYPE_CHANGE:
|
2022-08-30 23:31:16 -07:00
|
|
|
case IIO_EV_TYPE_GESTURE:
|
2012-02-13 02:25:34 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dir) {
|
|
|
|
case IIO_EV_DIR_EITHER:
|
|
|
|
case IIO_EV_DIR_RISING:
|
|
|
|
case IIO_EV_DIR_FALLING:
|
2022-08-30 23:31:16 -07:00
|
|
|
case IIO_EV_DIR_SINGLETAP:
|
|
|
|
case IIO_EV_DIR_DOUBLETAP:
|
iio: event_monitor: Add support for new channel types
We have the following testing scenario:
$ insmod iio_dummy_evgen.ko
$ insmod iio_dummy.ko
./iio_event_monitor /dev/iio:device0
Event: time: 1412786467971335337, type: activity(running), channel: 0,
evtype: thresh, direction: rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0,
evtype: thresh, direction: falling
Event: time: 1412764319184761765, type: steps, channel: 0, evtype: instance
$ echo 1 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 2 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 3 > /sys/bus/iio/devices/iio_evgen/poke_ev0
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-11-10 05:45:35 -07:00
|
|
|
case IIO_EV_DIR_NONE:
|
2012-02-13 02:25:34 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_event(struct iio_event_data *event)
|
|
|
|
{
|
|
|
|
enum iio_chan_type type = IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event->id);
|
|
|
|
enum iio_modifier mod = IIO_EVENT_CODE_EXTRACT_MODIFIER(event->id);
|
|
|
|
enum iio_event_type ev_type = IIO_EVENT_CODE_EXTRACT_TYPE(event->id);
|
|
|
|
enum iio_event_direction dir = IIO_EVENT_CODE_EXTRACT_DIR(event->id);
|
|
|
|
int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event->id);
|
|
|
|
int chan2 = IIO_EVENT_CODE_EXTRACT_CHAN2(event->id);
|
|
|
|
bool diff = IIO_EVENT_CODE_EXTRACT_DIFF(event->id);
|
|
|
|
|
|
|
|
if (!event_is_known(event)) {
|
2015-07-17 08:43:42 -07:00
|
|
|
fprintf(stderr, "Unknown event: time: %lld, id: %llx\n",
|
|
|
|
event->timestamp, event->id);
|
2015-06-10 12:51:20 -07:00
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-31 05:40:18 -07:00
|
|
|
printf("Event: time: %lld, type: %s", event->timestamp,
|
|
|
|
iio_chan_type_name_spec[type]);
|
2012-02-13 02:25:34 -07:00
|
|
|
|
2015-05-31 05:40:18 -07:00
|
|
|
if (mod != IIO_NO_MOD)
|
|
|
|
printf("(%s)", iio_modifier_names[mod]);
|
2012-02-13 02:25:34 -07:00
|
|
|
|
2015-05-31 05:40:18 -07:00
|
|
|
if (chan >= 0) {
|
|
|
|
printf(", channel: %d", chan);
|
|
|
|
if (diff && chan2 >= 0)
|
|
|
|
printf("-%d", chan2);
|
|
|
|
}
|
2012-02-13 02:25:34 -07:00
|
|
|
|
2015-05-31 05:40:18 -07:00
|
|
|
printf(", evtype: %s", iio_ev_type_text[ev_type]);
|
iio: event_monitor: Add support for new channel types
We have the following testing scenario:
$ insmod iio_dummy_evgen.ko
$ insmod iio_dummy.ko
./iio_event_monitor /dev/iio:device0
Event: time: 1412786467971335337, type: activity(running), channel: 0,
evtype: thresh, direction: rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0,
evtype: thresh, direction: falling
Event: time: 1412764319184761765, type: steps, channel: 0, evtype: instance
$ echo 1 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 2 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 3 > /sys/bus/iio/devices/iio_evgen/poke_ev0
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-11-10 05:45:35 -07:00
|
|
|
|
|
|
|
if (dir != IIO_EV_DIR_NONE)
|
|
|
|
printf(", direction: %s", iio_ev_dir_text[dir]);
|
2015-06-10 12:51:20 -07:00
|
|
|
|
iio: event_monitor: Add support for new channel types
We have the following testing scenario:
$ insmod iio_dummy_evgen.ko
$ insmod iio_dummy.ko
./iio_event_monitor /dev/iio:device0
Event: time: 1412786467971335337, type: activity(running), channel: 0,
evtype: thresh, direction: rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0,
evtype: thresh, direction: falling
Event: time: 1412764319184761765, type: steps, channel: 0, evtype: instance
$ echo 1 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 2 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 3 > /sys/bus/iio/devices/iio_evgen/poke_ev0
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-11-10 05:45:35 -07:00
|
|
|
printf("\n");
|
2021-12-08 14:48:08 -07:00
|
|
|
fflush(stdout);
|
2012-02-13 02:25:34 -07:00
|
|
|
}
|
|
|
|
|
2021-03-19 06:53:01 -07:00
|
|
|
/* Enable or disable events in sysfs if the knob is available */
|
|
|
|
static void enable_events(char *dev_dir, int enable)
|
|
|
|
{
|
|
|
|
const struct dirent *ent;
|
|
|
|
char evdir[256];
|
|
|
|
int ret;
|
|
|
|
DIR *dp;
|
|
|
|
|
|
|
|
snprintf(evdir, sizeof(evdir), FORMAT_EVENTS_DIR, dev_dir);
|
|
|
|
evdir[sizeof(evdir)-1] = '\0';
|
|
|
|
|
|
|
|
dp = opendir(evdir);
|
|
|
|
if (!dp) {
|
|
|
|
fprintf(stderr, "Enabling/disabling events: can't open %s\n",
|
|
|
|
evdir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ent = readdir(dp), ent) {
|
|
|
|
if (iioutils_check_suffix(ent->d_name, "_en")) {
|
|
|
|
printf("%sabling: %s\n",
|
|
|
|
enable ? "En" : "Dis",
|
|
|
|
ent->d_name);
|
|
|
|
ret = write_sysfs_int(ent->d_name, evdir,
|
|
|
|
enable);
|
|
|
|
if (ret < 0)
|
|
|
|
fprintf(stderr, "Failed to enable/disable %s\n",
|
|
|
|
ent->d_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closedir(dp) == -1) {
|
|
|
|
perror("Enabling/disabling channels: "
|
|
|
|
"Failed to close directory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct iio_event_data event;
|
|
|
|
const char *device_name;
|
2021-03-19 06:53:01 -07:00
|
|
|
char *dev_dir_name = NULL;
|
2012-02-13 02:25:34 -07:00
|
|
|
char *chrdev_name;
|
|
|
|
int ret;
|
|
|
|
int dev_num;
|
|
|
|
int fd, event_fd;
|
2021-03-19 06:53:01 -07:00
|
|
|
bool all_events = false;
|
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
device_name = argv[1];
|
|
|
|
} else if (argc == 3) {
|
|
|
|
device_name = argv[2];
|
|
|
|
if (!strcmp(argv[1], "-a"))
|
|
|
|
all_events = true;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: iio_event_monitor [options] <device_name>\n"
|
|
|
|
"Listen and display events from IIO devices\n"
|
|
|
|
" -a Auto-activate all available events\n");
|
2012-02-13 02:25:34 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_num = find_type_by_name(device_name, "iio:device");
|
|
|
|
if (dev_num >= 0) {
|
|
|
|
printf("Found IIO device with name %s with device number %d\n",
|
2015-06-10 12:51:20 -07:00
|
|
|
device_name, dev_num);
|
2012-02-13 02:25:34 -07:00
|
|
|
ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
|
2015-07-13 06:17:47 -07:00
|
|
|
if (ret < 0)
|
2015-05-31 05:40:17 -07:00
|
|
|
return -ENOMEM;
|
2021-03-19 06:53:01 -07:00
|
|
|
/* Look up sysfs dir as well if we can */
|
|
|
|
ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
|
|
|
|
if (ret < 0)
|
|
|
|
return -ENOMEM;
|
2012-02-13 02:25:34 -07:00
|
|
|
} else {
|
2015-06-10 12:51:20 -07:00
|
|
|
/*
|
|
|
|
* If we can't find an IIO device by name assume device_name is
|
|
|
|
* an IIO chrdev
|
|
|
|
*/
|
2012-02-13 02:25:34 -07:00
|
|
|
chrdev_name = strdup(device_name);
|
2015-05-31 05:40:02 -07:00
|
|
|
if (!chrdev_name)
|
|
|
|
return -ENOMEM;
|
2012-02-13 02:25:34 -07:00
|
|
|
}
|
|
|
|
|
2021-03-19 06:53:01 -07:00
|
|
|
if (all_events && dev_dir_name)
|
|
|
|
enable_events(dev_dir_name, 1);
|
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
fd = open(chrdev_name, 0);
|
|
|
|
if (fd == -1) {
|
|
|
|
ret = -errno;
|
2015-07-17 08:43:42 -07:00
|
|
|
fprintf(stderr, "Failed to open %s\n", chrdev_name);
|
2012-02-13 02:25:34 -07:00
|
|
|
goto error_free_chrdev_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
|
|
|
|
if (ret == -1 || event_fd == -1) {
|
|
|
|
ret = -errno;
|
2015-08-11 05:34:38 -07:00
|
|
|
if (ret == -ENODEV)
|
|
|
|
fprintf(stderr,
|
|
|
|
"This device does not support events\n");
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Failed to retrieve event fd\n");
|
2015-05-31 05:39:49 -07:00
|
|
|
if (close(fd) == -1)
|
|
|
|
perror("Failed to close character device file");
|
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
goto error_free_chrdev_name;
|
|
|
|
}
|
|
|
|
|
2015-05-31 05:40:05 -07:00
|
|
|
if (close(fd) == -1) {
|
|
|
|
ret = -errno;
|
|
|
|
goto error_free_chrdev_name;
|
|
|
|
}
|
2015-05-31 05:39:49 -07:00
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
while (true) {
|
|
|
|
ret = read(event_fd, &event, sizeof(event));
|
|
|
|
if (ret == -1) {
|
|
|
|
if (errno == EAGAIN) {
|
2015-07-17 08:43:42 -07:00
|
|
|
fprintf(stderr, "nothing available\n");
|
2012-02-13 02:25:34 -07:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
ret = -errno;
|
2015-05-31 05:39:48 -07:00
|
|
|
perror("Failed to read event from device");
|
2012-02-13 02:25:34 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-10 12:51:19 -07:00
|
|
|
if (ret != sizeof(event)) {
|
2015-07-17 08:43:42 -07:00
|
|
|
fprintf(stderr, "Reading event failed!\n");
|
2015-06-10 12:51:19 -07:00
|
|
|
ret = -EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
print_event(&event);
|
|
|
|
}
|
|
|
|
|
2015-05-31 05:40:05 -07:00
|
|
|
if (close(event_fd) == -1)
|
|
|
|
perror("Failed to close event file");
|
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
error_free_chrdev_name:
|
2021-03-19 06:53:01 -07:00
|
|
|
/* Disable events after use */
|
|
|
|
if (all_events && dev_dir_name)
|
|
|
|
enable_events(dev_dir_name, 0);
|
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
free(chrdev_name);
|
2015-05-31 05:40:17 -07:00
|
|
|
|
2012-02-13 02:25:34 -07:00
|
|
|
return ret;
|
|
|
|
}
|