2025-10-29 16:24:16 +08:00
|
|
|
|
#include "system/includes.h"
|
|
|
|
|
|
#include "btstack/btstack_task.h"
|
|
|
|
|
|
#include "app_config.h"
|
|
|
|
|
|
#include "app_action.h"
|
|
|
|
|
|
#include "asm/pwm_led.h"
|
|
|
|
|
|
#include "tone_player.h"
|
|
|
|
|
|
#include "ui_manage.h"
|
|
|
|
|
|
#include "gpio.h"
|
|
|
|
|
|
#include "app_main.h"
|
|
|
|
|
|
#include "asm/charge.h"
|
|
|
|
|
|
#include "update.h"
|
|
|
|
|
|
#include "app_power_manage.h"
|
|
|
|
|
|
#include "audio_config.h"
|
|
|
|
|
|
#include "app_charge.h"
|
|
|
|
|
|
#include "bt_profile_cfg.h"
|
|
|
|
|
|
#include "dev_manager/dev_manager.h"
|
|
|
|
|
|
#include "update_loader_download.h"
|
|
|
|
|
|
#include "LIS2DH12.h"
|
2025-10-30 11:33:38 +08:00
|
|
|
|
#include "circle_buffer.h"
|
|
|
|
|
|
#include "circle_buffer.h"
|
|
|
|
|
|
#include "btstack/avctp_user.h"
|
2025-11-03 18:48:15 +08:00
|
|
|
|
#include "calculate/skiing_tracker.h"
|
2025-10-31 09:40:15 +08:00
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//宏定义
|
|
|
|
|
|
#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
|
|
|
|
|
|
//
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2025-10-29 16:24:16 +08:00
|
|
|
|
|
2025-10-31 10:38:17 +08:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//START -- 函数定义
|
2025-10-30 16:14:14 +08:00
|
|
|
|
void send_data_to_ble_client(const u8* data, u16 length);
|
2025-11-03 18:48:15 +08:00
|
|
|
|
extern void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec);
|
2025-10-31 10:38:17 +08:00
|
|
|
|
//END -- 函数定义
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//START -- 变量定义
|
2025-10-30 16:14:14 +08:00
|
|
|
|
|
2025-10-30 11:33:38 +08:00
|
|
|
|
// --- 任务ID ---
|
|
|
|
|
|
static u16 xtell_i2c_test_id;
|
|
|
|
|
|
static u16 collect_data_id;
|
|
|
|
|
|
static u16 send_data_id;
|
|
|
|
|
|
|
|
|
|
|
|
// --- 环形缓冲区 ---
|
|
|
|
|
|
#define SENSOR_DATA_BUFFER_SIZE 512
|
|
|
|
|
|
static u8 sensor_data_buffer[SENSOR_DATA_BUFFER_SIZE];
|
|
|
|
|
|
static circle_buffer_t sensor_cb;
|
2025-11-03 18:48:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--- test ---
|
|
|
|
|
|
static SkiingTracker skiing_data;
|
|
|
|
|
|
static char ble_send_data[50];
|
2025-10-31 10:38:17 +08:00
|
|
|
|
//END -- 变量定义
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
2025-10-30 11:33:38 +08:00
|
|
|
|
|
2025-10-29 16:24:16 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
// 从环形缓冲区读取数据并发送
|
|
|
|
|
|
void send_sensor_data_task(void) {
|
|
|
|
|
|
// printf("xtell_ble_send\n");
|
|
|
|
|
|
}
|
2025-10-29 16:24:16 +08:00
|
|
|
|
|
2025-10-30 11:33:38 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
void sensor_test(){
|
2025-10-30 11:33:38 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
// signed short acc_raw[3], gyr_raw[3];
|
2025-10-30 11:33:38 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
// // 读取原始数据
|
|
|
|
|
|
// SL_SC7U22_RawData_Read(acc_raw, gyr_raw);
|
2025-10-31 16:58:39 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
// // 将原始数据送入追踪器进行处理
|
|
|
|
|
|
// SkiingTracker_Update(&skiing_data, acc_raw, gyr_raw);
|
|
|
|
|
|
|
|
|
|
|
|
// // c. 打印状态和结果
|
|
|
|
|
|
const char* state_str = "UNKNOWN";
|
|
|
|
|
|
switch(skiing_data.state) {
|
|
|
|
|
|
case STATE_UNCALIBRATED: state_str = "UNCALIBRATED"; break;
|
|
|
|
|
|
case STATE_CALIBRATING: state_str = "CALIBRATING..."; break;
|
|
|
|
|
|
case STATE_READY: state_str = "READY"; break;
|
|
|
|
|
|
case STATE_SKIING: state_str = "SKIING"; break;
|
|
|
|
|
|
case STATE_STOPPED: state_str = "STOPPED"; break;
|
|
|
|
|
|
}
|
2025-10-29 16:24:16 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
// // 转换为 km/h
|
|
|
|
|
|
// float velocity_kmh = skiing_data.velocity * 3.6f;
|
|
|
|
|
|
|
|
|
|
|
|
// printf("State: %s, Slope: %.1f deg, Vel: %.2f km/h, Dist: %.2f m\n",
|
|
|
|
|
|
// state_str,
|
|
|
|
|
|
// skiing_data.slope_angle_deg,
|
|
|
|
|
|
// velocity_kmh,
|
|
|
|
|
|
// skiing_data.distance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signed short acc_raw[3], gyr_raw[3];
|
|
|
|
|
|
|
|
|
|
|
|
// 读取原始数据
|
|
|
|
|
|
SL_SC7U22_RawData_Read(acc_raw, gyr_raw);
|
|
|
|
|
|
|
|
|
|
|
|
// 将原始数据送入追踪器进行处理
|
|
|
|
|
|
SkiingTracker_Update(&skiing_data, acc_raw, gyr_raw);
|
|
|
|
|
|
|
|
|
|
|
|
// 清空发送缓冲区
|
|
|
|
|
|
memset(ble_send_data, 0, sizeof(ble_send_data));
|
|
|
|
|
|
|
|
|
|
|
|
// 准备要填充的数据
|
|
|
|
|
|
// 状态
|
|
|
|
|
|
char state_code = (char)skiing_data.state;
|
|
|
|
|
|
|
|
|
|
|
|
// 坡度 (舍弃小数)
|
|
|
|
|
|
char slope_angle = (char)skiing_data.slope_angle_deg;
|
|
|
|
|
|
|
|
|
|
|
|
// 速度 km/h (舍弃小数)
|
|
|
|
|
|
float velocity_kmh_float = skiing_data.velocity * 3.6f;
|
|
|
|
|
|
// 使用 uint16_t 来存储速度,因为它可能超过255
|
|
|
|
|
|
uint16_t velocity_kmh_int = (uint16_t)velocity_kmh_float;
|
|
|
|
|
|
|
|
|
|
|
|
// 距离 (m)
|
|
|
|
|
|
// 使用 uint32_t 来存储距离,因为它会变得很大
|
|
|
|
|
|
uint32_t distance_int = (uint32_t)skiing_data.distance;
|
|
|
|
|
|
|
|
|
|
|
|
// 按顺序填充到 ble_send_data 数组中
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 字节 0: 状态码 (1 byte)
|
|
|
|
|
|
ble_send_data[index++] = state_code;
|
|
|
|
|
|
|
|
|
|
|
|
// 字节 1: 坡度 (1 byte)
|
|
|
|
|
|
ble_send_data[index++] = slope_angle;
|
|
|
|
|
|
|
|
|
|
|
|
// 字节 2-3: 速度 (2 bytes, 小端模式)
|
|
|
|
|
|
// 将 16 位的速度拆分成两个 8 位的 char
|
|
|
|
|
|
ble_send_data[index++] = (char)(velocity_kmh_int & 0xFF); // 低8位
|
|
|
|
|
|
ble_send_data[index++] = (char)((velocity_kmh_int >> 8) & 0xFF); // 高8位
|
|
|
|
|
|
|
|
|
|
|
|
// 字节 4-7: 距离 (4 bytes, 小端模式)
|
|
|
|
|
|
// 将 32 位的距离拆分成四个 8 位的 char
|
|
|
|
|
|
ble_send_data[index++] = (char)(distance_int & 0xFF); // 最低8位
|
|
|
|
|
|
ble_send_data[index++] = (char)((distance_int >> 8) & 0xFF);
|
|
|
|
|
|
ble_send_data[index++] = (char)((distance_int >> 16) & 0xFF);
|
|
|
|
|
|
ble_send_data[index++] = (char)((distance_int >> 24) & 0xFF); // 最高8位
|
|
|
|
|
|
|
|
|
|
|
|
send_data_to_ble_client(ble_send_data, index);
|
|
|
|
|
|
|
|
|
|
|
|
printf("State: %s, Slope: %.1f deg, Vel: %.2f km/h, Dist: %.2f m\n",
|
|
|
|
|
|
state_str,
|
|
|
|
|
|
skiing_data.slope_angle_deg,
|
|
|
|
|
|
velocity_kmh_float,
|
|
|
|
|
|
skiing_data.distance);
|
|
|
|
|
|
|
2025-10-29 16:24:16 +08:00
|
|
|
|
}
|
2025-11-03 18:48:15 +08:00
|
|
|
|
u16 test_id=0;
|
|
|
|
|
|
void xtell_task_create(void){
|
2025-10-29 16:24:16 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
// int ret = hw_iic_init(0);
|
|
|
|
|
|
// xlog("hw_iic_init result:%d\n",ret);
|
|
|
|
|
|
// //初始化传感器
|
|
|
|
|
|
// SL_SC7U22_Config();
|
2025-10-29 16:24:16 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
soft_iic_init(0);
|
|
|
|
|
|
gpio_set_direction(IO_PORTE_05,0); //设置PE5 输出模式
|
|
|
|
|
|
gpio_set_pull_up(IO_PORTE_05,1);
|
|
|
|
|
|
gpio_direction_output(IO_PORTE_05,1);
|
2025-10-31 16:58:39 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
SL_SC7U22_Config();
|
|
|
|
|
|
// extern u8 LIS2DH12_Config(void);
|
|
|
|
|
|
// LIS2DH12_Config();
|
2025-10-30 11:33:38 +08:00
|
|
|
|
|
2025-10-30 18:30:40 +08:00
|
|
|
|
xlog("xtell_task_create\n");
|
2025-10-30 11:33:38 +08:00
|
|
|
|
// 初始化环形缓冲区
|
|
|
|
|
|
circle_buffer_init(&sensor_cb, sensor_data_buffer, SENSOR_DATA_BUFFER_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
//初始化滑雪追踪器
|
|
|
|
|
|
// SkiingTracker_Init(&skiing_data);
|
|
|
|
|
|
xlog("SkiingTracker_Init\n");
|
2025-10-30 11:33:38 +08:00
|
|
|
|
|
2025-11-03 18:48:15 +08:00
|
|
|
|
create_process(&test_id, "test",NULL, sensor_test, 10);
|
2025-10-30 11:33:38 +08:00
|
|
|
|
|
|
|
|
|
|
}
|