| 551 | } |
| 552 | |
| 553 | static int sensor(int argc, char **argv) |
| 554 | { |
| 555 | static rt_device_t dev = RT_NULL; |
| 556 | struct rt_sensor_data data; |
| 557 | rt_sensor_t sensor; |
| 558 | rt_size_t res, i; |
| 559 | rt_int32_t delay; |
| 560 | |
| 561 | /* If the number of arguments less than 2 */ |
| 562 | if (argc < 2) |
| 563 | { |
| 564 | sensor_cmd_warning_unknown(); |
| 565 | return -RT_ERROR; |
| 566 | } |
| 567 | else if (!rt_strcmp(argv[1], "info")) |
| 568 | { |
| 569 | if (dev == RT_NULL) |
| 570 | { |
| 571 | sensor_cmd_warning_probe(); |
| 572 | return -RT_ERROR; |
| 573 | } |
| 574 | sensor = (rt_sensor_t)dev; |
| 575 | rt_kprintf("name :%s\n", sensor->info.name); |
| 576 | rt_kprintf("type: :%s\n", sensor_get_type_name(&sensor->info)); |
| 577 | rt_kprintf("vendor :%s\n", sensor_get_vendor_name(&sensor->info)); |
| 578 | rt_kprintf("unit :%s\n", sensor_get_unit_name(&sensor->info)); |
| 579 | rt_kprintf("fetch data:%s\n", sensor_get_fetch_mode_name(&sensor->info)); |
| 580 | rt_kprintf("power :%s\n", sensor_get_power_mode_name(&sensor->info)); |
| 581 | rt_kprintf("accuracy :%s\n", sensor_get_accuracy_mode_name(&sensor->info)); |
| 582 | rt_kprintf("range max :%f\n", sensor->info.scale.range_max); |
| 583 | rt_kprintf("range min :%f\n", sensor->info.scale.range_min); |
| 584 | rt_kprintf("resolution:%f\n", sensor->info.accuracy.resolution); |
| 585 | rt_kprintf("error :%f\n", sensor->info.accuracy.error); |
| 586 | rt_kprintf("acquire min:%fms\n", sensor->info.acquire_min); |
| 587 | rt_kprintf("fifo max :%d\n", sensor->info.fifo_max); |
| 588 | rt_kprintf("interface type :%s\n", sensor_get_intf_name(sensor)); |
| 589 | rt_kprintf("interface device :%s\n", sensor->config.intf.dev_name); |
| 590 | } |
| 591 | else if (!rt_strcmp(argv[1], "read")) |
| 592 | { |
| 593 | rt_uint16_t num = 5; |
| 594 | |
| 595 | if (dev == RT_NULL) |
| 596 | { |
| 597 | sensor_cmd_warning_probe(); |
| 598 | return -RT_ERROR; |
| 599 | } |
| 600 | if (argc == 3) |
| 601 | { |
| 602 | num = atoi(argv[2]); |
| 603 | } |
| 604 | |
| 605 | sensor = (rt_sensor_t)dev; |
| 606 | delay = sensor->info.acquire_min > 100 ? sensor->info.acquire_min : 100; |
| 607 | |
| 608 | for (i = 0; i < num; i++) |
| 609 | { |
| 610 | res = rt_device_read(dev, 0, &data, 1); |
nothing calls this directly
no test coverage detected