cun
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
#include "./sensor/MMC56.h"
|
||||
#include "./sensor/BMP280.h"
|
||||
#include "./sensor/AK8963.h"
|
||||
#include "./sensor/WF282A.h"
|
||||
#include "asm/rtc.h"
|
||||
#include "system/timer.h"
|
||||
#include "adv_time_stamp_setting.h"
|
||||
@ -167,7 +168,11 @@ void sensor_collect_task(void){
|
||||
if(interval >= 4){
|
||||
interval = 0;
|
||||
SL_data_index = 0;
|
||||
#if BMP280
|
||||
bmp280_read_data(&temperature, &pressure);//每40ms读取一次
|
||||
#else
|
||||
WF_GET_Temperature_Pressure(&temperature, &pressure);
|
||||
#endif
|
||||
for(int i = 0;i<MPU_FIFO_LEN;i++){
|
||||
send_data.sensor_package[i].temperature = (int16_t)(temperature * 1000.0f);
|
||||
send_data.sensor_package[i].pressure = (int32_t)(pressure * 1000.0f);
|
||||
@ -260,14 +265,14 @@ void data_log(uint8_t* data){
|
||||
float pressure = (float)press_raw / 1000.0f;
|
||||
|
||||
// 打印解析后的数据
|
||||
// if(i % 8 == 0){
|
||||
// printf(" ==================ble index: %d\n", *p);
|
||||
// printf("Package[%d]:\n", i);
|
||||
// printf(" ACC(g): x=%.3f, y=%.3f, z=%.3f\n", acc_g[0], acc_g[1], acc_g[2]);
|
||||
// printf(" GYR(dps):x=%.3f, y=%.3f, z=%.3f\n", gyr_dps[0], gyr_dps[1], gyr_dps[2]);
|
||||
// printf(" MAG(Gs): x=%.3f, y=%.3f, z=%.3f\n", mag_gauss[0], mag_gauss[1], mag_gauss[2]);
|
||||
// printf(" TEMP(C): %.3f, PRESS(Pa): %.3f\n", temperature, pressure);
|
||||
// }
|
||||
if(i % 8 == 0){
|
||||
printf(" ==================ble index: %d\n", *p);
|
||||
printf("Package[%d]:\n", i);
|
||||
printf(" ACC(g): x=%.3f, y=%.3f, z=%.3f\n", acc_g[0], acc_g[1], acc_g[2]);
|
||||
printf(" GYR(dps):x=%.3f, y=%.3f, z=%.3f\n", gyr_dps[0], gyr_dps[1], gyr_dps[2]);
|
||||
printf(" MAG(Gs): x=%.3f, y=%.3f, z=%.3f\n", mag_gauss[0], mag_gauss[1], mag_gauss[2]);
|
||||
printf(" TEMP(C): %.3f, PRESS(Pa): %.3f\n", temperature, pressure);
|
||||
}
|
||||
|
||||
}
|
||||
// printf("--- End of Packet ---\n\n");
|
||||
@ -511,7 +516,11 @@ void test_func(void){
|
||||
|
||||
SL_SC7U22_Config();
|
||||
mmc5603nj_init();
|
||||
bmp280_init();
|
||||
#if BMP280
|
||||
BMP280_init();
|
||||
#else
|
||||
WF_Init();
|
||||
#endif
|
||||
os_task_create(BLE_send_fuc,NULL,5,1024,32,"BLE_send_fuc");
|
||||
os_task_create(sensor_collect_task,NULL,5,1024,32,"sensor_collect_task");
|
||||
// create_process(&test_id, "sensor_test",NULL,data_send_task ,3);
|
||||
|
||||
@ -135,18 +135,18 @@ static float compensate_pressure(int32_t adc_P) {
|
||||
|
||||
|
||||
|
||||
uint8_t bmp280_init(void) {
|
||||
uint8_t BMP280_init(void) {
|
||||
uint8_t id;
|
||||
uint8_t calib_data[24];
|
||||
|
||||
// 1. 检查芯片ID
|
||||
if (bmp280_read_regs(BMP280_REG_ID, &id, 1) == 0) {
|
||||
printf("bmp280 get id error:%d\n",id );
|
||||
return 1; // I2C读取失败
|
||||
// return 1; // I2C读取失败
|
||||
}
|
||||
if (id != 0x58) {
|
||||
printf("bmp280 check diff:%d\n",id );
|
||||
return 1; // ID不匹配
|
||||
// return 1; // ID不匹配
|
||||
}
|
||||
printf("bmp280 get id:0%X\n",id );
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define BMP_PULL_UP 0 //外部是否接的上拉
|
||||
#define BMP_PULL_UP 1 //外部是否接的上拉
|
||||
|
||||
// I2C 从设备地址
|
||||
#if BMP_PULL_UP == 1 //外部接的高
|
||||
@ -33,7 +33,7 @@
|
||||
* @return 0: 成功, 1: 芯片ID错误, 2: 读取校准参数失败
|
||||
* @note 此函数会完成ID检查、软复位、读取校准参数,并设置传感器为连续测量模式。
|
||||
*/
|
||||
uint8_t bmp280_init(void);
|
||||
uint8_t BMP280_init(void);
|
||||
|
||||
/**
|
||||
* @brief 从BMP280读取温度和气压数据
|
||||
|
||||
@ -6,6 +6,15 @@
|
||||
#include <stdint.h> // 推荐使用标准类型
|
||||
#include "gSensor/gSensor_manage.h"
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
/*==================================================================================*/
|
||||
/* WF282A 内部定义 */
|
||||
/*==================================================================================*/
|
||||
@ -109,13 +118,14 @@ uint8_t WF_Init() {
|
||||
|
||||
// 1. 配置传感器工作模式
|
||||
// 推荐配置:压力8次过采样,温度1次过采样,测量速率16Hz
|
||||
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_16 << 4) | PM_PRC_8);
|
||||
wf282a_write_reg(WF_TMP_CFG, (TMP_RATE_16 << 4) | TMP_PRC_1 | TMP_INT_SENSOR);
|
||||
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_32 << 4) | PM_PRC_32);
|
||||
wf282a_write_reg(WF_TMP_CFG, TMP_INT_SENSOR | (TMP_RATE_32 << 4) | TMP_PRC_32);
|
||||
wf282a_write_reg(WF_MEAS_CFG, 0x07); // 启动连续压力和温度测量
|
||||
wf282a_write_reg(WF_CFG_REG, 0x00); // 无中断或FIFO移位配置
|
||||
|
||||
// 2. 一次性读取所有校准系数 (从0x10到0x21,共18字节)
|
||||
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 0) {
|
||||
if (wf282a_read_regs(COEF_C0, calib_buf, 18) == 0) {
|
||||
xlog("Failed to read the calibration coefficient\n");
|
||||
return 2; // 读取校准数据失败
|
||||
}
|
||||
parse_calibration_data(calib_buf);
|
||||
@ -123,6 +133,7 @@ uint8_t WF_Init() {
|
||||
// 3. 检查配置是否写入成功
|
||||
wf282a_read_regs(WF_MEAS_CFG, &check_cfg, 1);
|
||||
if (check_cfg != 0x07) {
|
||||
xlog("WF_Init error, check_cfg: %d\n", check_cfg);
|
||||
return 1; // 错误
|
||||
} else {
|
||||
return 0; // 成功
|
||||
@ -168,6 +179,19 @@ float WF_Pressure_Calculate() {
|
||||
return Pcomp;
|
||||
}
|
||||
|
||||
void WF_GET_Temperature_Pressure(float* temperature, float* precessure){
|
||||
int32_t Traw = Get_Traw();
|
||||
int32_t Praw = Get_Praw();
|
||||
float Traw_sc = (float)Traw / KT;// 缩放原始温度值
|
||||
float Praw_sc = (float)Praw / KP;// 缩放原始压力值
|
||||
|
||||
*temperature = (float)c0 * 0.5f + (float)c1 * Traw_sc;
|
||||
*precessure = (float)c00
|
||||
+ Praw_sc * ((float)c10 + Praw_sc * ((float)c20 + Praw_sc * (float)c30))
|
||||
+ Traw_sc * (float)c01
|
||||
+ Traw_sc * Praw_sc * ((float)c11 + Praw_sc * (float)c21);
|
||||
}
|
||||
|
||||
float WF_Altitude_Calculate() {
|
||||
float pressure_pa = WF_Pressure_Calculate();
|
||||
// 使用标准大气压公式计算海拔
|
||||
|
||||
@ -4,8 +4,19 @@
|
||||
#include <stdint.h> // 使用标准整数类型
|
||||
|
||||
// 标定值
|
||||
#define KT 524288.0f
|
||||
#define KP 1572864.0f
|
||||
/*
|
||||
Oversampling Rate Scale Factor (kP or kT
|
||||
1 (single) 524288
|
||||
2 times (Low Power) 1572864
|
||||
4 times 3670016
|
||||
8 times 7864320
|
||||
16 times (Standard) 253952
|
||||
32 times 516096
|
||||
64 times (High Precision) 1040384
|
||||
128 times 2088960
|
||||
*/
|
||||
#define KT 516096.0f //温度
|
||||
#define KP 516096.0f //压力
|
||||
|
||||
|
||||
#define WF_PULL_UP 1 //外部是否接的上拉
|
||||
@ -95,7 +106,7 @@
|
||||
#define TMP_RATE_32 0x05 // 32 次/秒
|
||||
#define TMP_RATE_64 0x06 // 64 次/秒
|
||||
#define TMP_RATE_128 0x07 // 128 次/秒
|
||||
// 温度配置 (TMP_CFG[3:0]) - 过采样率
|
||||
// 温度配置 (TMP_CFG[2:0]) - 过采样率
|
||||
#define TMP_PRC_1 0x00 // 1 次
|
||||
#define TMP_PRC_2 0x01 // 2 次
|
||||
#define TMP_PRC_4 0x02 // 4 次
|
||||
@ -145,4 +156,6 @@ float WF_Pressure_Calculate(void);
|
||||
*/
|
||||
float WF_Temperature_Calculate(void);
|
||||
|
||||
void WF_GET_Temperature_Pressure(float* temperature, float* precessure);
|
||||
|
||||
#endif // _WF282A_H_
|
||||
@ -7,4 +7,6 @@
|
||||
|
||||
#define ACC_RANGE 16 //g,加速度满量程:2、4、8、16
|
||||
|
||||
#define BMP280 1
|
||||
|
||||
#endif
|
||||
@ -49,6 +49,7 @@
|
||||
#include "./sensor/MMC56.h"
|
||||
#include "./sensor/BMP280.h"
|
||||
#include "./sensor/AK8963.h"
|
||||
#include "./sensor/WF282A.h"
|
||||
#include "./calculate/skiing_tracker.h"
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//宏定义
|
||||
@ -83,13 +84,13 @@ extern u8 init_ok;
|
||||
extern u8 sniff_out;
|
||||
unsigned char xtell_bl_state=0; //存放经典蓝牙的连接状态,0断开,1是连接
|
||||
u8 bt_newname =0;
|
||||
unsigned char xt_ble_new_name[9] = "skiing_2F";
|
||||
unsigned char xt_ble_new_name[9] = "skiing_D7";
|
||||
static u16 play_poweron_ok_timer_id = 0;
|
||||
|
||||
// -- 初始化标志位 --
|
||||
u8 SC7U22_init = 0x10; //六轴是否初始化
|
||||
u8 MMC5603nj_init = 0x20; //地磁是否初始化
|
||||
u8 BMP280_init = 0x30; //气压计初始化
|
||||
u8 barometer_init = 0x30; //气压计初始化
|
||||
u8 foot_init = 0x40; //数据来源初始化:左脚0x41 or 右脚0x42
|
||||
// -- 线程id --
|
||||
|
||||
@ -232,6 +233,7 @@ void le_user_app_event(u8* buffer){
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
// start_calibration();
|
||||
}else if(buffer[4] == 0x02){ //地磁
|
||||
|
||||
if(mmc5603nj_init() == 0){
|
||||
MMC5603nj_init = 0x20;
|
||||
send2_0[4] = MMC5603nj_init; //地磁初始化失败
|
||||
@ -242,16 +244,29 @@ void le_user_app_event(u8* buffer){
|
||||
send2_0[4] = MMC5603nj_init; //地磁初始化成功
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
}else if(buffer[4] == 0x03){ //气压计初始化
|
||||
if(bmp280_init() != 0){
|
||||
#if BMP280
|
||||
if(BMP280_init() != 0){
|
||||
//初始化失败
|
||||
BMP280_init = 0x30;
|
||||
send2_0[4] = BMP280_init;
|
||||
barometer_init = 0x30;
|
||||
send2_0[4] = barometer_init;
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
return;
|
||||
}
|
||||
BMP280_init = 0x31;
|
||||
send2_0[4] = BMP280_init; //气压计初始化成功
|
||||
barometer_init = 0x31;
|
||||
send2_0[4] = barometer_init; //气压计初始化成功
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
#else
|
||||
if(WF_Init() != 0){
|
||||
//初始化失败
|
||||
barometer_init = 0x30;
|
||||
send2_0[4] = barometer_init;
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
return;
|
||||
}
|
||||
barometer_init = 0x31;
|
||||
send2_0[4] = barometer_init; //气压计初始化成功
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case 0x01: //设置传感器采集对象:左脚or右脚
|
||||
@ -271,13 +286,13 @@ void le_user_app_event(u8* buffer){
|
||||
}else if(buffer[4] == 0x02){ //地磁
|
||||
send2_2[4] = MMC5603nj_init;
|
||||
}else if(buffer[4] == 0x03){ //气压计
|
||||
send2_2[4] = BMP280_init;
|
||||
send2_2[4] = barometer_init;
|
||||
}
|
||||
send_data_to_ble_client(&send2_2,5);
|
||||
break;
|
||||
case 0x03: //开始/停止滑雪计算
|
||||
if(buffer[4] == 0x01){ //开始滑雪计算
|
||||
if(SC7U22_init == 0x10 || MMC5603nj_init == 0x20 || BMP280_init == 0x30){ //传感器未进行初始化
|
||||
if(SC7U22_init == 0x10 || MMC5603nj_init == 0x20 || barometer_init == 0x30){ //传感器未进行初始化
|
||||
u8 send2_3[5] = {0xBB,0xBE,0x02,0x00,0x00};
|
||||
send_data_to_ble_client(&send2_3,5);
|
||||
return;
|
||||
@ -366,15 +381,15 @@ void le_user_app_event_handler(struct sys_event* event){
|
||||
send2_0[4] = MMC5603nj_init; //地磁初始化成功
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
}else if(event->u.app.buffer[4] == 0x03){ //气压计初始化
|
||||
if(bmp280_init() != 0){
|
||||
if(BMP280_init() != 0){
|
||||
//初始化失败
|
||||
BMP280_init = 0x30;
|
||||
send2_0[4] = BMP280_init;
|
||||
barometer_init = 0x30;
|
||||
send2_0[4] = barometer_init;
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
return;
|
||||
}
|
||||
BMP280_init = 0x31;
|
||||
send2_0[4] = BMP280_init; //气压计初始化成功
|
||||
barometer_init = 0x31;
|
||||
send2_0[4] = barometer_init; //气压计初始化成功
|
||||
send_data_to_ble_client(&send2_0,5);
|
||||
}
|
||||
break;
|
||||
@ -395,13 +410,13 @@ void le_user_app_event_handler(struct sys_event* event){
|
||||
}else if(event->u.app.buffer[4] == 0x02){ //地磁
|
||||
send2_2[4] = MMC5603nj_init;
|
||||
}else if(event->u.app.buffer[4] == 0x03){ //气压计
|
||||
send2_2[4] = BMP280_init;
|
||||
send2_2[4] = barometer_init;
|
||||
}
|
||||
send_data_to_ble_client(&send2_2,5);
|
||||
break;
|
||||
case 0x03: //开始/停止滑雪计算
|
||||
if(event->u.app.buffer[4] == 0x01){ //开始滑雪计算
|
||||
if(SC7U22_init == 0x10 || MMC5603nj_init == 0x20 || BMP280_init == 0x30){ //传感器未进行初始化
|
||||
if(SC7U22_init == 0x10 || MMC5603nj_init == 0x20 || barometer_init == 0x30){ //传感器未进行初始化
|
||||
u8 send2_3[5] = {0xBB,0xBE,0x02,0x00,0x00};
|
||||
send_data_to_ble_client(&send2_3,5);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user