From 7c4e70b3b3872afc3350f798170a7d885a997873 Mon Sep 17 00:00:00 2001 From: luhuadong Date: Mon, 16 Mar 2020 11:03:32 +0800 Subject: [PATCH] [Sensor] Add user-commands range limitation --- components/drivers/sensors/sensor.c | 11 +++++++++-- components/drivers/sensors/sensor.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index ce593e17bb..08127bc292 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -354,8 +354,15 @@ static rt_err_t rt_sensor_control(rt_device_t dev, int cmd, void *args) break; default: - /* Custom commands */ - result = sensor->ops->control(sensor, cmd, args); + if (cmd > RT_SENSOR_CTRL_USER_CMD_START) + { + /* Custom commands */ + result = sensor->ops->control(sensor, cmd, args); + } + else + { + result = -RT_ERROR; + } break; } diff --git a/components/drivers/sensors/sensor.h b/components/drivers/sensors/sensor.h index 0dae3d66f5..a0eaaae9ea 100755 --- a/components/drivers/sensors/sensor.h +++ b/components/drivers/sensors/sensor.h @@ -111,6 +111,8 @@ extern "C" { #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 */ #define RT_SENSOR_CTRL_SELF_TEST (6) /* Take a self test */ +#define RT_SENSOR_CTRL_USER_CMD_START 0x100 /* User commands should be greater than 0x100 */ + struct rt_sensor_info { rt_uint8_t type; /* The sensor type */