[sensor_v2] Repair an error occurs when sensor v2 probes a sensor device for the first time
This commit is contained in:
parent
8dc166b16c
commit
57bca1a072
|
@ -550,7 +550,7 @@ static void sensor_cmd_warning_probe(void)
|
||||||
LOG_W("Please probe sensor device first!");
|
LOG_W("Please probe sensor device first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sensor(int argc, char **argv)
|
static int 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;
|
||||||
|
@ -562,14 +562,14 @@ static void sensor(int argc, char **argv)
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_unknown();
|
sensor_cmd_warning_unknown();
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
else if (!rt_strcmp(argv[1], "info"))
|
else if (!rt_strcmp(argv[1], "info"))
|
||||||
{
|
{
|
||||||
if (dev == RT_NULL)
|
if (dev == RT_NULL)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_probe();
|
sensor_cmd_warning_probe();
|
||||||
return ;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
sensor = (rt_sensor_t)dev;
|
sensor = (rt_sensor_t)dev;
|
||||||
rt_kprintf("name :%s\n", sensor->info.name);
|
rt_kprintf("name :%s\n", sensor->info.name);
|
||||||
|
@ -595,7 +595,7 @@ static void sensor(int argc, char **argv)
|
||||||
if (dev == RT_NULL)
|
if (dev == RT_NULL)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_probe();
|
sensor_cmd_warning_probe();
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
if (argc == 3)
|
if (argc == 3)
|
||||||
{
|
{
|
||||||
|
@ -628,7 +628,7 @@ static void sensor(int argc, char **argv)
|
||||||
|
|
||||||
information = rt_object_get_information(RT_Object_Class_Device);
|
information = rt_object_get_information(RT_Object_Class_Device);
|
||||||
if(information == RT_NULL)
|
if(information == RT_NULL)
|
||||||
return;
|
return -RT_ERROR;
|
||||||
|
|
||||||
rt_kprintf("device name sensor name sensor type mode resolution range\n");
|
rt_kprintf("device name sensor name sensor type mode resolution range\n");
|
||||||
rt_kprintf("----------- ------------- ------------------ ---- ---------- ----------\n");
|
rt_kprintf("----------- ------------- ------------------ ---- ---------- ----------\n");
|
||||||
|
@ -655,7 +655,7 @@ static void sensor(int argc, char **argv)
|
||||||
if (dev == RT_NULL)
|
if (dev == RT_NULL)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_probe();
|
sensor_cmd_warning_probe();
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rt_device_control(dev, RT_SENSOR_CTRL_SOFT_RESET, RT_NULL) != RT_EOK)
|
if (rt_device_control(dev, RT_SENSOR_CTRL_SOFT_RESET, RT_NULL) != RT_EOK)
|
||||||
|
@ -671,19 +671,19 @@ static void sensor(int argc, char **argv)
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_unknown();
|
sensor_cmd_warning_unknown();
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_dev = rt_device_find(argv[2]);
|
new_dev = rt_device_find(argv[2]);
|
||||||
if (new_dev == RT_NULL)
|
if (new_dev == RT_NULL)
|
||||||
{
|
{
|
||||||
LOG_E("Can't find device:%s", argv[2]);
|
LOG_E("Can't find device:%s", argv[2]);
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
if (rt_device_open(new_dev, RT_DEVICE_FLAG_RDWR) != RT_EOK)
|
if (rt_device_open(new_dev, RT_DEVICE_FLAG_RDWR) != RT_EOK)
|
||||||
{
|
{
|
||||||
LOG_E("open device failed!");
|
LOG_E("open device failed!");
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
if (rt_device_control(new_dev, RT_SENSOR_CTRL_GET_ID, ®) == RT_EOK)
|
if (rt_device_control(new_dev, RT_SENSOR_CTRL_GET_ID, ®) == RT_EOK)
|
||||||
{
|
{
|
||||||
|
@ -702,7 +702,7 @@ static void sensor(int argc, char **argv)
|
||||||
if (dev == RT_NULL)
|
if (dev == RT_NULL)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_probe();
|
sensor_cmd_warning_probe();
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
sensor = (rt_sensor_t)dev;
|
sensor = (rt_sensor_t)dev;
|
||||||
|
@ -734,7 +734,7 @@ static void sensor(int argc, char **argv)
|
||||||
if (dev == RT_NULL)
|
if (dev == RT_NULL)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_probe();
|
sensor_cmd_warning_probe();
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
sensor = (rt_sensor_t)dev;
|
sensor = (rt_sensor_t)dev;
|
||||||
|
@ -766,7 +766,7 @@ static void sensor(int argc, char **argv)
|
||||||
if (dev == RT_NULL)
|
if (dev == RT_NULL)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_probe();
|
sensor_cmd_warning_probe();
|
||||||
return;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
sensor = (rt_sensor_t)dev;
|
sensor = (rt_sensor_t)dev;
|
||||||
|
@ -795,5 +795,7 @@ static void sensor(int argc, char **argv)
|
||||||
{
|
{
|
||||||
sensor_cmd_warning_unknown();
|
sensor_cmd_warning_unknown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
MSH_CMD_EXPORT(sensor, sensor test function);
|
MSH_CMD_EXPORT(sensor, sensor test function);
|
||||||
|
|
Loading…
Reference in New Issue