#include "osal_msgqueue.h"
#include "osal_mutex.h"
#include "ppg_service.h"
+#include "custom_utils.h"
#define AP_ENABLE_DML_SDO_LISTEN
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)
{
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)
//自由运动
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;
// break;
case 2:
- PRINT("222\r\n");
memset(&scl, 0, sizeof(scl));
scl.iData[0] = 1;
scl.iData[1] = 2;
break;
case 1:
- PRINT("333\r\n");
memset(&scl, 0, sizeof(scl));
scl.iData[0] = 1;
scl.iData[1] = 1;
void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
cywee_msg_callback_t cywee_func;
-
switch (sensorEVT->sensorType) {
case IDX_ACCEL:
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");
}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));
(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
(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
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
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__);
//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));
//uint8_t alg_ram[10] = {0};\r
ppg_sensor_data_t ppg_s_data;\r
\r
+uint8_t free_trainning_hrs = 0;\r
+uint8_t free_trainning_wearstatus = 0;\r
\r
//////// spo2 para and switches\r
const uint8_t COUNT_BLOCK_NUM = 25; //delay the block of some single good signal after a series of bad signal\r
int32_t ble_spo2_data = 0;\r
uint8_t ble_spo2_flag = 0;\r
\r
-\r
-\r
#ifdef SPO2_DATA_CALI\r
static int32_t red_data_fifo[4] = {0};\r
static int32_t ir_data_fifo[4] = {0};\r
static int32_t cali_data_cnt = 0;\r
#endif\r
\r
+void get_hrs_wearstatus(uint8_t *hrs,uint8_t *wearstatus)\r
+{\r
+ *hrs = free_trainning_hrs;\r
+ *wearstatus = free_trainning_wearstatus;\r
+}\r
+\r
+\r
// us 延时函数, 客户需填写\r
void hx3695_delay_us(uint32_t us)\r
{\r
// result.ir_data_final = hrs_s_dat.ir_data[0];\r
// hx3695_factory_test_process(NULL, APP_FACTORY_TEST_HR_START, &result);\r
\r
- //gsensor_get_n_data(8,gsensordata);\r
+ //gsensor_get_n_data(1,gsensordata);\r
\r
// for(ii=0; ii<*count; ii++)\r
// {\r
// }\r
\r
hrs_wear_status = hx3695_hrs_get_wear_status();\r
- PRINT("hrs_wear_status: %d !!\r\n", hrs_wear_status);\r
- \r
+ PRINT("hrs_wear_status: %d !!\r\n", hrs_wear_status);\r
+ \r
if(hrs_wear_status == MSG_HRS_WEAR)\r
{\r
tyhx_hrs_alg_send_data(PPG_buf, *count, gsen_fifo_x_send, gsen_fifo_y_send, \r
- gsen_fifo_z_send, cal.Group1_Ledidac);\r
+ gsen_fifo_z_send, cal.Group1_Ledidac);\r
}\r
#endif\r
\r
uint8_t curr_wear = 1;\r
//uint8_t last_wear = cwm_get_wear_status();\r
\r
- alg_results = tyhx_hrs_alg_get_results();\r
- hrsresult.lastesthrs = alg_results.hr_result;\r
- hrsresult.hr_living = alg_results.living_status;\r
- hrsresult.hr_living_qu = alg_results.hr_result_qual;\r
- hrsresult.hr_living_std = alg_results.hr_result_std;\r
+ alg_results = tyhx_hrs_alg_get_results();\r
+ hrsresult.lastesthrs = alg_results.hr_result;\r
+ hrsresult.hr_living = alg_results.living_status;\r
+ hrsresult.hr_living_qu = alg_results.hr_result_qual;\r
+ hrsresult.hr_living_std = alg_results.hr_result_std;\r
\r
PRINT("hx3695 data_cnt: %d, hr_living: %d, hr_living_qu: %d, hr_living_std: %d, hr_result:%d \r\n",\r
alg_results.data_cnt, hrsresult.hr_living, hrsresult.hr_living_qu, hrsresult.hr_living_std, hrsresult.lastesthrs);\r
\r
+ free_trainning_hrs = hrsresult.lastesthrs;\r
+ free_trainning_wearstatus = hrs_wear_status;\r
+\r
+\r
if(hrsresult.lastesthrs > 0)\r
{\r
ble_hrs_flag = 1;\r
}\r
#endif\r
\r
-\r
#endif //CHIP_HX3695\r