示例#1
0
static int max1363_write_thresh(struct iio_dev *indio_dev,
				u64 event_code,
				int val)
{
	struct max1363_state *st = iio_priv(indio_dev);
	/* make it handle signed correctly as well */
	switch (st->chip_info->bits) {
	case 10:
		if (val > 0x3FF)
			return -EINVAL;
		break;
	case 12:
		if (val > 0xFFF)
			return -EINVAL;
		break;
	}

	switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
	case IIO_EV_DIR_FALLING:
		st->thresh_low[IIO_EVENT_CODE_EXTRACT_NUM(event_code)] = val;
		break;
	case IIO_EV_DIR_RISING:
		st->thresh_high[IIO_EVENT_CODE_EXTRACT_NUM(event_code)] = val;
		break;
	}

	return 0;
}
示例#2
0
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)) {
        printf("Unknown event: time: %lld, id: %llx\n",
               event->timestamp, event->id);
        return;
    }

    printf("Event: time: %lld, type: %s", event->timestamp,
           iio_chan_type_name_spec[type]);

    if (mod != IIO_NO_MOD)
        printf("(%s)", iio_modifier_names[mod]);

    if (chan >= 0) {
        printf(", channel: %d", chan);
        if (diff && chan2 >= 0)
            printf("-%d", chan2);
    }

    printf(", evtype: %s", iio_ev_type_text[ev_type]);

    if (dir != IIO_EV_DIR_NONE)
        printf(", direction: %s", iio_ev_dir_text[dir]);
    printf("\n");
}
/**
 * iio_simple_dummy_write_event_config() - set whether event is enabled
 * @indio_dev: the device instance data
 * @event_code: event code of event being enabled/disabled
 * @state: whether to enable or disable the device.
 *
 * This function would normally set the relevant registers on the devices
 * so that it generates the specified event. Here it just sets up a cached
 * value.
 */
int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
					u64 event_code,
					int state)
{
	struct iio_dummy_state *st = iio_priv(indio_dev);

	/*
	 *  Deliberately over the top code splitting to illustrate
	 * how this is done when multiple events exist.
	 */
	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
	case IIO_VOLTAGE:
		switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
		case IIO_EV_TYPE_THRESH:
			if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
			    IIO_EV_DIR_RISING)
				st->event_en = state;
			else
				return -EINVAL;
			break;
		default:
			return -EINVAL;
		}
	default:
		return -EINVAL;
	}

	return 0;
}
示例#4
0
static int max1363_read_thresh(struct iio_dev *indio_dev,
			       u64 event_code,
			       int *val)
{
	struct max1363_state *st = iio_priv(indio_dev);
	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING)
		*val = st->thresh_low[IIO_EVENT_CODE_EXTRACT_NUM(event_code)];
	else
		*val = st->thresh_high[IIO_EVENT_CODE_EXTRACT_NUM(event_code)];
	return 0;
}
示例#5
0
文件: apds9300.c 项目: 03199618/linux
static int apds9300_write_thresh(struct iio_dev *indio_dev, u64 event_code,
		int val)
{
	struct apds9300_data *data = iio_priv(indio_dev);
	int ret;

	mutex_lock(&data->mutex);
	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)
		ret = apds9300_set_thresh_hi(data, val);
	else
		ret = apds9300_set_thresh_low(data, val);
	mutex_unlock(&data->mutex);

	return ret;
}
示例#6
0
文件: apds9300.c 项目: 03199618/linux
static int apds9300_read_thresh(struct iio_dev *indio_dev, u64 event_code,
		int *val)
{
	struct apds9300_data *data = iio_priv(indio_dev);

	switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
	case IIO_EV_DIR_RISING:
		*val = data->thresh_hi;
		break;
	case IIO_EV_DIR_FALLING:
		*val = data->thresh_low;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}
