Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
人间散章
rt-thread
提交
0fa10629
R
rt-thread
项目概览
人间散章
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
0fa10629
编写于
11月 01, 2014
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Sensor] code cleanup
上级
c3191826
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
113 addition
and
99 deletion
+113
-99
components/drivers/sensors/sensor.cpp
components/drivers/sensors/sensor.cpp
+61
-61
components/drivers/sensors/sensor.h
components/drivers/sensors/sensor.h
+52
-38
未找到文件。
components/drivers/sensors/sensor.cpp
浏览文件 @
0fa10629
#include <stddef.h>
#include "sensor.h"
/**
/**
* Sensor
*/
Sensor
::
Sensor
()
{
this
->
next
=
this
->
prev
=
NULL
;
Subscribe
(
NULL
,
NULL
);
this
->
next
=
this
->
prev
=
NULL
;
Subscribe
(
NULL
,
NULL
);
}
Sensor
::~
Sensor
()
...
...
@@ -19,7 +19,7 @@ int Sensor::GetType(void)
return
this
->
type
;
}
int
Sensor
::
Subscribe
(
SensorEventHandler_t
*
handler
,
void
*
user_data
)
int
Sensor
::
Subscribe
(
SensorEventHandler_t
*
handler
,
void
*
user_data
)
{
this
->
evtHandler
=
handler
;
this
->
userData
=
user_data
;
...
...
@@ -27,13 +27,13 @@ int Sensor::Subscribe(SensorEventHandler_t *handler, void* user_data)
return
0
;
}
int
Sensor
::
Publish
(
sensors_event_t
*
event
)
int
Sensor
::
Publish
(
sensors_event_t
*
event
)
{
if
(
this
->
evtHandler
!=
NULL
)
{
/* invoke subscribed handler */
(
*
evtHandler
)(
this
,
event
,
this
->
userData
);
}
if
(
this
->
evtHandler
!=
NULL
)
{
/* invoke subscribed handler */
(
*
evtHandler
)(
this
,
event
,
this
->
userData
);
}
return
0
;
}
...
...
@@ -46,89 +46,89 @@ static SensorManager _sensor_manager;
SensorManager
::
SensorManager
()
{
sensorList
=
NULL
;
sensorList
=
NULL
;
}
SensorManager
::~
SensorManager
()
{
}
int
SensorManager
::
RegisterSensor
(
Sensor
*
sensor
)
int
SensorManager
::
RegisterSensor
(
Sensor
*
sensor
)
{
SensorManager
*
self
=
&
_sensor_manager
;
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
;
/* 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
;
}
self
->
sensorList
->
next
->
prev
=
sensor
;
self
->
sensorList
->
next
=
sensor
;
}
/* point the sensorList to this sensor */
self
->
sensorList
=
sensor
;
/* point the sensorList to this sensor */
self
->
sensorList
=
sensor
;
return
0
;
return
0
;
}
int
SensorManager
::
DeregisterSensor
(
Sensor
*
sensor
)
int
SensorManager
::
DeregisterSensor
(
Sensor
*
sensor
)
{
SensorManager
*
self
=
&
_sensor_manager
;
SensorManager
*
self
=
&
_sensor_manager
;
/* disconnect sensor list */
sensor
->
next
->
prev
=
sensor
->
prev
;
sensor
->
prev
->
next
=
sensor
->
next
;
/* 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
;
}
/* 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
;
/* re-initialize sensor node */
sensor
->
next
=
sensor
->
prev
=
sensor
;
return
0
;
}
Sensor
*
SensorManager
::
GetDefaultSensor
(
int
type
)
{
SensorManager
*
self
=
&
_sensor_manager
;
Sensor
*
sensor
=
self
->
sensorList
;
SensorManager
*
self
=
&
_sensor_manager
;
Sensor
*
sensor
=
self
->
sensorList
;
if
(
sensor
==
NULL
)
return
NULL
;
if
(
sensor
==
NULL
)
return
NULL
;
do
{
/* find the same type */
if
(
sensor
->
GetType
()
==
type
)
return
sensor
;
do
{
/* find the same type */
if
(
sensor
->
GetType
()
==
type
)
return
sensor
;
sensor
=
sensor
->
next
;
}
while
(
sensor
!=
self
->
sensorList
);
sensor
=
sensor
->
next
;
}
while
(
sensor
!=
self
->
sensorList
);
return
NULL
;
}
int
SensorManager
::
Subscribe
(
int
type
,
SensorEventHandler_t
*
handler
,
void
*
user_data
)
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
;
}
Sensor
*
sensor
;
sensor
=
SensorManager
::
GetDefaultSensor
(
type
);
if
(
sensor
!=
NULL
)
{
sensor
->
Subscribe
(
handler
,
user_data
);
return
0
;
}
return
-
1
;
}
...
...
components/drivers/sensors/sensor.h
浏览文件 @
0fa10629
...
...
@@ -55,7 +55,8 @@
* Availability: SENSORS_DEVICE_API_VERSION_1_0
* see (*batch)() documentation for details
*/
enum
{
enum
{
SENSORS_BATCH_DRY_RUN
=
0x00000001
,
SENSORS_BATCH_WAKE_UPON_FIFO_FULL
=
0x00000002
};
...
...
@@ -63,7 +64,8 @@ enum {
/*
* what field for meta_data_event_t
*/
enum
{
enum
{
/* a previous flush operation has completed */
META_DATA_FLUSH_COMPLETE
=
1
,
META_DATA_VERSION
/* always last, leave auto-assigned */
...
...
@@ -749,14 +751,17 @@ enum {
*/
typedef
struct
{
union
{
union
{
float
v
[
3
];
struct
{
struct
{
float
x
;
float
y
;
float
z
;
};
struct
{
struct
{
float
azimuth
;
float
pitch
;
float
roll
;
...
...
@@ -771,22 +776,26 @@ typedef struct
*/
typedef
struct
{
union
{
float
uncalib
[
3
];
struct
{
float
x_uncalib
;
float
y_uncalib
;
float
z_uncalib
;
union
{
float
uncalib
[
3
];
struct
{
float
x_uncalib
;
float
y_uncalib
;
float
z_uncalib
;
};
};
};
union
{
float
bias
[
3
];
struct
{
float
x_bias
;
float
y_bias
;
float
z_bias
;
union
{
float
bias
[
3
];
struct
{
float
x_bias
;
float
y_bias
;
float
z_bias
;
};
};
};
}
uncalibrated_event_t
;
typedef
struct
meta_data_event
...
...
@@ -799,7 +808,8 @@ typedef struct meta_data_event
* Union of the various types of sensor data
* that can be returned.
*/
typedef
struct
sensors_event_t
{
typedef
struct
sensors_event_t
{
/* must be sizeof(struct sensors_event_t) */
int32_t
version
;
...
...
@@ -815,8 +825,10 @@ typedef struct sensors_event_t {
/* time is in nanosecond */
int64_t
timestamp
;
union
{
union
{
union
{
union
{
float
data
[
16
];
/* acceleration values are in meter per second per second (m/s^2) */
...
...
@@ -859,7 +871,8 @@ typedef struct sensors_event_t {
meta_data_event_t
meta_data
;
};
union
{
union
{
uint64_t
data
[
8
];
/* step-counter */
...
...
@@ -872,15 +885,16 @@ typedef struct sensors_event_t {
/* see SENSOR_TYPE_META_DATA */
typedef
sensors_event_t
sensors_meta_data_event_t
;
typedef
struct
sensor_t
{
typedef
struct
sensor_t
{
/* Name of this sensor.
* All sensors of the same "type" must have a different "name".
*/
const
char
*
name
;
const
char
*
name
;
/* vendor of the hardware part */
const
char
*
vendor
;
const
char
*
vendor
;
/* version of the hardware part + driver. The value of this field
* must increase when the driver is updated in a way that changes the
...
...
@@ -929,7 +943,7 @@ typedef struct sensor_t {
uint32_t
fifoMaxEventCount
;
/* reserved fields, must be zero */
void
*
reserved
[
6
];
void
*
reserved
[
6
];
}
sensor_t
;
class
SensorConfigure
...
...
@@ -939,7 +953,7 @@ class SensorConfigure
class
Sensor
;
class
SensorManager
;
typedef
void
(
*
SensorEventHandler_t
)(
Sensor
*
sensor
,
sensors_event_t
*
event
,
void
*
user_data
);
typedef
void
(
*
SensorEventHandler_t
)(
Sensor
*
sensor
,
sensors_event_t
*
event
,
void
*
user_data
);
/**
* Sensor Base Class
...
...
@@ -961,17 +975,17 @@ public:
int
GetType
(
void
);
int
Subscribe
(
SensorEventHandler_t
*
handler
,
void
*
user_data
);
int
Publish
(
sensors_event_t
*
event
);
int
Subscribe
(
SensorEventHandler_t
*
handler
,
void
*
user_data
);
int
Publish
(
sensors_event_t
*
event
);
protected:
protected:
Sensor
*
next
;
Sensor
*
prev
;
Sensor
*
prev
;
SensorEventHandler_t
*
evtHandler
;
void
*
userData
;
friend
class
SensorManager
;
friend
class
SensorManager
;
};
/**
...
...
@@ -982,15 +996,15 @@ class SensorManager
public:
SensorManager
();
~
SensorManager
();
static
int
RegisterSensor
(
Sensor
*
sensor
);
static
int
DeregisterSensor
(
Sensor
*
sensor
);
static
int
RegisterSensor
(
Sensor
*
sensor
);
static
int
DeregisterSensor
(
Sensor
*
sensor
);
static
Sensor
*
GetDefaultSensor
(
int
type
);
static
int
Subscribe
(
int
type
,
SensorEventHandler_t
*
handler
,
void
*
user_data
);
static
int
Subscribe
(
int
type
,
SensorEventHandler_t
*
handler
,
void
*
user_data
);
private:
Sensor
*
sensorList
;
Sensor
*
sensorList
;
};
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录