[sensor] fixed sensor cmd delay time

This commit is contained in:
luhuadong 2020-07-08 22:53:02 +08:00
parent a6d7dc73ed
commit cc15a1b59c
1 changed files with 10 additions and 3 deletions

View File

@ -226,6 +226,7 @@ static void sensor_polling(int argc, char **argv)
rt_sensor_t sensor; rt_sensor_t sensor;
struct rt_sensor_data data; struct rt_sensor_data data;
rt_size_t res, i; rt_size_t res, i;
rt_int32_t delay;
dev = rt_device_find(argv[1]); dev = rt_device_find(argv[1]);
if (dev == RT_NULL) if (dev == RT_NULL)
@ -237,6 +238,7 @@ static void sensor_polling(int argc, char **argv)
num = atoi(argv[2]); num = atoi(argv[2]);
sensor = (rt_sensor_t)dev; sensor = (rt_sensor_t)dev;
delay = sensor->info.period_min > 100 ? sensor->info.period_min : 100;
if (rt_device_open(dev, RT_DEVICE_FLAG_RDWR) != RT_EOK) if (rt_device_open(dev, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{ {
@ -256,7 +258,7 @@ static void sensor_polling(int argc, char **argv)
{ {
sensor_show_data(i, sensor, &data); sensor_show_data(i, sensor, &data);
} }
rt_thread_mdelay(100); rt_thread_mdelay(delay);
} }
rt_device_close(dev); rt_device_close(dev);
} }
@ -268,7 +270,9 @@ static void sensor(int argc, char **argv)
{ {
static rt_device_t dev = RT_NULL; static rt_device_t dev = RT_NULL;
struct rt_sensor_data data; struct rt_sensor_data data;
rt_sensor_t sensor;
rt_size_t res, i; rt_size_t res, i;
rt_int32_t delay;
/* If the number of arguments less than 2 */ /* If the number of arguments less than 2 */
if (argc < 2) if (argc < 2)
@ -410,6 +414,9 @@ static void sensor(int argc, char **argv)
num = atoi(argv[2]); num = atoi(argv[2]);
} }
sensor = (rt_sensor_t)dev;
delay = sensor->info.period_min > 100 ? sensor->info.period_min : 100;
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
res = rt_device_read(dev, 0, &data, 1); res = rt_device_read(dev, 0, &data, 1);
@ -419,9 +426,9 @@ static void sensor(int argc, char **argv)
} }
else else
{ {
sensor_show_data(i, (rt_sensor_t)dev, &data); sensor_show_data(i, sensor, &data);
} }
rt_thread_mdelay(100); rt_thread_mdelay(delay);
} }
} }
else if (argc == 3) else if (argc == 3)