From: penglei <1624952103@qq.com> Date: Wed, 10 Apr 2024 12:28:48 +0000 (+0800) Subject: 添加自由训练模式心率区间输出 X-Git-Tag: release_V1.2.70_20241020_135402~1216 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=9a41aac033c624870f9d908b257ec648b0d88abb;p=mirrors%2FFD230.git 添加自由训练模式心率区间输出 --- diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index cc6647b53..9059742d9 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -446,6 +446,7 @@ typedef struct int max_step_freq; int max_pace; int ar_alert_type; + int MHR_zone; }cywee_result_t; #pragma pack() typedef enum{ @@ -460,6 +461,9 @@ typedef enum{ } cywee_msg_type_t; +#define RAISE_HAND 1 +#define DROP_HAND 2 + extern void get_gsonsen_xyz(gsenson_t *t); void gsensor_get_n_data(uint8_t cnt,gsenson_t t[]); diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h index 767a405d4..f1218419c 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h @@ -64,7 +64,6 @@ void uapi_cywee_service_deinit(void); */ void do_cywee_service_check_msg(int cmd); -void do_cywee_service_check_msg(int cmd); #ifdef __cplusplus } diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c index c1968c8df..e8b094532 100644 --- a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c @@ -112,8 +112,8 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen //自由运动模式 case CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE: PRINT("CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE"); - PRINT("activit_mode[%d], calories[%d], duration[%d],len[%d]\n", - c_result_t.activity_mode,c_result_t.calories,c_result_t.duration,sizeof(c_result_t)); + PRINT("activit_mode[%d], calories[%d], duration[%d], MHR_zone[%d],len[%d]\n", + c_result_t.activity_mode,c_result_t.calories,c_result_t.duration,c_result_t.MHR_zone,sizeof(c_result_t)); CustomEventPublish(TOPIC_EVENT_FREE_TRAINING_UPDATE,&c_result_t,sizeof(c_result_t)); break; @@ -207,12 +207,11 @@ static void cywee_service_check_task(void const *arg) test_api(); }else if (mail.cmd == CYWEE_SERVICE_CMD_START_CHECK){ cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_NORMAL); + //cywee_main_dml(SPORT_ACTIVE_MODE_NORMAL); cywee_service_timer_start_check(CYWEE_CHECK_MS); }else if (mail.cmd == CYWEE_SERVICE_CMD_STOP_CHECK){ cywee_service_running_stat = false; if (g_cywee_service_timer != NULL) osTimerStop(g_cywee_service_timer); - activity_exit(); } else if (mail.cmd == CYWEE_SERVICE_CMD_NORMAL_MODE){ @@ -248,8 +247,9 @@ static void cywee_service_check_task(void const *arg) }else if(mail.cmd == CYWEE_SERVICE_CMD_RESUME){ activity_setstatus(0); }else if(mail.cmd == CYWEE_SERVICE_CMD_EXIT){ + cywee_service_running_stat = false; + if (g_cywee_service_timer != NULL) osTimerStop(g_cywee_service_timer); activity_exit(); - osTimerStop(g_cywee_service_timer); } #define CYWEE_SERVICE_CMD_PAUSE 0x22 diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 88f8c04ef..d88e0919e 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -11,6 +11,7 @@ #include "osal_msgqueue.h" #include "osal_mutex.h" #include "ppg_service.h" +#include "custom_utils.h" #define AP_ENABLE_DML_SDO_LISTEN @@ -32,6 +33,68 @@ SettingControl_t scl; cywee_result_t c_result_t; static int cywee_installized = 0 ; +static int free_training_installized = 0 ; + +static osTimerId_t g_cywee_hrs_timer; + +// static osTimerId_t g_cywee_wearstatus_timer; + +static osTimerId_t g_cywee_oncharging_timer; + +CustomSensorData csd; + +void free_training_task(void) +{ + ppg_send_cmd_to_driver("hrs",1); +} + +errcode_t free_training_init(void) +{ + app_task_definition_t taskcfg={0}; + taskcfg.create_queue_handle = NULL; + taskcfg.attr.name="free_training_service"; + taskcfg.attr.priority = TASK_PRIORITY_CMD; + taskcfg.attr.stack_size = 1024*8; + taskcfg.func = free_training_task; + taskcfg.use_mem = USE_EXTEND_MEM; + + errcode_t ret=uapi_create_osThread_custom(&taskcfg); + if(ret != ERRCODE_SUCC) + { + PRINT("create free_training_task failed %d!\r\n",ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + + +void cywee_hrs_check_timer_callback(void) +{ + uint8_t hrs,wearstatus; + get_hrs_wearstatus(&hrs,&wearstatus); + CWM_OS_dbgPrintf("hrs : %d,wearstatus : %d \r\n",hrs,wearstatus); + memset(&csd, 0, sizeof(CUSTOM_HEARTRATE)); + csd.sensorType = CUSTOM_HEARTRATE; + csd.fData[0] = hrs + 15; + CWM_CustomSensorInput(&csd); + memset(&csd, 0, sizeof(CUSTOM_OFFBODY_DETECT)); + csd.sensorType = CUSTOM_OFFBODY_DETECT; + csd.fData[0] = wearstatus; + CWM_CustomSensorInput(&csd); +} + +void cywee_oncharging_check_timer_callback(void) +{ + bool oncharging_status; + oncharging_status = uapi_get_charger_plug_status(); + //CWM_OS_dbgPrintf("charging_status : %d\r\n",oncharging_status); + memset(&csd, 0, sizeof(CUSTOM_ON_CHARGING)); + csd.sensorType = CUSTOM_ON_CHARGING; + csd.fData[0] = oncharging_status; + CWM_CustomSensorInput(&csd); +} + void watch_hand_updown(int fdata) { @@ -70,8 +133,19 @@ void activity_exit(void) memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; CWM_SettingControl(SCL_REQ_ACTIVITY_EXIT, &scl); - cywee_installized = 0; - CWM_Sensor_Disable(IDX_ALGO_ACTIVITY_OUTPUT); + + if(cywee_installized == 1) + cywee_installized = 0; + if(free_training_installized == 1) + { + free_training_installized = 0; + //osTimerStop(g_cywee_wearstatus_timer); + osTimerStop(g_cywee_oncharging_timer); + osTimerStop(g_cywee_hrs_timer); + osTimerDelete(g_cywee_oncharging_timer); + osTimerDelete(g_cywee_hrs_timer); + ppg_send_cmd_to_driver("hrs",0); + } } void cyw_mode_init(int mode) @@ -124,6 +198,8 @@ void cyw_mode_init(int mode) //自由运动 case SPORT_ACTIVE_MODE_FREE_TRAINING: + free_training_installized = 1; + free_training_init(); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = SPORT_ACTIVE_MODE_FREE_TRAINING; @@ -135,7 +211,6 @@ void cyw_mode_init(int mode) // break; case 2: - PRINT("222\r\n"); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = 2; @@ -143,7 +218,6 @@ void cyw_mode_init(int mode) break; case 1: - PRINT("333\r\n"); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = 1; @@ -198,7 +272,6 @@ void gsensor_get_n_data(uint8_t cnt,gsenson_t t[]) void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { cywee_msg_callback_t cywee_func; - switch (sensorEVT->sensorType) { case IDX_ACCEL: @@ -268,26 +341,24 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { CWM_OS_dbgPrintf("IDX_REQUEST_SENSOR input_sensor[%d][%s] (0: acc, 1: gyro, 2: mag, 3: baro, 4: temperature, 5: heart_rate, 6: GNSS(GPS), 7: off-body detect 8: on-charging detect 9: acc_any_motion)\n", (int)sensorEVT->fData[1], (int)sensorEVT->fData[2]==0?"off":"on"); - CustomSensorData csd; if((int)sensorEVT->fData[1] == CUSTOM_OFFBODY_DETECT) { - // [0] = off-body state -// (0: device is off-body(未戴身上) , 1: device is on-body(戴在身上)) - memset(&csd, 0, sizeof(CustomSensorData)); - csd.sensorType = CUSTOM_OFFBODY_DETECT; - csd.fData[0] = 1; - CWM_CustomSensorInput(&csd); + CWM_OS_dbgPrintf("CUSTOM_OFFBODY_DETECT !!! \r\n"); + // if(free_training_installized == 1) + // osTimerStart(g_cywee_wearstatus_timer,20); } if((int)sensorEVT->fData[1] == CUSTOM_ON_CHARGING) { - // [0] = On-Charging state -// (0: 裝置未連接充電裝置, 1: 裝置連接充電裝置) - memset(&csd, 0, sizeof(CustomSensorData)); - csd.sensorType = CUSTOM_ON_CHARGING; - csd.fData[0] = 0; - CWM_CustomSensorInput(&csd); + CWM_OS_dbgPrintf("CUSTOM_ON_CHARGING !!! \r\n"); + //if(free_training_installized == 1) + osTimerStart(g_cywee_oncharging_timer,20); + } + if((int)sensorEVT->fData[1] == CUSTOM_HEARTRATE) + { + CWM_OS_dbgPrintf("CUSTOM_HEARTRATE !!! \r\n"); + if(free_training_installized == 1) + osTimerStart(g_cywee_hrs_timer,20); } - break; case IDX_ALGO_SHAKE: CWM_OS_dbgPrintf("IDX_ALGO_SHAKE\n"); @@ -329,14 +400,16 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { }else if((int)sensorEVT->fData[0] == 5001) { - CWM_OS_dbgPrintf("Free_Training : calories[%d], duration[%d]\n", + CWM_OS_dbgPrintf("Free_Training : calories[%d], duration[%d], MHR_zone[%d]\n", (int)sensorEVT->fData[1], - (int)sensorEVT->fData[5]); + (int)sensorEVT->fData[5], + (int)sensorEVT->fData[6]); memset(&c_result_t,0,sizeof(cywee_result_t)); c_result_t.activity_mode = (int)sensorEVT->fData[0]; c_result_t.calories = (int)sensorEVT->fData[1]; c_result_t.duration = (int)sensorEVT->fData[5]; + c_result_t.MHR_zone = (int)sensorEVT->fData[6]; cywee_func = cywee_get_send_msg_callback_func(); cywee_func(CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE,&c_result_t,sizeof(cywee_result_t)); @@ -708,14 +781,14 @@ int[12] = 靜態活動角度靈敏度 (default: 13) (0: default, 1: 較難入睡 - 30: 容易入睡) */ - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[3] = 7; - scl.iData[4] = 7; - scl.iData[6] = 7; - scl.iData[7] = 7; - scl.iData[9] = 1; - CWM_SettingControl(SCL_SLEEP_CONFIG, &scl); + // memset(&scl, 0, sizeof(scl)); + // scl.iData[0] = 1; + // scl.iData[3] = 7; + // scl.iData[4] = 7; + // scl.iData[6] = 7; + // scl.iData[7] = 7; + // scl.iData[9] = 1; + // CWM_SettingControl(SCL_SLEEP_CONFIG, &scl); /* SCL_REQ_SLEEPING_DATA @@ -724,10 +797,10 @@ int[1] = terminate_sleep (0: 立刻輸出狀態,但不中止此段睡眠偵測, 1: 立刻輸出狀態,並中止此段睡眠偵測) */ - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 1; - CWM_SettingControl(SCL_REQ_SLEEPING_DATA, &scl); + // memset(&scl, 0, sizeof(scl)); + // scl.iData[0] = 1; + // scl.iData[1] = 1; + // CWM_SettingControl(SCL_REQ_SLEEPING_DATA, &scl); /* SCL_INACTIVITY_CONFIG @@ -750,20 +823,21 @@ int[1] = 感測器雜訊度等級 (default: 低雜訊) int[5] = minute (0 - 59) int[6] = second (0 - 59) */ - char databuf[64] = {0}; - int year,month,day,hour,min,sec; - uapi_get_yyyymmddhhmmss_Date(databuf); - PRINT("databuf : %s \r\n",databuf); - sscanf(databuf, "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &min, &sec); - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = year; - scl.iData[2] = month; - scl.iData[3] = day; - scl.iData[4] = hour; - scl.iData[5] = min; - scl.iData[6] = sec; - CWM_SettingControl(SCL_DATE_TIME, &scl); + + // char databuf[64] = {0}; + // int year,month,day,hour,min,sec; + // uapi_get_yyyymmddhhmmss_Date(databuf); + // PRINT("databuf : %s \r\n",databuf); + // sscanf(databuf, "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &min, &sec); + // memset(&scl, 0, sizeof(scl)); + // scl.iData[0] = 1; + // scl.iData[1] = year; + // scl.iData[2] = month; + // scl.iData[3] = day; + // scl.iData[4] = hour; + // scl.iData[5] = min; + // scl.iData[6] = sec; + // CWM_SettingControl(SCL_DATE_TIME, &scl); /* SCL_SEDENTARY @@ -804,7 +878,11 @@ int[5] = release_mode (解除久坐的算法模式)(default: 行走模式) scl.iData[3] = 3; scl.iData[4] = 5; // CWM_SettingControl(SCL_LOG, &scl); + + g_cywee_hrs_timer = osTimerNew((osTimerFunc_t)cywee_hrs_check_timer_callback, osTimerPeriodic, NULL, NULL); + //g_cywee_wearstatus_timer = osTimerNew((osTimerFunc_t)cywee_wearstatus_check_timer_callback, osTimerPeriodic, NULL, NULL); + g_cywee_oncharging_timer = osTimerNew((osTimerFunc_t)cywee_oncharging_check_timer_callback, osTimerPeriodic, NULL, NULL); CWM_Sensor_Enable(IDX_REQUEST_SENSOR); // //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); @@ -822,6 +900,7 @@ int[5] = release_mode (解除久坐的算法模式)(default: 行走模式) //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); CWM_Sensor_Enable(IDX_ALGO_WATCH_HANDUP); + cyw_mode_init(cmd); // memset(&scl, 0, sizeof(scl)); diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 91c768736..819e1c14e 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -117,6 +117,8 @@ uint8_t alg_ram[11 * 1024] __attribute__((aligned(4))); //uint8_t alg_ram[10] = {0}; ppg_sensor_data_t ppg_s_data; +uint8_t free_trainning_hrs = 0; +uint8_t free_trainning_wearstatus = 0; //////// spo2 para and switches const uint8_t COUNT_BLOCK_NUM = 25; //delay the block of some single good signal after a series of bad signal @@ -146,8 +148,6 @@ uint8_t ble_hrs_flag = 0; int32_t ble_spo2_data = 0; uint8_t ble_spo2_flag = 0; - - #ifdef SPO2_DATA_CALI static int32_t red_data_fifo[4] = {0}; static int32_t ir_data_fifo[4] = {0}; @@ -160,6 +160,13 @@ static int32_t ir_jump_delta = 0; static int32_t cali_data_cnt = 0; #endif +void get_hrs_wearstatus(uint8_t *hrs,uint8_t *wearstatus) +{ + *hrs = free_trainning_hrs; + *wearstatus = free_trainning_wearstatus; +} + + // us 延时函数, 客户需填写 void hx3695_delay_us(uint32_t us) { @@ -2732,7 +2739,7 @@ void hx3695_hrs_ppg_Int_handle(void) // result.ir_data_final = hrs_s_dat.ir_data[0]; // hx3695_factory_test_process(NULL, APP_FACTORY_TEST_HR_START, &result); - //gsensor_get_n_data(8,gsensordata); + //gsensor_get_n_data(1,gsensordata); // for(ii=0; ii<*count; ii++) // { @@ -2753,12 +2760,12 @@ void hx3695_hrs_ppg_Int_handle(void) // } hrs_wear_status = hx3695_hrs_get_wear_status(); - PRINT("hrs_wear_status: %d !!\r\n", hrs_wear_status); - + PRINT("hrs_wear_status: %d !!\r\n", hrs_wear_status); + if(hrs_wear_status == MSG_HRS_WEAR) { tyhx_hrs_alg_send_data(PPG_buf, *count, gsen_fifo_x_send, gsen_fifo_y_send, - gsen_fifo_z_send, cal.Group1_Ledidac); + gsen_fifo_z_send, cal.Group1_Ledidac); } #endif @@ -2787,15 +2794,19 @@ void hx3695_hrs_ppg_Int_handle(void) uint8_t curr_wear = 1; //uint8_t last_wear = cwm_get_wear_status(); - alg_results = tyhx_hrs_alg_get_results(); - hrsresult.lastesthrs = alg_results.hr_result; - hrsresult.hr_living = alg_results.living_status; - hrsresult.hr_living_qu = alg_results.hr_result_qual; - hrsresult.hr_living_std = alg_results.hr_result_std; + alg_results = tyhx_hrs_alg_get_results(); + hrsresult.lastesthrs = alg_results.hr_result; + hrsresult.hr_living = alg_results.living_status; + hrsresult.hr_living_qu = alg_results.hr_result_qual; + hrsresult.hr_living_std = alg_results.hr_result_std; PRINT("hx3695 data_cnt: %d, hr_living: %d, hr_living_qu: %d, hr_living_std: %d, hr_result:%d \r\n", alg_results.data_cnt, hrsresult.hr_living, hrsresult.hr_living_qu, hrsresult.hr_living_std, hrsresult.lastesthrs); + free_trainning_hrs = hrsresult.lastesthrs; + free_trainning_wearstatus = hrs_wear_status; + + if(hrsresult.lastesthrs > 0) { ble_hrs_flag = 1; @@ -3471,5 +3482,4 @@ void hx3695_lab_test_Int_handle(void) } #endif - #endif //CHIP_HX3695 diff --git a/code/sdk/drivers/peripheral/ppg/service/ppg_service.h b/code/sdk/drivers/peripheral/ppg/service/ppg_service.h index 983767020..9f4e5e27a 100644 --- a/code/sdk/drivers/peripheral/ppg/service/ppg_service.h +++ b/code/sdk/drivers/peripheral/ppg/service/ppg_service.h @@ -1,3 +1,13 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-03-27 09:07:00 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-04-10 11:23:48 + * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/service/ppg_service.h + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ /** * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n * @@ -42,6 +52,8 @@ int ppg_service_get_iAccuracy(void); uint32_t ppg_suspend(void); uint32_t ppg_resume(void); +void get_hrs_wearstatus(uint8_t *hrs,uint8_t *wearstatus); + typedef enum { PPG_TEST_MODE_HRS, PPG_TEST_MODE_SPO2,