Skip to content

Commit beda089

Browse files
authored
Merge pull request #3397 from luhuadong/develop
[Sensor] Support custom commands for rt_sensor_control
2 parents 19a7e5f + 7c4e70b commit beda089

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

components/drivers/sensors/sensor.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2019-01-31 flybreak first version
9+
* 2020-02-22 luhuadong support custom commands
910
*/
1011

1112
#include "sensor.h"
@@ -307,7 +308,7 @@ static rt_err_t rt_sensor_control(rt_device_t dev, int cmd, void *args)
307308
case RT_SENSOR_CTRL_GET_ID:
308309
if (args)
309310
{
310-
sensor->ops->control(sensor, RT_SENSOR_CTRL_GET_ID, args);
311+
result = sensor->ops->control(sensor, RT_SENSOR_CTRL_GET_ID, args);
311312
}
312313
break;
313314
case RT_SENSOR_CTRL_GET_INFO:
@@ -352,7 +353,17 @@ static rt_err_t rt_sensor_control(rt_device_t dev, int cmd, void *args)
352353
result = sensor->ops->control(sensor, RT_SENSOR_CTRL_SELF_TEST, args);
353354
break;
354355
default:
355-
return -RT_ERROR;
356+
357+
if (cmd > RT_SENSOR_CTRL_USER_CMD_START)
358+
{
359+
/* Custom commands */
360+
result = sensor->ops->control(sensor, cmd, args);
361+
}
362+
else
363+
{
364+
result = -RT_ERROR;
365+
}
366+
break;
356367
}
357368

358369
if (sensor->module)

components/drivers/sensors/sensor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ extern "C" {
111111
#define RT_SENSOR_CTRL_SET_POWER (5) /* Set power mode. args type of sensor power mode. ex. RT_SENSOR_POWER_DOWN,RT_SENSOR_POWER_NORMAL */
112112
#define RT_SENSOR_CTRL_SELF_TEST (6) /* Take a self test */
113113

114+
#define RT_SENSOR_CTRL_USER_CMD_START 0x100 /* User commands should be greater than 0x100 */
115+
114116
struct rt_sensor_info
115117
{
116118
rt_uint8_t type; /* The sensor type */

0 commit comments

Comments
 (0)