Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76519099
rt-thread
提交
b1763e69
R
rt-thread
项目概览
2301_76519099
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
3
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b1763e69
编写于
12月 25, 2022
作者:
mysterywolf
提交者:
mysterywolf
12月 26, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[sensor] add setting power/accuracy/fetch data mode commands
上级
3a7ee557
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
112 addition
and
14 deletion
+112
-14
components/drivers/include/drivers/sensor.h
components/drivers/include/drivers/sensor.h
+3
-3
components/drivers/sensor/sensor.c
components/drivers/sensor/sensor.c
+8
-7
components/drivers/sensor/sensor_cmd.c
components/drivers/sensor/sensor_cmd.c
+101
-4
未找到文件。
components/drivers/include/drivers/sensor.h
浏览文件 @
b1763e69
...
...
@@ -222,11 +222,11 @@ extern "C" {
#define RT_SENSOR_MODE_ACCURACY_HIGH_STR "Accuracy High"
#define RT_SENSOR_MODE_ACCURACY_MEDIUM (2)
#define RT_SENSOR_MODE_ACCURACY_MEDIUM_STR "Accuracy Medium"
#define RT_SENSOR_MODE_ACCURACY_LOW (
4
)
#define RT_SENSOR_MODE_ACCURACY_LOW (
3
)
#define RT_SENSOR_MODE_ACCURACY_LOW_STR "Accuracy Low"
#define RT_SENSOR_MODE_ACCURACY_LOWEST (
5
)
#define RT_SENSOR_MODE_ACCURACY_LOWEST (
4
)
#define RT_SENSOR_MODE_ACCURACY_LOWEST_STR "Accuracy Lowest"
#define RT_SENSOR_MODE_ACCURACY_NOTRUST (
6
)
#define RT_SENSOR_MODE_ACCURACY_NOTRUST (
5
)
#define RT_SENSOR_MODE_ACCURACY_NOTRUST_STR "Accuracy No Trust"
/* Sensor mode: power */
...
...
components/drivers/sensor/sensor.c
浏览文件 @
b1763e69
...
...
@@ -358,7 +358,7 @@ static rt_err_t _sensor_control(rt_device_t dev, int cmd, void *args)
break
;
case
RT_SENSOR_CTRL_SET_ACCURACY_MODE
:
/* Configuration sensor power mode */
mode
=
(
rt_uint32_t
)
args
;
mode
=
(
rt_uint32_t
)
args
&
0x000F
;
if
(
!
(
mode
==
RT_SENSOR_MODE_ACCURACY_HIGHEST
||
mode
==
RT_SENSOR_MODE_ACCURACY_HIGH
||
\
mode
==
RT_SENSOR_MODE_ACCURACY_MEDIUM
||
mode
==
RT_SENSOR_MODE_ACCURACY_LOW
||
\
mode
==
RT_SENSOR_MODE_ACCURACY_LOWEST
||
mode
==
RT_SENSOR_MODE_ACCURACY_NOTRUST
))
...
...
@@ -369,13 +369,13 @@ static rt_err_t _sensor_control(rt_device_t dev, int cmd, void *args)
result
=
local_ctrl
(
sensor
,
RT_SENSOR_CTRL_SET_ACCURACY_MODE
,
args
);
if
(
result
==
RT_EOK
)
{
RT_SENSOR_MODE_SET_ACCURACY
(
sensor
->
info
.
mode
,
(
rt_uint32_t
)
args
&
0x0F
);
RT_SENSOR_MODE_SET_ACCURACY
(
sensor
->
info
.
mode
,
mode
);
LOG_D
(
"set accuracy mode code: %d"
,
RT_SENSOR_MODE_GET_ACCURACY
(
sensor
->
info
.
mode
));
}
break
;
case
RT_SENSOR_CTRL_SET_POWER_MODE
:
/* Configuration sensor power mode */
mode
=
(
rt_uint32_t
)
args
;
mode
=
(
rt_uint32_t
)
args
&
0x000F
;
if
(
!
(
mode
==
RT_SENSOR_MODE_POWER_HIGHEST
||
mode
==
RT_SENSOR_MODE_POWER_HIGH
||
\
mode
==
RT_SENSOR_MODE_POWER_MEDIUM
||
mode
==
RT_SENSOR_MODE_POWER_LOW
||
\
mode
==
RT_SENSOR_MODE_POWER_LOWEST
||
mode
==
RT_SENSOR_MODE_POWER_DOWN
))
...
...
@@ -386,13 +386,13 @@ static rt_err_t _sensor_control(rt_device_t dev, int cmd, void *args)
result
=
local_ctrl
(
sensor
,
RT_SENSOR_CTRL_SET_POWER_MODE
,
args
);
if
(
result
==
RT_EOK
)
{
RT_SENSOR_MODE_SET_POWER
(
sensor
->
info
.
mode
,
(
rt_uint32_t
)
args
&
0x0F
);
RT_SENSOR_MODE_SET_POWER
(
sensor
->
info
.
mode
,
mode
);
LOG_D
(
"set power mode code: %d"
,
RT_SENSOR_MODE_GET_POWER
(
sensor
->
info
.
mode
));
}
break
;
case
RT_SENSOR_CTRL_SET_FETCH_MODE
:
/* Configuration sensor power mode */
mode
=
(
rt_uint32_t
)
args
;
mode
=
(
rt_uint32_t
)
args
&
0x000F
;
if
(
!
(
mode
==
RT_SENSOR_MODE_FETCH_POLLING
||
mode
==
RT_SENSOR_MODE_FETCH_INT
||
\
mode
==
RT_SENSOR_MODE_FETCH_FIFO
))
{
...
...
@@ -402,7 +402,7 @@ static rt_err_t _sensor_control(rt_device_t dev, int cmd, void *args)
result
=
local_ctrl
(
sensor
,
RT_SENSOR_CTRL_SET_FETCH_MODE
,
args
);
if
(
result
==
RT_EOK
)
{
RT_SENSOR_MODE_SET_FETCH
(
sensor
->
info
.
mode
,
(
rt_uint32_t
)
args
&
0x0F
);
RT_SENSOR_MODE_SET_FETCH
(
sensor
->
info
.
mode
,
mode
);
LOG_D
(
"set fetch mode code: %d"
,
RT_SENSOR_MODE_GET_FETCH
(
sensor
->
info
.
mode
));
}
break
;
...
...
@@ -517,9 +517,10 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
LOG_I
(
"sensor[%s] init success"
,
device_name
);
rt_free
(
device_name
);
/* set sensor accuracy and power as the hightest */
/* set sensor accuracy and power as the hightest
, and polling data as default
*/
rt_device_control
(
device
,
RT_SENSOR_CTRL_SET_ACCURACY_MODE
,
RT_SENSOR_MODE_ACCURACY_HIGHEST
);
rt_device_control
(
device
,
RT_SENSOR_CTRL_SET_POWER_MODE
,
RT_SENSOR_MODE_POWER_HIGHEST
);
rt_device_control
(
device
,
RT_SENSOR_CTRL_SET_FETCH_MODE
,
RT_SENSOR_MODE_FETCH_POLLING
);
return
RT_EOK
;
}
components/drivers/sensor/sensor_cmd.c
浏览文件 @
b1763e69
...
...
@@ -541,6 +541,7 @@ static void sensor_cmd_warning_unknown(void)
rt_kprintf
(
" read [num] read [num] times sensor (default 5)
\n
"
);
rt_kprintf
(
" power [mode] set or get power mode
\n
"
);
rt_kprintf
(
" accuracy [mode] set or get accuracy mode
\n
"
);
rt_kprintf
(
" fetch [mode] set or get fetch data mode
\n
"
);
}
static
void
sensor_cmd_warning_probe
(
void
)
...
...
@@ -562,7 +563,7 @@ static void sensor(int argc, char **argv)
sensor_cmd_warning_unknown
();
return
;
}
else
if
(
!
strcmp
(
argv
[
1
],
"info"
))
else
if
(
!
rt_
strcmp
(
argv
[
1
],
"info"
))
{
if
(
dev
==
RT_NULL
)
{
...
...
@@ -586,7 +587,7 @@ static void sensor(int argc, char **argv)
rt_kprintf
(
"interface type :%s
\n
"
,
sensor_get_intf_name
(
sensor
));
rt_kprintf
(
"interface device :%s
\n
"
,
sensor
->
config
.
intf
.
dev_name
);
}
else
if
(
!
strcmp
(
argv
[
1
],
"read"
))
else
if
(
!
rt_
strcmp
(
argv
[
1
],
"read"
))
{
rt_uint16_t
num
=
5
;
...
...
@@ -617,7 +618,7 @@ static void sensor(int argc, char **argv)
rt_thread_mdelay
(
delay
);
}
}
else
if
(
!
strcmp
(
argv
[
1
],
"list"
))
else
if
(
!
rt_
strcmp
(
argv
[
1
],
"list"
))
{
struct
rt_object
*
object
;
struct
rt_list_node
*
node
;
...
...
@@ -648,7 +649,7 @@ static void sensor(int argc, char **argv)
2
,
sensor_dev
->
info
.
scale
.
range_min
,
2
,
sensor_dev
->
info
.
scale
.
range_max
,
5
,
sensor_get_unit_name
(
&
sensor_dev
->
info
));
}
}
else
if
(
!
strcmp
(
argv
[
1
],
"probe"
))
else
if
(
!
rt_
strcmp
(
argv
[
1
],
"probe"
))
{
rt_uint8_t
reg
=
0xFF
;
rt_device_t
new_dev
;
...
...
@@ -680,6 +681,102 @@ static void sensor(int argc, char **argv)
}
dev
=
new_dev
;
}
else
if
(
!
rt_strcmp
(
argv
[
1
],
"power"
))
{
rt_uint32_t
mode
;
if
(
dev
==
RT_NULL
)
{
sensor_cmd_warning_probe
();
return
;
}
sensor
=
(
rt_sensor_t
)
dev
;
if
(
argc
==
2
)
{
rt_kprintf
(
"current power mode: %s
\n
"
,
sensor_get_power_mode_name
(
&
sensor
->
info
));
}
else
if
(
argc
==
3
)
{
mode
=
atoi
(
argv
[
2
]);
if
(
rt_device_control
(
dev
,
RT_SENSOR_CTRL_SET_POWER_MODE
,
(
void
*
)
mode
)
==
RT_EOK
)
{
rt_kprintf
(
"set new power mode as: %s
\n
"
,
sensor_get_power_mode_name
(
&
sensor
->
info
));
}
else
{
LOG_E
(
"Don't support! Set new power mode error!"
);
}
}
else
{
sensor_cmd_warning_unknown
();
}
}
else
if
(
!
rt_strcmp
(
argv
[
1
],
"accuracy"
))
{
rt_uint32_t
mode
;
if
(
dev
==
RT_NULL
)
{
sensor_cmd_warning_probe
();
return
;
}
sensor
=
(
rt_sensor_t
)
dev
;
if
(
argc
==
2
)
{
rt_kprintf
(
"current accuracy mode: %s
\n
"
,
sensor_get_accuracy_mode_name
(
&
sensor
->
info
));
}
else
if
(
argc
==
3
)
{
mode
=
atoi
(
argv
[
2
]);
if
(
rt_device_control
(
dev
,
RT_SENSOR_CTRL_SET_ACCURACY_MODE
,
(
void
*
)
mode
)
==
RT_EOK
)
{
rt_kprintf
(
"set new accuracy mode as: %s
\n
"
,
sensor_get_accuracy_mode_name
(
&
sensor
->
info
));
}
else
{
LOG_E
(
"Don't support! Set new accuracy mode error!"
);
}
}
else
{
sensor_cmd_warning_unknown
();
}
}
else
if
(
!
rt_strcmp
(
argv
[
1
],
"fetch"
))
{
rt_uint32_t
mode
;
if
(
dev
==
RT_NULL
)
{
sensor_cmd_warning_probe
();
return
;
}
sensor
=
(
rt_sensor_t
)
dev
;
if
(
argc
==
2
)
{
rt_kprintf
(
"current fetch data mode: %s
\n
"
,
sensor_get_fetch_mode_name
(
&
sensor
->
info
));
}
else
if
(
argc
==
3
)
{
mode
=
atoi
(
argv
[
2
]);
if
(
rt_device_control
(
dev
,
RT_SENSOR_CTRL_SET_FETCH_MODE
,
(
void
*
)
mode
)
==
RT_EOK
)
{
rt_kprintf
(
"set new fetch data mode as: %s
\n
"
,
sensor_get_fetch_mode_name
(
&
sensor
->
info
));
}
else
{
LOG_E
(
"Don't support! Set new fetch data mode error!"
);
}
}
else
{
sensor_cmd_warning_unknown
();
}
}
else
{
sensor_cmd_warning_unknown
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录