Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mr_Pangza
rt-thread
提交
18cd9568
R
rt-thread
项目概览
Mr_Pangza
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
2
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,发现更多精彩内容 >>
提交
18cd9568
编写于
11月 01, 2014
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Drivers] Add sensor framework
上级
b84123b0
变更
3
展开全部
显示空白变更内容
内联
并排
Showing
3 changed file
with
1144 addition
and
0 deletion
+1144
-0
components/drivers/sensors/SConscript
components/drivers/sensors/SConscript
+12
-0
components/drivers/sensors/sensor.cpp
components/drivers/sensors/sensor.cpp
+135
-0
components/drivers/sensors/sensor.h
components/drivers/sensors/sensor.h
+997
-0
未找到文件。
components/drivers/sensors/SConscript
0 → 100644
浏览文件 @
18cd9568
# SConscript for sensor framework
from
building
import
*
cwd
=
GetCurrentDir
()
src
=
Glob
(
'*.c'
)
+
Glob
(
'*.cpp'
)
CPPPATH
=
[
cwd
,
cwd
+
'/../include'
]
group
=
DefineGroup
(
'Sensors'
,
src
,
depend
=
[
'RT_USING_SENSOR'
,
'RT_USING_DEVICE'
],
CPPPATH
=
CPPPATH
)
Return
(
'group'
)
components/drivers/sensors/sensor.cpp
0 → 100644
浏览文件 @
18cd9568
#include <stddef.h>
#include "sensor.h"
/**
* Sensor
*/
Sensor
::
Sensor
()
{
this
->
next
=
this
->
prev
=
NULL
;
Subscribe
(
NULL
,
NULL
);
}
Sensor
::~
Sensor
()
{
}
int
Sensor
::
GetType
(
void
)
{
return
this
->
type
;
}
int
Sensor
::
Subscribe
(
SensorEventHandler_t
*
handler
,
void
*
user_data
)
{
this
->
evtHandler
=
handler
;
this
->
userData
=
user_data
;
return
0
;
}
int
Sensor
::
Publish
(
sensors_event_t
*
event
)
{
if
(
this
->
evtHandler
!=
NULL
)
{
/* invoke subscribed handler */
(
*
evtHandler
)(
this
,
event
,
this
->
userData
);
}
return
0
;
}
/**
* Sensor Manager
*/
/* sensor manager instance */
static
SensorManager
_sensor_manager
;
SensorManager
::
SensorManager
()
{
sensorList
=
NULL
;
}
SensorManager
::~
SensorManager
()
{
}
int
SensorManager
::
RegisterSensor
(
Sensor
*
sensor
)
{
SensorManager
*
self
=
&
_sensor_manager
;
RT_ASSERT
(
sensor
!=
RT_NULL
);
/* add sensor into the list */
if
(
self
->
sensorList
=
NULL
)
{
sensor
->
prev
=
sensor
->
next
=
sensor
;
}
else
{
sensor
->
prev
=
self
->
sensorList
;
sensor
->
next
=
self
->
sensorList
->
next
;
self
->
sensorList
->
next
->
prev
=
sensor
;
self
->
sensorList
->
next
=
sensor
;
}
/* point the sensorList to this sensor */
self
->
sensorList
=
sensor
;
return
0
;
}
int
SensorManager
::
DeregisterSensor
(
Sensor
*
sensor
)
{
SensorManager
*
self
=
&
_sensor_manager
;
/* disconnect sensor list */
sensor
->
next
->
prev
=
sensor
->
prev
;
sensor
->
prev
->
next
=
sensor
->
next
;
/* check the sensorList */
if
(
sensor
==
self
->
sensorList
)
{
if
(
sensor
->
next
==
sensor
)
self
->
sensorList
=
NULL
;
/* empty list */
else
self
->
sensorList
=
sensor
->
next
;
}
/* re-initialize sensor node */
sensor
->
next
=
sensor
->
prev
=
sensor
;
return
0
;
}
Sensor
*
SensorManager
::
GetDefaultSensor
(
int
type
)
{
SensorManager
*
self
=
&
_sensor_manager
;
Sensor
*
sensor
=
self
->
sensorList
;
if
(
sensor
==
NULL
)
return
NULL
;
do
{
/* find the same type */
if
(
sensor
->
GetType
()
==
type
)
return
sensor
;
sensor
=
sensor
->
next
;
}
while
(
sensor
!=
self
->
sensorList
);
return
NULL
;
}
int
SensorManager
::
Subscribe
(
int
type
,
SensorEventHandler_t
*
handler
,
void
*
user_data
)
{
Sensor
*
sensor
;
sensor
=
SensorManager
::
GetDefaultSensor
(
type
);
if
(
sensor
!=
NULL
)
{
sensor
->
Subscribe
(
handler
,
user_data
);
return
0
;
}
return
-
1
;
}
components/drivers/sensors/sensor.h
0 → 100644
浏览文件 @
18cd9568
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录