bsp_interface.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /********************** 头文件 *************************/
  2. #include "bsp_interface.h"
  3. /********************** 变量区 *************************/
  4. //extern int16_t gyro[3];
  5. //extern int16_t accel[3];
  6. //extern uint16_t press;
  7. extern int16_t accel[3];
  8. extern int16_t gyro[3];
  9. extern uint16_t h_press;
  10. extern int16_t s_gyro[3];
  11. extern int16_t s_accel[3];
  12. extern uint16_t s_press;
  13. /********************** 函数声明区 *************************/
  14. //enum _CMD_UPDATE{
  15. // UPDATE_NONE = 0,
  16. // UPDATE_RUN,
  17. // NUMBERS_OF_UPDATE,
  18. // };
  19. void sen_step_to_host(uint8_t step,uint16_t distance)
  20. {
  21. uint8_t buf[32];
  22. uint8_t L=0;
  23. buf[L++] = UPDATE_RUN;
  24. buf[L++] = (uint8_t)(step>>0);
  25. buf[L++] = (uint8_t)(distance>>8);
  26. buf[L++] = (uint8_t)(distance>>0);
  27. send_protocol(DEX_NUM,CMD_UPDATE,buf,L);
  28. }
  29. void sen_data_to_host(void)
  30. {
  31. // uint8_t buf[256];
  32. // uint8_t L=0;
  33. //
  34. // buf[L++] = (uint8_t)(h_press>>8);
  35. // buf[L++] = (uint8_t)(h_press>>0);
  36. //
  37. // buf[L++] = (uint8_t)(s_press>>8);
  38. // buf[L++] = (uint8_t)(s_press>>0);
  39. //
  40. // buf[L++] = (uint8_t)(accel[0]>>8);
  41. // buf[L++] = (uint8_t)(accel[0]>>0);
  42. //
  43. // buf[L++] = (uint8_t)(accel[1]>>8);
  44. // buf[L++] = (uint8_t)(accel[1]>>0);
  45. //
  46. // buf[L++] = (uint8_t)(accel[2]>>8);
  47. // buf[L++] = (uint8_t)(accel[2]>>0);
  48. //
  49. // buf[L++] = (uint8_t)(s_accel[0]>>8);
  50. // buf[L++] = (uint8_t)(s_accel[0]>>0);
  51. //
  52. // buf[L++] = (uint8_t)(s_accel[1]>>8);
  53. // buf[L++] = (uint8_t)(s_accel[1]>>0);
  54. //
  55. // buf[L++] = (uint8_t)(s_accel[2]>>8);
  56. // buf[L++] = (uint8_t)(s_accel[2]>>0);
  57. //
  58. // buf[L++] = (uint8_t)(gyro[0]>>8);
  59. // buf[L++] = (uint8_t)(gyro[0]>>0);
  60. //
  61. // buf[L++] = (uint8_t)(gyro[1]>>8);
  62. // buf[L++] = (uint8_t)(gyro[1]>>0);
  63. //
  64. // buf[L++] = (uint8_t)(gyro[2]>>8);
  65. // buf[L++] = (uint8_t)(gyro[2]>>0);
  66. //
  67. // buf[L++] = (uint8_t)(s_gyro[0]>>8);
  68. // buf[L++] = (uint8_t)(s_gyro[0]>>0);
  69. //
  70. // buf[L++] = (uint8_t)(s_gyro[1]>>8);
  71. // buf[L++] = (uint8_t)(s_gyro[1]>>0);
  72. //
  73. // buf[L++] = (uint8_t)(s_gyro[2]>>8);
  74. // buf[L++] = (uint8_t)(s_gyro[2]>>0);
  75. //
  76. // send_protocol(DEX_NUM,CMD_HEART,buf,L);
  77. }
  78. static uint8_t send_motion = 0;
  79. static uint8_t send_ts = 0;
  80. static uint8_t send_times = 0;
  81. void send_motion_to_phone(uint8_t motion,uint16_t ts)
  82. {
  83. send_motion = motion;
  84. send_ts = ts;
  85. send_times = 10;
  86. // uint8_t buf[16];
  87. // uint8_t L=0;
  88. // buf[L++] = motion;
  89. //
  90. // buf[L++] = (uint8_t)(ts>>8);
  91. // buf[L++] = (uint8_t)(ts>>0);
  92. //
  93. // for(int i = 0; i <5; i++)
  94. // send_protocol(DEX_NUM,CMD_MOTION,buf,L);
  95. }
  96. void send_to_phone_process(void)
  97. {
  98. uint8_t buf[16];
  99. uint8_t L=0;
  100. if(send_times>0){
  101. send_times--;
  102. buf[L++] = send_motion;
  103. buf[L++] = (uint8_t)(send_ts>>8);
  104. buf[L++] = (uint8_t)(send_ts>>0);
  105. send_protocol(DEX_NUM,CMD_MOTION,buf,L);
  106. }
  107. }