123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #include "app_step.h"
- #include "nrf_gpio.h"
- #include "usr_config.h"
- #include "bsp_time.h"
- #include "system.h"
- #include "hal_mt.h"
- #include "app_host.h"
- #include "app_charge.h"
- #include "hal_ble_client.h"
- #include "hal_ble_host.h"
- #include "nrf_delay.h"
- #include "app_flash.h"
- #include "hal_mode_manage.h"
- #include "ble_comm.h"
- static uint8_t realStepMode = 0; //是否为实时计步模式
- static uint32_t realStepCur_L = 0; //左鞋步数记录点
- static uint16_t realStepAdd_R = 0; //右鞋步数
- static uint32_t realStepTimCnt = 0; //连接右鞋计时
- /********************** 函数声明区 *************************/
- uint32_t app_step_GetStep_L(void)
- {
- return mFlash.mStep.stepCur[0];
- }
- uint32_t app_step_GetStep_R(void)
- {
- return mFlash.mStep.stepCur[1];
- }
- //左鞋实时计步发送
- void app_step_RealSendProcess(void)
- {
- if(realStepMode==BLE_Client_R_REALTIMESTEP_ENTER && slave_isconnect()>0){
- uint8_t buf[8];
- uint8_t L = 0;
- buf[L++] = BLE_Client_R_REALTIMESTEP_ENTER;
- buf[L++] = (uint8_t)((mFlash.mStep.stepCur[0]-realStepCur_L)>>8);
- buf[L++] = (uint8_t)((mFlash.mStep.stepCur[0]-realStepCur_L)>>0);
- buf[L++] = (uint8_t)(realStepAdd_R>>8);
- buf[L++] = (uint8_t)(realStepAdd_R>>0);
- BLE_Client_Tx_Send(0,BLE_REALTIMESTEP,buf,L);
- }
- }
- //右鞋实时计步连接管理
- void app_step_RealConnectProcess(void)
- {
- if(realStepMode==BLE_Client_R_REALTIMESTEP_ENTER){
- if(slave_isconnect()==0){//与手机断开连接
- if(realStepTimCnt>0){ realStepTimCnt = 0; //从机在发步数
- uint8_t mod = BLE_Client_R_REALTIMESTEP_HANDUP;
- hal_mode_set(HAL_MODE_NORMAL);
- BLE_Host_Tx_Send(0,BLE_REALTIMESTEP,&mod,1); //挂起从机实时步数
- }
- }else{
- if(realStepTimCnt>0) realStepTimCnt--;
- if(realStepTimCnt==0) BLE_Host_Tx_Send(0,BLE_REALTIMESTEP,&realStepMode,1);
- }
- }else{
- if(realStepTimCnt>0){ realStepTimCnt = 0;
- BLE_Host_Tx_Send(0,BLE_REALTIMESTEP,&realStepMode,1);
- }
- }
- }
- //接收右鞋实时步数
- void cb_BLE_Host_R_REALTIMESTEP(void* handle)
- {
- BLE_Client_Rx_t* target = handle;
- #if DEBUG_STEP
- extern step_count_t mIstep_count_t_right;
-
- mIstep_count_t_right.F_val_now = ((uint32_t)target->pDat[1]<<8)|((uint32_t)target->pDat[2]<<0);
- mIstep_count_t_right.F_val_now_B = ((uint32_t)target->pDat[3]<<8)|((uint32_t)target->pDat[4]<<0);
- mIstep_count_t_right.F_filter_val = ((uint32_t)target->pDat[5]<<8)|((uint32_t)target->pDat[6]<<0);
- mIstep_count_t_right.F_flag_step = ((uint32_t)target->pDat[7]<<8)|((uint32_t)target->pDat[8]<<0);
- hal_step_matlib_Test(0x01);
- if(mIstep_count_t_right.F_flag_step > 0)mIstep_count_t_right.F_flag_step =0;
- #else
- if(target->pDat[0]==BLE_Client_R_REALTIMESTEP_ENTER){
- realStepAdd_R = ((uint16_t)target->pDat[1]<<8) | ((uint16_t)target->pDat[2]<<0);
- realStepTimCnt = 3;
- }
- #endif
- }
- //接收手机命令
- void cb_BLE_Client_R_REALTIMESTEP(void* handle)
- {
- BLE_Client_Rx_t* target = handle;
- uint8_t cmd = target->pDat[0];
- if(cmd==BLE_Client_R_REALTIMESTEP_ENTER)hal_mode_set(HAL_MODE_REALSTEP);
- else if(cmd==BLE_Client_R_REALTIMESTEP_EXIT)hal_mode_set(HAL_MODE_NORMAL);
-
- BLE_Host_Tx_Send(0,BLE_REALTIMESTEP,&cmd,1);
-
- if(cmd==BLE_Client_R_REALTIMESTEP_ENTER && realStepMode==BLE_Client_R_REALTIMESTEP_EXIT)
- realStepCur_L = mFlash.mStep.stepCur[0]; //重新计数
- realStepMode = cmd;
- }
- void app_step_Init(void)
- {
- Process_Start(100,"step_RealSend",app_step_RealSendProcess);
- Process_Start(1000,"step_RealConnect",app_step_RealConnectProcess);
- BLE_Client_Rx_Regist(BLE_REALTIMESTEP,cb_BLE_Client_R_REALTIMESTEP);
- BLE_Host_Rx_Regist(BLE_REALTIMESTEP,cb_BLE_Host_R_REALTIMESTEP);
-
- }
|