123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #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 "hal_flash.h"
- #include "hal_imu.h"
- extern uint8_t slave_isconnect(void);
- static uint8_t realStepMode = 0; //是否为实时计步模式
- static uint32_t realStepCur_L = 0; //左鞋步数记录点
- static uint16_t realStepAdd_R = 0; //右鞋步数
- static uint32_t realStepTimCnt = 0; //连接右鞋计时
- /********************** 函数声明区 *************************/
- uint16_t app_step_GetStep_L(void)
- {
- uint16_t st = 0;
- if(mFlash.mStep.stepCur[0]>mFlash.mStep.step[0])
- st = mFlash.mStep.stepCur[0] - mFlash.mStep.step[0];
- return st;
- }
- uint16_t app_step_GetStep_R(void)
- {
- uint16_t st = 0;
- if(mFlash.mStep.stepCur[1]>mFlash.mStep.step[1])
- st = mFlash.mStep.stepCur[1] - mFlash.mStep.step[1];
- return st;
- }
- //左鞋实时计步发送
- 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_Client_T_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;
- BLE_Host_Tx_Send(0,BLE_Host_T_REALTIMESTEP,&mod,1); //挂起从机实时步数
- }
- }else{
- if(realStepTimCnt>0) realStepTimCnt--;
- if(realStepTimCnt==0) BLE_Host_Tx_Send(0,BLE_Host_T_REALTIMESTEP,&realStepMode,1);
- }
- }else{
- if(realStepTimCnt>0){ realStepTimCnt = 0;
- BLE_Host_Tx_Send(0,BLE_Host_T_REALTIMESTEP,&realStepMode,1);
- }
- }
- }
- //接收右鞋实时步数
- void cb_BLE_Host_R_REALTIMESTEP(void* handle)
- {
- BLE_Client_Rx_t* target = handle;
- 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;
- }
- }
- //接收手机命令
- void cb_BLE_Client_R_REALTIMESTEP(void* handle)
- {
- BLE_Client_Rx_t* target = handle;
- uint8_t cmd = target->pDat[0];
- BLE_Host_Tx_Send(0,BLE_Host_T_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_Client_R_REALTIMESTEP,cb_BLE_Client_R_REALTIMESTEP);
- BLE_Host_Rx_Regist(BLE_Host_R_REALTIMESTEP,cb_BLE_Host_R_REALTIMESTEP);
- }
|