Lines Matching +full:channel +full:- +full:count
4 * SPDX-License-Identifier: Apache-2.0
24 "Get sensor data. Channel names are optional. All channels are read " \
26 "<device_name> <channel name 0> .. <channel name N>"
34 "Get the sensor's channel attribute. Syntax:\n" \
39 "Set the sensor's channel attribute.\n" \
140 uint32_t count; member
152 if (sensor->dev == dev) { in device_is_sensor()
169 return -1; in find_sensor_trigger_device()
225 return -1; in sensor_trigger_name_lookup()
240 /* Crate a single common config for one-shot reading */
246 .count = 0,
254 static int parse_named_int(const char *name, const char *heystack[], size_t count) in parse_named_int() argument
259 /* Attempt to parse channel name as a number first */ in parse_named_int()
266 /* Channel name is not a number, look it up */ in parse_named_int()
267 for (i = 0; i < count; i++) { in parse_named_int()
273 return -ENOTSUP; in parse_named_int()
278 const bool is_negative = val_str[0] == '-'; in parse_sensor_value()
287 return -EINVAL; in parse_sensor_value()
290 return -EINVAL; in parse_sensor_value()
292 out->val1 = (int32_t)value; in parse_sensor_value()
301 return -EINVAL; in parse_sensor_value()
307 return -EINVAL; in parse_sensor_value()
309 out->val2 = (int32_t)value; in parse_sensor_value()
311 out->val2 *= -1; in parse_sensor_value()
323 int count; in sensor_shell_processing_callback() member
333 shell_error(ctx->sh, "Read failed"); in sensor_shell_processing_callback()
337 rc = sensor_get_decoder(ctx->dev, &decoder); in sensor_shell_processing_callback()
339 shell_error(ctx->sh, "Failed to get decoder for '%s'", ctx->dev->name); in sensor_shell_processing_callback()
343 for (int trigger = 0; decoder->has_trigger != NULL && trigger < SENSOR_TRIG_COMMON_COUNT; in sensor_shell_processing_callback()
345 if (!decoder->has_trigger(buf, trigger)) { in sensor_shell_processing_callback()
348 shell_info(ctx->sh, "Trigger (%d / %s) detected", trigger, in sensor_shell_processing_callback()
362 /* Channels with multi-axis equivalents are skipped */ in sensor_shell_processing_callback()
379 rc = decoder->get_size_info(ch, &base_size, &frame_size); in sensor_shell_processing_callback()
381 LOG_DBG("skipping unsupported channel %s:%d", in sensor_shell_processing_callback()
383 /* Channel not supported, skipping */ in sensor_shell_processing_callback()
388 shell_error(ctx->sh, in sensor_shell_processing_callback()
389 "Channel (type %d, idx %d) requires %zu bytes to decode, but " in sensor_shell_processing_callback()
396 while (decoder->get_frame_count(buf, ch, &frame_count) == 0) { in sensor_shell_processing_callback()
397 LOG_DBG("decoding %d frames from channel %s:%d", in sensor_shell_processing_callback()
401 while (decoder->decode(buf, ch, &fit, 1, decoded_buffer) > 0) { in sensor_shell_processing_callback()
410 if (accumulator_buffer.count == 0) { in sensor_shell_processing_callback()
412 data->header.base_timestamp_ns; in sensor_shell_processing_callback()
414 accumulator_buffer.count++; in sensor_shell_processing_callback()
415 accumulator_buffer.shift = data->shift; in sensor_shell_processing_callback()
417 data->readings[0].timestamp_delta; in sensor_shell_processing_callback()
418 accumulator_buffer.values[0] += data->readings[0].values[0]; in sensor_shell_processing_callback()
419 accumulator_buffer.values[1] += data->readings[0].values[1]; in sensor_shell_processing_callback()
420 accumulator_buffer.values[2] += data->readings[0].values[2]; in sensor_shell_processing_callback()
427 if (accumulator_buffer.count == 0) { in sensor_shell_processing_callback()
429 data->header.base_timestamp_ns; in sensor_shell_processing_callback()
431 accumulator_buffer.count++; in sensor_shell_processing_callback()
433 data->readings[0].timestamp_delta; in sensor_shell_processing_callback()
434 accumulator_buffer.values[0] += data->readings[0].is_near; in sensor_shell_processing_callback()
441 if (accumulator_buffer.count == 0) { in sensor_shell_processing_callback()
443 data->header.base_timestamp_ns; in sensor_shell_processing_callback()
445 accumulator_buffer.count++; in sensor_shell_processing_callback()
446 accumulator_buffer.shift = data->shift; in sensor_shell_processing_callback()
448 data->readings[0].timestamp_delta; in sensor_shell_processing_callback()
449 accumulator_buffer.values[0] += data->readings[0].value; in sensor_shell_processing_callback()
464 data->header.base_timestamp_ns = in sensor_shell_processing_callback()
466 data->header.reading_count = 1; in sensor_shell_processing_callback()
467 data->shift = accumulator_buffer.shift; in sensor_shell_processing_callback()
468 data->readings[0].timestamp_delta = in sensor_shell_processing_callback()
470 accumulator_buffer.count); in sensor_shell_processing_callback()
471 data->readings[0].values[0] = (q31_t)(accumulator_buffer.values[0] / in sensor_shell_processing_callback()
472 accumulator_buffer.count); in sensor_shell_processing_callback()
473 data->readings[0].values[1] = (q31_t)(accumulator_buffer.values[1] / in sensor_shell_processing_callback()
474 accumulator_buffer.count); in sensor_shell_processing_callback()
475 data->readings[0].values[2] = (q31_t)(accumulator_buffer.values[2] / in sensor_shell_processing_callback()
476 accumulator_buffer.count); in sensor_shell_processing_callback()
477 shell_info(ctx->sh, in sensor_shell_processing_callback()
478 "channel type=%d(%s) index=%d shift=%d num_samples=%d " in sensor_shell_processing_callback()
481 ch.chan_idx, data->shift, accumulator_buffer.count, in sensor_shell_processing_callback()
489 data->header.base_timestamp_ns = in sensor_shell_processing_callback()
491 data->header.reading_count = 1; in sensor_shell_processing_callback()
492 data->readings[0].timestamp_delta = in sensor_shell_processing_callback()
494 accumulator_buffer.count); in sensor_shell_processing_callback()
495 data->readings[0].is_near = in sensor_shell_processing_callback()
496 accumulator_buffer.values[0] / accumulator_buffer.count; in sensor_shell_processing_callback()
498 shell_info(ctx->sh, in sensor_shell_processing_callback()
499 "channel type=%d(%s) index=%d num_samples=%d " in sensor_shell_processing_callback()
502 ch.chan_idx, accumulator_buffer.count, in sensor_shell_processing_callback()
510 data->header.base_timestamp_ns = in sensor_shell_processing_callback()
512 data->header.reading_count = 1; in sensor_shell_processing_callback()
513 data->shift = accumulator_buffer.shift; in sensor_shell_processing_callback()
514 data->readings[0].timestamp_delta = in sensor_shell_processing_callback()
516 accumulator_buffer.count); in sensor_shell_processing_callback()
517 data->readings[0].value = (q31_t)(accumulator_buffer.values[0] / in sensor_shell_processing_callback()
518 accumulator_buffer.count); in sensor_shell_processing_callback()
520 shell_info(ctx->sh, in sensor_shell_processing_callback()
521 "channel type=%d(%s) index=%d shift=%d num_samples=%d " in sensor_shell_processing_callback()
528 data->shift, accumulator_buffer.count, in sensor_shell_processing_callback()
542 int count = 0; in cmd_get_sensor() local
555 return -ENODEV; in cmd_get_sensor()
561 return -ENODEV; in cmd_get_sensor()
565 /* read all channel types */ in cmd_get_sensor()
570 iodev_sensor_shell_channels[count++] = (struct sensor_chan_spec){i, 0}; in cmd_get_sensor()
579 shell_error(sh, "Failed to read channel (%s)", argv[i]); in cmd_get_sensor()
582 iodev_sensor_shell_channels[count++] = in cmd_get_sensor()
587 if (count == 0) { in cmd_get_sensor()
590 return -EINVAL; in cmd_get_sensor()
593 iodev_sensor_shell_read_config.count = count; in cmd_get_sensor()
623 return -ENODEV; in cmd_sensor_attr_set()
629 return -ENODEV; in cmd_sensor_attr_set()
633 int channel = parse_named_int(argv[i], sensor_channel_name, in cmd_sensor_attr_set() local
639 if (channel < 0) { in cmd_sensor_attr_set()
640 shell_error(shell_ptr, "Channel '%s' unknown", argv[i]); in cmd_sensor_attr_set()
641 return -EINVAL; in cmd_sensor_attr_set()
645 return -EINVAL; in cmd_sensor_attr_set()
649 return -EINVAL; in cmd_sensor_attr_set()
652 rc = sensor_attr_set(dev, channel, attr, &value); in cmd_sensor_attr_set()
654 shell_error(shell_ptr, "Failed to set channel(%s) attribute(%s): %d", in cmd_sensor_attr_set()
655 sensor_channel_name[channel], sensor_attribute_name[attr], rc); in cmd_sensor_attr_set()
658 shell_info(shell_ptr, "%s channel=%s, attr=%s set to value=%s", dev->name, in cmd_sensor_attr_set()
659 sensor_channel_name[channel], sensor_attribute_name[attr], argv[i + 2]); in cmd_sensor_attr_set()
668 int channel = in cmd_sensor_attr_get_handler() local
675 if (channel < 0) { in cmd_sensor_attr_get_handler()
676 shell_error(shell_ptr, "Channel '%s' unknown", channel_name); in cmd_sensor_attr_get_handler()
684 rc = sensor_attr_get(dev, channel, attr, &value); in cmd_sensor_attr_get_handler()
687 if (rc == -EINVAL && !print_missing_attribute) { in cmd_sensor_attr_get_handler()
690 shell_error(shell_ptr, "Failed to get channel(%s) attribute(%s): %d", in cmd_sensor_attr_get_handler()
691 sensor_channel_name[channel], sensor_attribute_name[attr], rc); in cmd_sensor_attr_get_handler()
695 shell_info(shell_ptr, "%s(channel=%s, attr=%s) value=%.6f", dev->name, in cmd_sensor_attr_get_handler()
696 sensor_channel_name[channel], sensor_attribute_name[attr], in cmd_sensor_attr_get_handler()
707 return -ENODEV; in cmd_sensor_attr_get()
713 return -ENODEV; in cmd_sensor_attr_get()
746 entry->syntax = NULL; in channel_name_get()
747 entry->handler = NULL; in channel_name_get()
748 entry->help = NULL; in channel_name_get()
750 entry->subcmd = &dsub_channel_name; in channel_name_get()
752 entry->subcmd = &dsub_attribute_name; in channel_name_get()
754 entry->subcmd = NULL; in channel_name_get()
760 entry->syntax = sensor_channel_name[i]; in channel_name_get()
772 entry->syntax = NULL; in attribute_name_get()
773 entry->handler = NULL; in attribute_name_get()
774 entry->help = NULL; in attribute_name_get()
775 entry->subcmd = &dsub_channel_name; in attribute_name_get()
780 entry->syntax = sensor_attribute_name[i]; in attribute_name_get()
793 entry->syntax = NULL; in trigger_opt_get_for_stream()
794 entry->handler = NULL; in trigger_opt_get_for_stream()
795 entry->help = NULL; in trigger_opt_get_for_stream()
796 entry->subcmd = NULL; in trigger_opt_get_for_stream()
800 entry->syntax = "incl"; in trigger_opt_get_for_stream()
803 entry->syntax = "drop"; in trigger_opt_get_for_stream()
806 entry->syntax = "nop"; in trigger_opt_get_for_stream()
818 entry->syntax = NULL; in trigger_name_get_for_stream()
819 entry->handler = NULL; in trigger_name_get_for_stream()
820 entry->help = NULL; in trigger_name_get_for_stream()
821 entry->subcmd = &dsub_trigger_opt_get_for_stream; in trigger_name_get_for_stream()
826 entry->syntax = sensor_trigger_table[i].name; in trigger_name_get_for_stream()
836 entry->syntax = NULL; in stream_on_off()
837 entry->handler = NULL; in stream_on_off()
838 entry->help = NULL; in stream_on_off()
841 entry->syntax = "on"; in stream_on_off()
842 entry->subcmd = &dsub_trigger_name_for_stream; in stream_on_off()
844 entry->syntax = "off"; in stream_on_off()
845 entry->subcmd = NULL; in stream_on_off()
859 entry->syntax = (dev != NULL) ? dev->name : NULL; in device_name_get()
860 entry->handler = NULL; in device_name_get()
861 entry->help = NULL; in device_name_get()
862 entry->subcmd = &dsub_channel_name; in device_name_get()
870 entry->syntax = (dev != NULL) ? dev->name : NULL; in device_name_get_for_attr()
871 entry->handler = NULL; in device_name_get_for_attr()
872 entry->help = NULL; in device_name_get_for_attr()
873 entry->subcmd = &dsub_channel_name; in device_name_get_for_attr()
881 entry->syntax = NULL; in trigger_name_get()
882 entry->handler = NULL; in trigger_name_get()
883 entry->help = NULL; in trigger_name_get()
884 entry->subcmd = NULL; in trigger_name_get()
889 entry->syntax = sensor_trigger_table[i].name; in trigger_name_get()
901 entry->handler = NULL; in trigger_on_off_get()
902 entry->help = NULL; in trigger_on_off_get()
903 entry->subcmd = &dsub_trigger_name; in trigger_on_off_get()
907 entry->syntax = "on"; in trigger_on_off_get()
910 entry->syntax = "off"; in trigger_on_off_get()
913 entry->syntax = NULL; in trigger_on_off_get()
924 entry->syntax = (dev != NULL) ? dev->name : NULL; in device_name_get_for_trigger()
925 entry->handler = NULL; in device_name_get_for_trigger()
926 entry->help = NULL; in device_name_get_for_trigger()
927 entry->subcmd = &dsub_trigger_onoff; in device_name_get_for_trigger()
937 entry->syntax = (dev != NULL) ? dev->name : NULL; in device_name_get_for_stream()
938 entry->handler = NULL; in device_name_get_for_stream()
939 entry->help = NULL; in device_name_get_for_stream()
940 entry->subcmd = &dsub_stream_on_off; in device_name_get_for_stream()
956 sensor->dev->name, sensor->vendor ? sensor->vendor : null_str, in cmd_get_sensor_info()
957 sensor->model ? sensor->model : null_str, in cmd_get_sensor_info()
958 sensor->friendly_name ? sensor->friendly_name : null_str); in cmd_get_sensor_info()
962 return -EINVAL; in cmd_get_sensor_info()
981 sensor_name = sensor_trigger_devices[sensor_idx]->name; in data_ready_trigger_handler()
983 sensor_name_len_before_at = strchr(sensor_name, '@') - sensor_name; in data_ready_trigger_handler()
1005 if (rc == -ENOTSUP) { in data_ready_trigger_handler()
1007 * Stop reading this channel if the driver told us in data_ready_trigger_handler()
1021 if (stats[i].count++ == 0) { in data_ready_trigger_handler()
1025 int64_t micro_value = stats[i].accumulator / stats[i].count; in data_ready_trigger_handler()
1028 value.val2 = (int32_t)llabs(micro_value - (value.val1 * 1000000)); in data_ready_trigger_handler()
1032 stats[i].count, in data_ready_trigger_handler()
1036 stats[i].count = 0; in data_ready_trigger_handler()
1050 return -EINVAL; in cmd_trig_sensor()
1057 return -ENODEV; in cmd_trig_sensor()
1064 return -ENOTSUP; in cmd_trig_sensor()
1075 err = -ENOTSUP; in cmd_trig_sensor()
1103 return -EINVAL; in cmd_trig_sensor()
1118 /* clang-format off */
1134 /* clang-format on */