app_Authen - 副本.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "usr_config.h"
  2. #include "app_Authen.h"
  3. #include "system.h"
  4. #include "hal_ble_client.h"
  5. #include "hal_ble_host.h"
  6. #include "bsp_time.h"
  7. #include "ble_comm.h"
  8. #include "bll_imu.h"
  9. #include "app_flash.h"
  10. #include "app_Authen.h"
  11. #include "app_connect_manage.h"
  12. /************************ º¯ÊýÉùÃ÷ ***********************************/
  13. static uint8_t Phoneflag =0;
  14. static uint32_t tim =0;
  15. static void cb_BLE_Client_BLE_AUTHEN(void* handle){
  16. BLE_Client_Rx_t* target = handle;
  17. Phoneflag = target->pDat[0];
  18. tim = TIME_GetTicks();
  19. }
  20. static BLE_Client_Tx_t m_Client_BLE_AUTHEN = {
  21. .n = 10,
  22. .t = 100,
  23. };
  24. static void app_Authen_Process(void){
  25. static uint8_t state =0;
  26. bll_imu_data_t data= {0};
  27. static uint8_t LIFE_SIGNAL =0;
  28. uint8_t buf =0;
  29. switch(state){
  30. case 0:
  31. if(slave_isconnect()){
  32. if(BLE_RIGHT_CONNTED == app_conneted_getRight()){
  33. tim = TIME_GetTicks();
  34. state =1;
  35. }
  36. }
  37. else{
  38. if(host_isconnect()){
  39. buf =1;
  40. BLE_Host_Tx_Send(&m_Client_BLE_AUTHEN,BLE_AUTHEN,&buf,1);
  41. }
  42. }
  43. break;
  44. case 1:
  45. if(1 == Phoneflag){
  46. state = 2;
  47. Phoneflag =0;
  48. }
  49. else if(TIME_GetTicks() -tim >= 3000){
  50. if(slave_isconnect()){
  51. slave_disconnect();
  52. }
  53. else {
  54. state =3;
  55. Phoneflag =0;
  56. }
  57. }
  58. break;
  59. case 2:
  60. if(!slave_isconnect()){
  61. state =3;
  62. }
  63. else {
  64. int16_t data_size = 0;
  65. data_size = bll_imu_get_data_num(BLL_IMU_DIR_FRONT);
  66. if(data_size > 0){
  67. bll_imu_get_data(BLL_IMU_DIR_FRONT, data_size -1 , &data);
  68. int32_t acc_norm = (data.acc[0] * data.acc[0] +data.acc[1] * data.acc[1] + data.acc[2] * data.acc[2]);
  69. if(abs(acc_norm - 4194304) < 362144 && data.acc[2] > 1536){
  70. LIFE_SIGNAL = 3;
  71. }
  72. else if(LIFE_SIGNAL > 0)LIFE_SIGNAL --;
  73. if(abs(acc_norm - 4194304) < 362144 && data.acc[2] < -1024)LIFE_SIGNAL = 0;
  74. if(LIFE_SIGNAL > 0){
  75. buf =3;
  76. BLE_Client_Tx_Send(&m_Client_BLE_AUTHEN,BLE_AUTHEN,&buf,1);
  77. state =3;
  78. }
  79. }
  80. }
  81. break;
  82. case 3:
  83. state =0;
  84. Phoneflag =0;
  85. break;
  86. default:state=0;Phoneflag =0;break;
  87. }
  88. }
  89. void app_Authen_Init(void)
  90. {
  91. Process_Start(100,"app_charge",app_Authen_Process);
  92. BLE_Client_Rx_Regist(BLE_AUTHEN,cb_BLE_Client_BLE_AUTHEN);
  93. }