From 1d2d93b21d7a8538b2d4930f2e88882b1778e714 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BD=AD=E7=A3=8A?= <1624952103@qq.com> Date: Fri, 19 Apr 2024 10:11:44 +0000 Subject: [PATCH] Merge #53 into xts_origin from refs/changes/53/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 优化运动切换与静态模式切换,优化动态心率计算,添加抬腕亮屏开关 * refs/changes/53/head: (1 commits squashed) - 优化运动切换与静态模式切换,优化动态心率计算,添加抬腕亮屏开关 Signed-off-by: aliyun6865282430 <1624952103@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/53 --- .../drivers/peripheral/cywee/Inc/cywee_hal.h | 8 +- .../peripheral/cywee/Inc/cywee_service.h | 6 +- .../peripheral/cywee/service/cywee_service.c | 42 +- .../drivers/peripheral/cywee/src/main_dml.c | 524 +++++++++--------- .../drivers/peripheral/ppg/hx3695/hx3695.c | 13 +- .../peripheral/ppg/hx3695/hx3695_hrs_custom.c | 6 +- .../drivers/peripheral/utils/custom_utils.c | 21 +- 7 files changed, 316 insertions(+), 304 deletions(-) diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 48f4ee4af..8fbb26024 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -525,13 +525,15 @@ extern uint8_t hrs_mode_state; -int cywee_main_dml(int cmd); +int cywee_main_dml(void); void cywee_int_handler(void); -void watch_hand_updown(int fdata); +void set_user_info(int age,int gender,double weight,int height,int wearing_method); + void cyw_inactivity_mode_change(int mode); void cyw_activity_mode_change(int mode); -void set_user_info(int age,int gender,double weight,int height,int wearing_method); + +void hand_updown_switch(int cmd); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h index 1ccade082..0260d846d 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-03-26 20:29:58 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-04-18 11:43:11 + * @LastEditTime: 2024-04-19 18:00:31 * @FilePath: /FD230/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h * @Description: * @@ -59,6 +59,10 @@ extern "C" { #define CYWEE_SERVICE_CMD_ONCHARGING_CHANGE 0x20 #define CYWEE_SERVICE_CMD_HRS_WEARSTATUS_CHANGE 0x21 +#define CYWEE_SERVICE_CMD_SEDENTARY_MODE 0x22 +#define CYWEE_SERVICE_CMD_NAP_MODE 0x23 +#define CYWEE_SERVICE_CMD_SLEEPING_MODE 0x24 + errcode_t uapi_cywee_service_init(void); void uapi_cywee_service_deinit(void); diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c index 0aaa6e976..a546e163a 100644 --- a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c @@ -280,7 +280,7 @@ static void cywee_service_check_task(void const *arg) else if (mail.cmd == CYWEE_SERVICE_CMD_START_CHECK) { cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_NORMAL); + cywee_main_dml(); cywee_service_timer_start_check(CYWEE_CHECK_MS); } else if (mail.cmd == CYWEE_SERVICE_CMD_STOP_CHECK) @@ -291,45 +291,31 @@ static void cywee_service_check_task(void const *arg) } else if (mail.cmd == CYWEE_SERVICE_CMD_NORMAL_MODE) { - cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_NORMAL); - cywee_service_timer_start_check(CYWEE_CHECK_MS); + cyw_activity_mode_change(SPORT_ACTIVE_MODE_NORMAL); } else if (mail.cmd == CYWEE_SERVICE_CMD_TREADMILL_MODE) { - cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_TREADMILL); - cywee_service_timer_start_check(CYWEE_CHECK_MS); + cyw_activity_mode_change(SPORT_ACTIVE_MODE_TREADMILL); } else if (mail.cmd == CYWEE_SERVICE_CMD_OUTDOOR_RUNNING_MODE) { - cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_OUTDOOR_RUNNING); - cywee_service_timer_start_check(CYWEE_CHECK_MS); + cyw_activity_mode_change(SPORT_ACTIVE_MODE_OUTDOOR_RUNNING); } else if (mail.cmd == CYWEE_SERVICE_CMD_INDOOR_RUNNING_MODE) { - cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_INDOOR_RUNNING); - cywee_service_timer_start_check(CYWEE_CHECK_MS); + cyw_activity_mode_change(SPORT_ACTIVE_MODE_INDOOR_RUNNING); } else if (mail.cmd == CYWEE_SERVICE_CMD_FITNESS_PEDOMETER_MODE) { - cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_FITNESS_PEDOMETERR); - cywee_service_timer_start_check(CYWEE_CHECK_MS); + cyw_activity_mode_change(SPORT_ACTIVE_MODE_FITNESS_PEDOMETERR); } else if (mail.cmd == CYWEE_SERVICE_CMD_FREE_TRAINING_MODE) { - cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_FREE_TRAINING); - cywee_service_timer_start_check(CYWEE_CHECK_MS); + cyw_activity_mode_change(SPORT_ACTIVE_MODE_FREE_TRAINING); } else if (mail.cmd == CYWEE_SERVICE_CMD_AR_ALERT_MODE) { - cywee_service_running_stat = true; - cywee_main_dml(SPORT_ACTIVE_MODE_AR_ALERT); - cywee_service_timer_start_check(CYWEE_CHECK_MS); + cyw_activity_mode_change(SPORT_ACTIVE_MODE_AR_ALERT); } else if (mail.cmd == CYWEE_SERVICE_CMD_PAUSE) { @@ -351,6 +337,18 @@ static void cywee_service_check_task(void const *arg) { cywee_hrs_wearstatus_update(mail.data[0], mail.data[1]); } + else if (mail.cmd == CYWEE_SERVICE_CMD_SEDENTARY_MODE) + { + cyw_inactivity_mode_change(INACTIVITY_MODE_SEDENTARY); + } + else if (mail.cmd == CYWEE_SERVICE_CMD_NAP_MODE) + { + cyw_inactivity_mode_change(INACTIVITY_MODE_NAP); + } + else if (mail.cmd == CYWEE_SERVICE_CMD_SLEEPING_MODE) + { + cyw_inactivity_mode_change(INACTIVITY_MODE_SLEEPING); + } } } #define CYWEE_APP_BOARD_MSG_COUNT 50 diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 5eb9708f9..80ac1e8ea 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -19,13 +19,13 @@ #define AP_ENABLE_DML_SDO_LISTEN -#define GSENSON_MSG_COUNT 16 +#define GSENSON_MSG_COUNT 8 static gsenson_t gxyz_t; static uint8_t gsenson_falg=0; static uint16 num_falg=0; -static gsenson_t gxyz_t_queue[16]={0}; +static gsenson_t gxyz_t_queue[8]={0}; static int16 left_falg=0; static int16 right_falg=-1; @@ -39,11 +39,15 @@ CustomSensorData csd; static uint8_t hrs = 0; - uint8_t hrs_mode_state = 0; - -static uint8_t mail = 0; +void hand_updown_switch(int cmd) +{ + if(cmd == 1) + CWM_Sensor_Enable(IDX_ALGO_WATCH_HANDUP); + else + CWM_Sensor_Disable(IDX_ALGO_WATCH_HANDUP); +} void get_sleep_data(void) { @@ -125,23 +129,7 @@ void cywee_wearstatus_update(int wearstatus) CWM_CustomSensorInput(&csd); } -void activity_mode_init(void) -{ - if(hrs_mode_state == 1) - { - send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST); - hrs_mode_state = 0; - } - if(mail == 1 && hrs_mode_state == 0) - { - send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_PPG_TEST); - hrs_mode_state = 1; - }else if(mail == 2) - { - send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_WEAR_MODE_TEST); - } -} //0:resume , 1:pause void activity_mode_setstatus(int cmd) @@ -216,7 +204,6 @@ void cyw_inactivity_mode_change(int mode) void cyw_activity_mode_change(int mode) { - activity_mode_init(); switch (mode) { //一般模式(生活模式) @@ -302,7 +289,7 @@ void gsensor_get_n_data(uint8_t cnt,gsenson_t t[]) if(num_falg) { left_falg++; - left_falg=left_falg%16; + left_falg=left_falg%8; num_falg--; } @@ -313,19 +300,18 @@ void gsensor_get_n_data(uint8_t cnt,gsenson_t t[]) //static int flag=32; void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { - cywee_msg_callback_t cywee_func; switch (sensorEVT->sensorType) { case IDX_ACCEL: #if 1 - if(num_falg==16) + if(num_falg==8) { left_falg++; right_falg++; - right_falg=right_falg%16; - left_falg=left_falg%16; + right_falg=right_falg%8; + left_falg=left_falg%8; gxyz_t_queue[right_falg].x= sensorEVT->fData[0]; gxyz_t_queue[right_falg].y= sensorEVT->fData[1]; gxyz_t_queue[right_falg].z= sensorEVT->fData[2]; @@ -334,7 +320,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { { //left_falg++; right_falg++; - right_falg=right_falg%16; + right_falg=right_falg%8; //left_falg=left_falg%16; num_falg++; gxyz_t_queue[right_falg].x= sensorEVT->fData[0]; @@ -372,7 +358,25 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { break; case IDX_ALGO_WATCH_HANDUP: CWM_OS_dbgPrintf("HANDUP_DOWN MSG [%d]\n",(int)sensorEVT->fData[1]); - uapi_take_to_wake((int)sensorEVT->fData[1]); + #if defined(SUPPORT_POWER_MANAGER) + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + #endif + if ((int)sensorEVT->fData[1] == 2) + { + #if defined(SUPPORT_POWER_MANAGER) + display_api->set_screen_set_keepon_timeout(0); + PRINT("[cwyee] turn_off_screen"); + #endif + }else if ((int)sensorEVT->fData[1] == 1) + { + #if defined(SUPPORT_POWER_MANAGER) + if (display_api->get_screen_state() != SCREEN_ON) { + PRINT("[cwyee] turn_on_screen"); + display_api->turn_on_screen(); + } + display_api->set_screen_set_keepon_timeout(5000); + #endif + } break; case IDX_ALGO_SLEEP: CWM_OS_dbgPrintf("IDX_ALGO_SLEEP\n"); @@ -388,7 +392,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { { memset(&csd, 0, sizeof(CUSTOM_OFFBODY_DETECT)); csd.sensorType = CUSTOM_OFFBODY_DETECT; - csd.fData[0] = 0; + csd.fData[0] = 1; CWM_CustomSensorInput(&csd); } } @@ -399,13 +403,23 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { { memset(&csd, 0, sizeof(CUSTOM_ON_CHARGING)); csd.sensorType = CUSTOM_ON_CHARGING; - csd.fData[0] = 1; + csd.fData[0] = 0; CWM_CustomSensorInput(&csd); } } if((int)sensorEVT->fData[1] == CUSTOM_HEARTRATE) { CWM_OS_dbgPrintf("CUSTOM_HEARTRATE !!! \r\n"); + if((int)sensorEVT->fData[2] == 1) + { + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_PPG_TEST); + hrs_mode_state = 1; + } + else + { + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST); + hrs_mode_state = 0; + } } break; case IDX_ALGO_SHAKE: @@ -416,10 +430,13 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { CWM_OS_dbgPrintf("IDX_ALGO_INACTIVITY_OUTPUT\n"); if((int)sensorEVT->fData[0] == 20) { - CWM_OS_dbgPrintf("inactivity_mode_number[%d], sedentary status[%d], stand freq[%d]\n", + CWM_OS_dbgPrintf("inactivity_mode_number[%d], sedentary status[%d], stand freq[%d], day[%d], hour[%d], min[%d]\n", (int)sensorEVT->fData[15], (int)sensorEVT->fData[2], - (int)sensorEVT->fData[3]); + (int)sensorEVT->fData[3], + (int)sensorEVT->fData[8], + (int)sensorEVT->fData[9], + (int)sensorEVT->fData[10]); memset(&c_inactivity_result_t,0,sizeof(cywee_inactivity_result_t)); c_inactivity_result_t.inactivity_mode = (int)sensorEVT->fData[15]; c_inactivity_result_t.sedentary_status = (int)sensorEVT->fData[2]; @@ -623,233 +640,236 @@ void CWM_AP_dmlSensorDataOutput_listen(const dml_sensorData_t * pSdo) { #endif -int cywee_main_dml(int cmd) +int cywee_main_dml(void) { - if(cmd == SPORT_ACTIVE_MODE_NORMAL) - mail = 2; - else - mail = 1; - - if (cywee_installized==0) + if (cywee_installized == 1) { - cywee_installized = 1; - int i; - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - CWM_SettingControl(SCL_GET_LIB_INFO, &scl); - CWM_OS_dbgPrintf("version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]); - CWM_OS_dbgPrintf("[DBG] ach: %d\n", scl.iData[7]); - #if USE_P813 - os_api api = { - .GetTimeNs = CWM_OS_GetTimeNs, - .dbgOutput = CWM_OS_dbgOutput, - .i2cRead = CWM_OS_i2cRead, - .i2cWrite = CWM_OS_i2cWrite, - .uSleep = CWM_OS_uSleep, - .free = CWM_OS_free, - .malloc = CWM_OS_malloc, - .spiRead = NULL, - .spiWrite = NULL, - }; - CWM_LibPreInit(&api); - - #else - OsAPI apiOS = { - .GetTimeNs = CWM_OS_GetTimeNs, - .dbgOutput = CWM_OS_dbgOutput, - .i2cRead = CWM_OS_i2cRead, - .i2cWrite = CWM_OS_i2cWrite, - .uSleep = CWM_OS_uSleep, - .free = CWM_OS_free, - .malloc = CWM_OS_malloc, - .i2cTransfer = CWM_OS_i2cTransfer, - .restoreData = CWM_OS_restoreData, - .saveData = CWM_OS_saveData, - .spiRead = NULL, - .spiWrite = NULL, - .securityCodeWrite = NULL, - .setGpio = NULL, - .enableGpioIRQ = NULL, - .disableGpioIRQ = NULL, - }; - CWM_LibPreInit(&apiOS); - #endif - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + CWM_OS_dbgPrintf("cywee installized !!! \r\n"); + return 0; + } - //set mcu_chip information, must call this before CWM_LibPostInit() + cywee_installized = 1; + int i; + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_GET_LIB_INFO, &scl); + CWM_OS_dbgPrintf("version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]); + CWM_OS_dbgPrintf("[DBG] ach: %d\n", scl.iData[7]); +#if USE_P813 + os_api api = { + .GetTimeNs = CWM_OS_GetTimeNs, + .dbgOutput = CWM_OS_dbgOutput, + .i2cRead = CWM_OS_i2cRead, + .i2cWrite = CWM_OS_i2cWrite, + .uSleep = CWM_OS_uSleep, + .free = CWM_OS_free, + .malloc = CWM_OS_malloc, + .spiRead = NULL, + .spiWrite = NULL, + }; + CWM_LibPreInit(&api); + +#else + OsAPI apiOS = { + .GetTimeNs = CWM_OS_GetTimeNs, + .dbgOutput = CWM_OS_dbgOutput, + .i2cRead = CWM_OS_i2cRead, + .i2cWrite = CWM_OS_i2cWrite, + .uSleep = CWM_OS_uSleep, + .free = CWM_OS_free, + .malloc = CWM_OS_malloc, + .i2cTransfer = CWM_OS_i2cTransfer, + .restoreData = CWM_OS_restoreData, + .saveData = CWM_OS_saveData, + .spiRead = NULL, + .spiWrite = NULL, + .securityCodeWrite = NULL, + .setGpio = NULL, + .enableGpioIRQ = NULL, + .disableGpioIRQ = NULL, + }; + CWM_LibPreInit(&apiOS); +#endif + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 2; // 0: mcu_auto_detect 2: skip_mcu_auto_detect - CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + //set mcu_chip information, must call this before CWM_LibPostInit() - CWM_LibPostInit(CWM_AP_SensorListen); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - //get chip information - - char chipInfo[64]; - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 1; - scl.iData[2] = (int)chipInfo; - scl.iData[3] = sizeof(chipInfo); - scl.iData[4] = 0; - scl.iData[5] = 0; - scl.iData[6] = 0; - CWM_SettingControl(SCL_GET_CHIP_INFO, &scl); - CWM_OS_dbgPrintf("have_security = %d.%d ret_buff_size = %d chipInfo = %s\n", scl.iData[5], scl.iData[6], scl.iData[4], chipInfo); - CWM_OS_dbgPrintf("chip_settings = %d, %d, %d\n", scl.iData[9], scl.iData[10], scl.iData[11]); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - CWM_Dml_LibInit(); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - #ifdef AP_ENABLE_DML_SDO_LISTEN - // This API allows customers to develop custom features. - // Specific settingControl commands needs to be called for this API to work. - // No need to enable or implement this function for general usage. - CWM_Dml_sensorDataOutput_register(CWM_AP_dmlSensorDataOutput_listen); - #endif - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - CWM_SettingControl(SCL_DML_GET_LIB_INFO, &scl); - CWM_OS_dbgPrintf("dml version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]); - - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 18; //00000000000000000000000000010010 高位在前 - // CWM_SettingControl(SCL_DML_DEBUG, &scl); - - //设置acc gyro 相关参数 - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[7] = 5; //轴向配置 - #if 0 - scl.iData[3] = 2; - scl.iData[4] = 2; //1 anytime 2 fifo - scl.iData[6] = 5; //先設定5 - scl.iData[8] = 52; // for st sensor(52Hz) - #else - scl.iData[3] = 2; - scl.iData[4] = 2; //1 anytime 2 fifo - scl.iData[6] = 5; //fifocount 先設定5 - scl.iData[8] = 25; // for st sensor(52Hz) + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 2; // 0: mcu_auto_detect 2: skip_mcu_auto_detect + CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + CWM_LibPostInit(CWM_AP_SensorListen); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + //get chip information + + char chipInfo[64]; + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 1; + scl.iData[2] = (int)chipInfo; + scl.iData[3] = sizeof(chipInfo); + scl.iData[4] = 0; + scl.iData[5] = 0; + scl.iData[6] = 0; + CWM_SettingControl(SCL_GET_CHIP_INFO, &scl); + CWM_OS_dbgPrintf("have_security = %d.%d ret_buff_size = %d chipInfo = %s\n", scl.iData[5], scl.iData[6], scl.iData[4], chipInfo); + CWM_OS_dbgPrintf("chip_settings = %d, %d, %d\n", scl.iData[9], scl.iData[10], scl.iData[11]); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + CWM_Dml_LibInit(); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + #ifdef AP_ENABLE_DML_SDO_LISTEN + // This API allows customers to develop custom features. + // Specific settingControl commands needs to be called for this API to work. + // No need to enable or implement this function for general usage. + CWM_Dml_sensorDataOutput_register(CWM_AP_dmlSensorDataOutput_listen); #endif - CWM_SettingControl(SCL_DML_DRV_AG_CONFIG, &scl); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - //设定搜寻哪种型号的传感器,以及要搜寻的属性 - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 2; - scl.iData[6] = 3002502; - scl.iData[7] = (0|1|8|256|1024); - CWM_SettingControl(SCL_DML_DRV_HW_CONFIG, &scl); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - //搜寻是否接入传感器 - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 1; - CWM_SettingControl(SCL_DML_DRV_INIT, &scl); - CWM_OS_dbgPrintf("DML device=%d\n", scl.iData[2]); - - //获取初始化 driver清单 - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - CWM_SettingControl(SCL_DML_GET_INITED_LIST, &scl); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - for (i = 0; i < scl.iData[2]; i ++) { - - CWM_OS_dbgPrintf("DML device[%d]: hw_id=%d hw_attr=%d\n", i, scl.iData[6 + i * 2], scl.iData[7 + i * 2]); - } + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - //设置抬腕功能 - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - // scl.iData[1] = 5; - // scl.iData[2] = 5; - // scl.iData[3] = 5; - // scl.iData[4] = 5; - CWM_SettingControl(SCL_HAND_UPDOWN_CONFIG, &scl); - - //配置跑步机模式相关参数(进入跑步机模式自动生效) - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - CWM_SettingControl(SCL_PEDO_CONFIG, &scl); - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - CWM_SettingControl(SCL_ACTIVITY_CONFIG, &scl); - - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - CWM_SettingControl(SCL_SLEEP_CONFIG, &scl); - - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[2] = 1; - CWM_SettingControl(SCL_SEDENTARY, &scl); - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - CWM_SettingControl(SCL_INACTIVITY_CONFIG, &scl); - - - // memset(&scl, 0, sizeof(scl)); - // scl.iData[0] = 1; - // scl.iData[3] = 9; - // scl.iData[4] = 5; - // scl.iData[7] = -1; - // CWM_SettingControl(SCL_LOG, &scl); - // CWM_SettingControl(SCL_LOG, &scl); - - //呼叫任一個CWM_Sensor_Enable 前呼叫此指令 设置手动或自动模式 - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 1; - // int[2] = 3,代表開啟acc和gyro感測器 1代表开启acc - scl.iData[2] = 1; - CWM_SettingControl(SCL_DML_DRV_ENABLE, &scl); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[3] = 3; - scl.iData[4] = 5; - - CWM_Sensor_Enable(IDX_REQUEST_SENSOR); - // //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - - CWM_Sensor_Enable(IDX_ALGO_ACTIVITY_OUTPUT); - CWM_Sensor_Enable(IDX_ALGO_INACTIVITY_OUTPUT); - CWM_Sensor_Enable(IDX_ALGO_SEDENTARY); - CWM_Sensor_Enable(IDX_ALGO_SLEEP); - CWM_Sensor_Enable(IDX_ACCEL); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - // CWM_Sensor_Enable(IDX_GYRO); - CWM_Sensor_Enable(IDX_ALGO_NO_MOTION); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - // CWM_Sensor_Enable(IDX_ALGO_ANY_MOTIOIN); - CWM_Sensor_Enable(IDX_ALGO_ABSOLUTE_STATIC); - //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - CWM_Sensor_Enable(IDX_ALGO_WATCH_HANDUP); - } - cyw_activity_mode_change(cmd); - if(cmd == SPORT_ACTIVE_MODE_NORMAL) - { - cyw_inactivity_mode_change(INACTIVITY_MODE_SEDENTARY); + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_DML_GET_LIB_INFO, &scl); + CWM_OS_dbgPrintf("dml version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]); + + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 18; //00000000000000000000000000010010 高位在前 + // CWM_SettingControl(SCL_DML_DEBUG, &scl); + + //设置acc gyro 相关参数 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[7] = 5; //轴向配置 +#if 0 + scl.iData[3] = 2; + scl.iData[4] = 2; //1 anytime 2 fifo + scl.iData[6] = 5; //先設定5 + scl.iData[8] = 52; // for st sensor(52Hz) +#else + scl.iData[3] = 2; + scl.iData[4] = 2; //1 anytime 2 fifo + scl.iData[6] = 5; //fifocount 先設定5 + scl.iData[8] = 25; // for st sensor(52Hz) +#endif + CWM_SettingControl(SCL_DML_DRV_AG_CONFIG, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + //设定搜寻哪种型号的传感器,以及要搜寻的属性 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 2; + scl.iData[6] = 3002502; + scl.iData[7] = (0|1|8|256|1024); + CWM_SettingControl(SCL_DML_DRV_HW_CONFIG, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + //搜寻是否接入传感器 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 1; + CWM_SettingControl(SCL_DML_DRV_INIT, &scl); + CWM_OS_dbgPrintf("DML device=%d\n", scl.iData[2]); + + //获取初始化 driver清单 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_DML_GET_INITED_LIST, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + for (i = 0; i < scl.iData[2]; i ++) { + + CWM_OS_dbgPrintf("DML device[%d]: hw_id=%d hw_attr=%d\n", i, scl.iData[6 + i * 2], scl.iData[7 + i * 2]); } + + //设置抬腕功能 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + // scl.iData[1] = 5; + // scl.iData[2] = 5; + // scl.iData[3] = 5; + // scl.iData[4] = 5; + CWM_SettingControl(SCL_HAND_UPDOWN_CONFIG, &scl); + + //配置跑步机模式相关参数(进入跑步机模式自动生效) + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_PEDO_CONFIG, &scl); + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_ACTIVITY_CONFIG, &scl); + + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_SLEEP_CONFIG, &scl); + + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[2] = 1; + CWM_SettingControl(SCL_SEDENTARY, &scl); + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_INACTIVITY_CONFIG, &scl); + + + // memset(&scl, 0, sizeof(scl)); + // scl.iData[0] = 1; + // scl.iData[3] = 9; + // scl.iData[4] = 5; + // scl.iData[7] = -1; + // CWM_SettingControl(SCL_LOG, &scl); + // CWM_SettingControl(SCL_LOG, &scl); + + //呼叫任一個CWM_Sensor_Enable 前呼叫此指令 设置手动或自动模式 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 1; + // int[2] = 3,代表開啟acc和gyro感測器 1代表开启acc + scl.iData[2] = 1; + CWM_SettingControl(SCL_DML_DRV_ENABLE, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[3] = 3; + scl.iData[4] = 5; + + CWM_Sensor_Enable(IDX_REQUEST_SENSOR); + // //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + CWM_Sensor_Enable(IDX_ALGO_ACTIVITY_OUTPUT); + CWM_Sensor_Enable(IDX_ALGO_INACTIVITY_OUTPUT); + CWM_Sensor_Enable(IDX_ALGO_SEDENTARY); + CWM_Sensor_Enable(IDX_ALGO_SLEEP); + CWM_Sensor_Enable(IDX_ACCEL); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + // CWM_Sensor_Enable(IDX_GYRO); + CWM_Sensor_Enable(IDX_ALGO_NO_MOTION); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + // CWM_Sensor_Enable(IDX_ALGO_ANY_MOTIOIN); + CWM_Sensor_Enable(IDX_ALGO_ABSOLUTE_STATIC); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + cyw_activity_mode_change(SPORT_ACTIVE_MODE_NORMAL); + + cyw_inactivity_mode_change(INACTIVITY_MODE_SEDENTARY); + + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_WEAR_MODE_TEST); + // cyw_activity_mode_change(cmd); + // if(cmd == SPORT_ACTIVE_MODE_NORMAL) + // { + // cyw_inactivity_mode_change(INACTIVITY_MODE_SEDENTARY); + // } // memset(&scl, 0, sizeof(scl)); // scl.iData[0] = 1; // scl.iData[1] = SPORT_ACTIVE_MODE_NORMAL; //ACTIVITY_MODE_NORMAL 1001 diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 9435968e3..3facf3cf2 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -41,7 +41,7 @@ int16_t gsen_fifo_x[64]={0}; int16_t gsen_fifo_y[64]={0}; int16_t gsen_fifo_z[64]={0}; -gsenson_t gsensordata[16]; +gsenson_t gsensordata[8]; #ifdef SPO2_VECTOR #include "spo2_vec.h" @@ -2736,7 +2736,7 @@ void hx3695_hrs_ppg_Int_handle(void) PRINT("*count : %d \r\n",*count); if(*count < 10) { - gsensor_get_n_data(16,gsensordata); + gsensor_get_n_data(8,gsensordata); for(ii=0; ii<*count; ii++) { if(ii == 8) @@ -2747,9 +2747,12 @@ void hx3695_hrs_ppg_Int_handle(void) } else { - gsen_fifo_x_send[ii] = (gsensordata[ii*2].x + gsensordata[2*ii + 1].x)/2; - gsen_fifo_y_send[ii] = (gsensordata[ii*2].y + gsensordata[2*ii + 1].y)/2; - gsen_fifo_z_send[ii] = (gsensordata[ii*2].z + gsensordata[2*ii + 1].z)/2; + // gsen_fifo_x_send[ii] = (gsensordata[ii*2].x + gsensordata[2*ii + 1].x)/2; + // gsen_fifo_y_send[ii] = (gsensordata[ii*2].y + gsensordata[2*ii + 1].y)/2; + // gsen_fifo_z_send[ii] = (gsensordata[ii*2].z + gsensordata[2*ii + 1].z)/2; + gsen_fifo_x_send[ii] = gsensordata[ii].x; + gsen_fifo_y_send[ii] = gsensordata[ii].y; + gsen_fifo_z_send[ii] = gsensordata[ii].z; } PRINT("hxdata:%d/%d %d %d %d %d %d %d\r\n" ,1+ii,*count,PPG_buf[ii],ir_buf[0],gsen_fifo_x_send[ii],gsen_fifo_y_send[ii],gsen_fifo_z_send[ii],ppg_s_data.green_cur); } diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c index 5e1d00501..491bf15b3 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c @@ -225,17 +225,19 @@ uint32_t tyhx_poweron(void) uapi_pin_set_mode(GPIO_PIN_PRG_LED_ON, (pin_mode_t)HAL_PIO_FUNC_GPIO); uapi_gpio_set_dir(GPIO_PIN_PRG_LED_ON, GPIO_DIRECTION_OUTPUT); uapi_gpio_set_val(GPIO_PIN_PRG_LED_ON, GPIO_LEVEL_HIGH); + tyhx_delay_ms(100); return 0; } uint32_t tyhx_poweroff(void) { uapi_pin_set_mode(GPIO_PIN_PRG_RESET, (pin_mode_t)HAL_PIO_FUNC_GPIO); uapi_gpio_set_dir(GPIO_PIN_PRG_RESET, GPIO_DIRECTION_OUTPUT); - uapi_gpio_set_val(GPIO_PIN_PRG_RESET, GPIO_LEVEL_HIGH); + uapi_gpio_set_val(GPIO_PIN_PRG_RESET, GPIO_LEVEL_LOW); uapi_pin_set_mode(GPIO_PIN_PRG_LED_ON, (pin_mode_t)HAL_PIO_FUNC_GPIO); uapi_gpio_set_dir(GPIO_PIN_PRG_LED_ON, GPIO_DIRECTION_OUTPUT); - uapi_gpio_set_val(GPIO_PIN_PRG_LED_ON, GPIO_LEVEL_HIGH); + uapi_gpio_set_val(GPIO_PIN_PRG_LED_ON, GPIO_LEVEL_LOW); + tyhx_delay_ms(50); return 0; } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 12af27d18..126d847fb 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -36,6 +36,7 @@ #include "time.h" #include "custom_utils.h" +#include "cywee_hal.h" errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg) { @@ -934,25 +935,7 @@ void uapi_set_vibrator_level(int level) void uapi_take_to_wake(int cmd) { - #if defined(SUPPORT_POWER_MANAGER) - const power_display_svr_api_t *display_api = power_display_svr_get_api(); - #endif - if (cmd == 2) - { - #if defined(SUPPORT_POWER_MANAGER) - display_api->set_screen_set_keepon_timeout(0); - PRINT("[cwyee] turn_off_screen"); - #endif - }else if (cmd == 1) - { - #if defined(SUPPORT_POWER_MANAGER) - if (display_api->get_screen_state() != SCREEN_ON) { - PRINT("[cwyee] turn_on_screen"); - display_api->turn_on_screen(); - } - display_api->set_screen_set_keepon_timeout(5000); - #endif - } + hand_updown_switch(cmd); } -- 2.17.1