From cc15a1b59cdc11b9a05816f417b6c9cec165849b Mon Sep 17 00:00:00 2001 From: luhuadong Date: Wed, 8 Jul 2020 22:53:02 +0800 Subject: [PATCH] [sensor] fixed sensor cmd delay time --- components/drivers/sensors/sensor_cmd.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index d46b23f4cf..d74b1a6307 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -226,6 +226,7 @@ static void sensor_polling(int argc, char **argv) rt_sensor_t sensor; struct rt_sensor_data data; rt_size_t res, i; + rt_int32_t delay; dev = rt_device_find(argv[1]); if (dev == RT_NULL) @@ -237,6 +238,7 @@ static void sensor_polling(int argc, char **argv) num = atoi(argv[2]); 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) { @@ -256,7 +258,7 @@ static void sensor_polling(int argc, char **argv) { sensor_show_data(i, sensor, &data); } - rt_thread_mdelay(100); + rt_thread_mdelay(delay); } rt_device_close(dev); } @@ -268,7 +270,9 @@ static void sensor(int argc, char **argv) { static rt_device_t dev = RT_NULL; struct rt_sensor_data data; + rt_sensor_t sensor; rt_size_t res, i; + rt_int32_t delay; /* If the number of arguments less than 2 */ if (argc < 2) @@ -410,6 +414,9 @@ static void sensor(int argc, char **argv) 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++) { res = rt_device_read(dev, 0, &data, 1); @@ -419,9 +426,9 @@ static void sensor(int argc, char **argv) } 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)