示例#7
0
文件: iio.c 项目: fboudra/mraa
mraa_result_t
mraa_iio_event_extract_event(struct iio_event_data* event,
                             int* chan_type,
                             int* modifier,
                             int* type,
                             int* direction,
                             int* channel,
                             int* channel2,
                             int* different)
{
    *chan_type = IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event->id);
    *modifier = IIO_EVENT_CODE_EXTRACT_MODIFIER(event->id);
    *type = IIO_EVENT_CODE_EXTRACT_TYPE(event->id);
    *direction = IIO_EVENT_CODE_EXTRACT_DIR(event->id);
    *channel = IIO_EVENT_CODE_EXTRACT_CHAN(event->id);
    *channel2 = IIO_EVENT_CODE_EXTRACT_CHAN2(event->id);
    *different = IIO_EVENT_CODE_EXTRACT_DIFF(event->id);
    return MRAA_SUCCESS;
}
示例#8
0
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:
    case IIO_ALTVOLTAGE:
    case IIO_CCT:
    case IIO_PRESSURE:
    case IIO_HUMIDITYRELATIVE:
    case IIO_ACTIVITY:
    case IIO_STEPS:
        break;
    default:
        return false;
    }

    switch (mod) {
    case IIO_NO_MOD:
    case IIO_MOD_X:
    case IIO_MOD_Y:
    case IIO_MOD_Z:
    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:
    case IIO_MOD_LIGHT_BOTH:
    case IIO_MOD_LIGHT_IR:
    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:
    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:
    case IIO_MOD_RUNNING:
    case IIO_MOD_JOGGING:
    case IIO_MOD_WALKING:
    case IIO_MOD_STILL:
        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:
    case IIO_EV_TYPE_CHANGE:
        break;
    default:
        return false;
    }

    switch (dir) {
    case IIO_EV_DIR_EITHER:
    case IIO_EV_DIR_RISING:
    case IIO_EV_DIR_FALLING:
    case IIO_EV_DIR_NONE:
        break;
    default:
        return false;
    }

    return true;
}
示例#9
0
static void * thread_event_handler(void* args)
{
	int fd, event_fd;
	char device_file[MAX_PATH_SIZE];
	struct iio_event_data event;
	enum iio_event_type ev_type;
	enum iio_chan_type ch_type;
	enum iio_event_direction ev_dir;
	int channel_number;

	int ret = 0;

	if (sprintf(device_file, "/dev/%s", gNodeName) < 0)
	{
		perror("Error:Out of Memory");
		ret = 1;
		goto ERR_OUT;
	}

	if ((fd = open(device_file,O_RDONLY)) == -1)
	{
		perror("Failed to open device file");
		ret = 2;
		goto ERR_OUT;
	}

	//get the event_fd

	if (ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd) == -1)
	{
		perror("IOCTL failed on device file");
		ret = 3;
		goto ERR_OUT;
	}

	close (fd);

	if(event_fd == -1)
	{
		perror("Couldn't obtain event file descriptor\n");
		ret = 3;
		goto ERR_OUT;
	}

	while (gExitNow == false)
	{
		ret=read(event_fd, &event, sizeof(event));
		if(ret == -1)
		{
			if(errno == EAGAIN)
			{
				printf("Nothing available\n");
				continue;
			}
			else
			{
				perror("Failed to read event from device");
				ret = -errno;
				break;
			}
		}
		// Parsing event
		ev_type = IIO_EVENT_CODE_EXTRACT_TYPE(event.id);
		ch_type = IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event.id);
		ev_dir = IIO_EVENT_CODE_EXTRACT_DIR(event.id);
		channel_number = IIO_EVENT_CODE_EXTRACT_CHAN(event.id);

		do_event_action(ev_type,ch_type,ev_dir,channel_number);
	}

	close (event_fd);

	return NULL;

ERR_OUT:
	exit(ret);
}
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:
		break;
	default:
		return false;
	}

	switch (mod) {
	case IIO_NO_MOD:
	case IIO_MOD_X:
	case IIO_MOD_Y:
	case IIO_MOD_Z:
	case IIO_MOD_LIGHT_BOTH:
	case IIO_MOD_LIGHT_IR:
		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:
		break;
	default:
		return false;
	}

	switch (dir) {
	case IIO_EV_DIR_EITHER:
	case IIO_EV_DIR_RISING:
	case IIO_EV_DIR_FALLING:
		break;
	default:
		return false;
	}

	return true;
}