Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76519099
rt-thread
提交
46bca6f8
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,发现更多精彩内容 >>
提交
46bca6f8
编写于
1月 04, 2015
作者:
B
bernard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add C programming language APIs.
上级
58163f49
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
130 addition
and
72 deletion
+130
-72
components/drivers/sensors/sensor.cpp
components/drivers/sensors/sensor.cpp
+37
-1
components/drivers/sensors/sensor.h
components/drivers/sensors/sensor.h
+93
-71
未找到文件。
components/drivers/sensors/sensor.cpp
浏览文件 @
46bca6f8
...
...
@@ -71,7 +71,7 @@ int SensorBase::publish(sensors_event_t *event)
if
(
this
->
evtHandler
!=
NULL
)
{
/* invoke subscribed handler */
(
*
evtHandler
)(
this
,
event
,
this
->
userData
);
(
*
evtHandler
)(
event
,
this
->
userData
);
}
return
0
;
...
...
@@ -189,3 +189,39 @@ int SensorManager::pollSensor(SensorBase *sensor, sensors_event_t *events, int n
return
index
;
}
int
rt_sensor_subscribe
(
int
type
,
SensorEventHandler_t
*
handler
,
void
*
user_data
)
{
return
SensorManager
::
subscribe
(
type
,
handler
,
user_data
);
}
rt_sensor_t
rt_sensor_get_default
(
int
type
)
{
return
(
rt_sensor_t
)
SensorManager
::
getDefaultSensor
(
type
);
}
int
rt_sensor_poll
(
rt_sensor_t
sensor
,
sensors_event_t
*
event
)
{
SensorBase
*
sensor_base
;
if
(
sensor
==
NULL
||
event
==
NULL
)
return
-
1
;
return
sensor_base
->
poll
(
event
);
}
int
rt_sensor_configure
(
rt_sensor_t
sensor
,
SensorConfig
*
config
)
{
SensorBase
*
sensor_base
;
if
(
sensor
==
NULL
||
config
==
NULL
)
return
-
1
;
sensor_base
=
(
SensorBase
*
)
sensor
;
return
sensor_base
->
setConfig
(
config
);
}
int
rt_sensor_activate
(
rt_sensor_t
sensor
,
int
enable
)
{
SensorBase
*
sensor_base
;
if
(
sensor
==
NULL
)
return
-
1
;
sensor_base
=
(
SensorBase
*
)
sensor
;
return
sensor_base
->
activate
(
enable
);
}
components/drivers/sensors/sensor.h
浏览文件 @
46bca6f8
...
...
@@ -36,7 +36,9 @@
#include <rtdevice.h>
#include <stdint.h>
#ifdef __CC_ARM
/* skip warning in armcc */
#pragma anon_unions
#endif
/**
* Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
...
...
@@ -729,23 +731,23 @@ enum
* all values are in SI units (m/s^2)
*/
#define SENSORS_GRAVITY_SUN (275.0f)
#define SENSORS_GRAVITY_MOON
(1.6f)
#define SENSORS_GRAVITY_MOON
(1.6f)
#define SENSORS_GRAVITY_EARTH (9.80665f)
#define SENSORS_GRAVITY_STANDARD
(SENSORS_GRAVITY_EARTH)
#define SENSORS_GRAVITY_STANDARD
(SENSORS_GRAVITY_EARTH)
/** Maximum magnetic field on Earth's surface */
#define MAGNETIC_FIELD_EARTH_MAX
(60.0f)
#define MAGNETIC_FIELD_EARTH_MAX
(60.0f)
/** Minimum magnetic field on Earth's surface */
#define MAGNETIC_FIELD_EARTH_MIN
(30.0f)
#define MAGNETIC_FIELD_EARTH_MIN
(30.0f)
/** Average sea level pressure is 1013.25 hPa */
#define SENSORS_PRESSURE_SEALEVELHPA
(1013.25F)
#define SENSORS_PRESSURE_SEALEVELHPA
(1013.25F)
/** Degrees/s to rad/s multiplier */
#define SENSORS_DPS_TO_RADS
(0.017453293F)
#define SENSORS_DPS_TO_RADS
(0.017453293F)
/** Gauss to micro-Tesla multiplier */
#define SENSORS_GAUSS_TO_MICROTESLA
(100)
#define SENSORS_GAUSS_TO_MICROTESLA
(100)
/**
* status of orientation sensor
...
...
@@ -785,15 +787,15 @@ typedef struct
*/
typedef
struct
{
struct
{
int16_t
x
;
int16_t
y
;
int16_t
z
;
};
int8_t
status
;
uint8_t
reserved
[
1
];
struct
{
int16_t
x
;
int16_t
y
;
int16_t
z
;
};
int8_t
status
;
uint8_t
reserved
[
1
];
}
sensors_raw_vec_t
;
/**
...
...
@@ -858,21 +860,21 @@ typedef struct sensors_event_t
/* acceleration values are in meter per second per second (m/s^2) */
sensors_vec_t
acceleration
;
/* raw acceleration data */
sensors_raw_vec_t
raw_acceleration
;
/* raw acceleration data */
sensors_raw_vec_t
raw_acceleration
;
/* magnetic vector values are in micro-Tesla (uT) */
sensors_vec_t
magnetic
;
/* raw magnetic data */
sensors_raw_vec_t
raw_magnetic
;
/* raw magnetic data */
sensors_raw_vec_t
raw_magnetic
;
/* orientation values are in degrees */
sensors_vec_t
orientation
;
/* gyroscope values are in rad/s */
sensors_vec_t
gyro
;
/* raw gyroscope data */
sensors_raw_vec_t
raw_gyro
;
/* raw gyroscope data */
sensors_raw_vec_t
raw_gyro
;
/* temperature is in degrees centigrade (Celsius) */
float
temperature
;
...
...
@@ -918,7 +920,6 @@ typedef sensors_event_t sensors_meta_data_event_t;
typedef
struct
sensor_t
{
/* Name of this sensor.
* All sensors of the same "type" must have a different "name".
*/
...
...
@@ -979,17 +980,17 @@ typedef struct sensor_t
enum
SensorMode
{
SENSOR_MODE_RAW
,
SENSOR_MODE_CALIBRATED
,
SENSOR_MODE_NORMAL
,
SENSOR_MODE_RAW
,
SENSOR_MODE_CALIBRATED
,
SENSOR_MODE_NORMAL
,
};
enum
SensorAccelRange
{
SENSOR_ACCEL_RANGE_2G
,
SENSOR_ACCEL_RANGE_4G
,
SENSOR_ACCEL_RANGE_8G
,
SENSOR_ACCEL_RANGE_16G
,
SENSOR_ACCEL_RANGE_2G
,
SENSOR_ACCEL_RANGE_4G
,
SENSOR_ACCEL_RANGE_8G
,
SENSOR_ACCEL_RANGE_16G
,
};
#define SENSOR_ACCEL_SENSITIVITY_2G (0.001F)
#define SENSOR_ACCEL_SENSITIVITY_4G (0.002F)
...
...
@@ -998,56 +999,58 @@ enum SensorAccelRange
enum
SensorGyroRange
{
SENSOR_GYRO_RANGE_250DPS
,
SENSOR_GYRO_RANGE_500DPS
,
SENSOR_GYRO_RANGE_1000DPS
,
SENSOR_GYRO_RANGE_2000DPS
,
SENSOR_GYRO_RANGE_250DPS
,
SENSOR_GYRO_RANGE_500DPS
,
SENSOR_GYRO_RANGE_1000DPS
,
SENSOR_GYRO_RANGE_2000DPS
,
};
#define SENSOR_GYRO_SENSITIVITY_250DPS
(0.00875F)
#define SENSOR_GYRO_SENSITIVITY_500DPS
(0.0175F)
#define SENSOR_GYRO_SENSITIVITY_1000DPS
(0.035F)
#define SENSOR_GYRO_SENSITIVITY_2000DPS
(0.070F)
#define SENSOR_GYRO_SENSITIVITY_250DPS
(0.00875F)
#define SENSOR_GYRO_SENSITIVITY_500DPS
(0.0175F)
#define SENSOR_GYRO_SENSITIVITY_1000DPS
(0.035F)
#define SENSOR_GYRO_SENSITIVITY_2000DPS
(0.070F)
enum
SensorDataRate
{
SENSOR_DATARATE_3200HZ
,
SENSOR_DATARATE_1600HZ
,
SENSOR_DATARATE_800HZ
,
SENSOR_DATARATE_400HZ
,
SENSOR_DATARATE_200HZ
,
SENSOR_DATARATE_100HZ
,
SENSOR_DATARATE_50HZ
,
SENSOR_DATARATE_25HZ
,
SENSOR_DATARATE_12_5HZ
,
SENSOR_DATARATE_6_25HZ
,
SENSOR_DATARATE_3_13HZ
,
SENSOR_DATARATE_1_56HZ
,
SENSOR_DATARATE_0_78HZ
,
SENSOR_DATARATE_0_39HZ
,
SENSOR_DATARATE_0_20HZ
,
SENSOR_DATARATE_0_10HZ
,
SENSOR_DATARATE_3200HZ
,
SENSOR_DATARATE_1600HZ
,
SENSOR_DATARATE_800HZ
,
SENSOR_DATARATE_400HZ
,
SENSOR_DATARATE_200HZ
,
SENSOR_DATARATE_100HZ
,
SENSOR_DATARATE_50HZ
,
SENSOR_DATARATE_25HZ
,
SENSOR_DATARATE_12_5HZ
,
SENSOR_DATARATE_6_25HZ
,
SENSOR_DATARATE_3_13HZ
,
SENSOR_DATARATE_1_56HZ
,
SENSOR_DATARATE_0_78HZ
,
SENSOR_DATARATE_0_39HZ
,
SENSOR_DATARATE_0_20HZ
,
SENSOR_DATARATE_0_10HZ
,
};
class
SensorBase
;
class
SensorManager
;
typedef
void
(
*
SensorEventHandler_t
)(
SensorBase
*
sensor
,
sensors_event_t
*
event
,
void
*
user_data
);
/**
* Sensor Configuration
*/
typedef
struct
SensorConfig
{
int
mode
;
int
mode
;
enum
SensorDataRate
data_rate
;
enum
SensorDataRate
data_rate
;
union
range
{
enum
SensorAccelRange
accel_range
;
enum
SensorGyroRange
gyro_range
;
}
range
;
union
range
{
enum
SensorAccelRange
accel_range
;
enum
SensorGyroRange
gyro_range
;
}
range
;
}
SensorConfig
;
typedef
void
(
*
SensorEventHandler_t
)(
sensors_event_t
*
event
,
void
*
user_data
);
#ifdef __cplusplus
class
SensorBase
;
class
SensorManager
;
/**
* Sensor Base Class
*/
...
...
@@ -1068,8 +1071,8 @@ public:
int
getType
(
void
);
int
setConfig
(
SensorConfig
*
config
);
int
getConfig
(
SensorConfig
*
config
);
int
setConfig
(
SensorConfig
*
config
);
int
getConfig
(
SensorConfig
*
config
);
int
subscribe
(
SensorEventHandler_t
*
handler
,
void
*
user_data
);
int
publish
(
sensors_event_t
*
event
);
...
...
@@ -1078,8 +1081,8 @@ protected:
SensorBase
*
next
;
SensorBase
*
prev
;
/* sensor configuration */
SensorConfig
config
;
/* sensor configuration */
SensorConfig
config
;
SensorEventHandler_t
*
evtHandler
;
void
*
userData
;
...
...
@@ -1102,9 +1105,28 @@ public:
static
SensorBase
*
getDefaultSensor
(
int
type
);
static
int
subscribe
(
int
type
,
SensorEventHandler_t
*
handler
,
void
*
user_data
);
static
int
sensorEventReady
(
SensorBase
*
sensor
);
static
int
pollSensor
(
SensorBase
*
sensor
,
sensors_event_t
*
events
,
int
number
,
int
duration
);
static
int
sensorEventReady
(
SensorBase
*
sensor
);
static
int
pollSensor
(
SensorBase
*
sensor
,
sensors_event_t
*
events
,
int
number
,
int
duration
);
};
#endif
/* C programming language APIs */
/* rt_sensor_t is a C typedef for SensorBase */
typedef
void
*
rt_sensor_t
;
#ifdef __cplusplus
extern
"C"
{
#endif
rt_sensor_t
rt_sensor_get_default
(
int
type
);
int
rt_sensor_subscribe
(
rt_sensor_t
sensor
,
SensorEventHandler_t
*
handler
,
void
*
user_data
);
int
rt_sensor_activate
(
rt_sensor_t
sensor
,
int
enable
);
int
rt_sensor_configure
(
rt_sensor_t
sensor
,
SensorConfig
*
config
);
int
rt_sensor_poll
(
rt_sensor_t
sensor
,
sensors_event_t
*
event
);
#ifdef __cplusplus
}
#endif
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录