special_motion.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #include "special_motion.h"
  2. #include "motion_config.h"
  3. int down_send_count = 0;
  4. int is_down = 0;
  5. int jump_send_count = 0;
  6. int is_jump = 0;
  7. int16_t left_time;
  8. uint16_t left_press_front;
  9. uint16_t left_press_back;
  10. int32_t left_pos[3];
  11. int16_t left_att[3];
  12. int16_t left_acc[3];
  13. int16_t left_zupt;
  14. int16_t right_time;
  15. uint16_t right_press_front;
  16. uint16_t right_press_back;
  17. int32_t right_pos[3];
  18. int16_t right_att[3];
  19. int16_t right_acc[3];
  20. int16_t right_zupt;
  21. uint8_t rssi;
  22. uint8_t right_rssi;
  23. uint8_t left_rssi;
  24. uint16_t right_laser_distance;
  25. uint16_t left_laser_distance;
  26. void decode_shoes_data_right(uint8_t* buff,uint8_t right_len)
  27. {
  28. right_laser_distance = ((uint16_t)buff[0] << 8) | ((uint16_t)buff[1] << 0);
  29. right_pos[0] = ((int32_t)buff[2] << 24) | ((int32_t)buff[3] << 16) | ((int32_t)buff[4] << 8) | ((int32_t)buff[5] << 0);
  30. right_pos[1] = ((int32_t)buff[6] << 24) | ((int32_t)buff[7] << 16) | ((int32_t)buff[8] << 8) | ((int32_t)buff[9] << 0);
  31. right_pos[2] = ((int32_t)buff[10] << 24) | ((int32_t)buff[11] << 16) | ((int32_t)buff[12] << 8) | ((int32_t)buff[13] << 0);
  32. right_att[0] = ((int16_t)buff[14] << 8) | ((int16_t)buff[15] << 0);
  33. right_att[1] = ((int16_t)buff[16] << 8) | ((int16_t)buff[17] << 0);
  34. right_att[2] = ((int16_t)buff[18] << 8) | ((int16_t)buff[19] << 0);
  35. right_zupt = ((uint8_t)buff[20]);
  36. right_acc[0] = ((int16_t)buff[21] << 8) | ((int16_t)buff[22] << 0);
  37. right_acc[1] = ((int16_t)buff[23] << 8) | ((int16_t)buff[24] << 0);
  38. right_acc[2] = ((int16_t)buff[25] << 8) | ((int16_t)buff[26] << 0);
  39. right_rssi = (uint8_t) buff[27];
  40. right_time = ((uint16_t)buff[28] << 8) | ((uint16_t)buff[29] << 0);
  41. right_press_front = ((uint16_t)buff[30] << 8) | ((uint16_t)buff[31] << 0);
  42. right_press_back = ((uint16_t)buff[32] << 8) | ((uint16_t)buff[33] << 0);
  43. }
  44. void decode_shoes_data_left(uint8_t* buff,uint8_t left_len)
  45. {
  46. left_laser_distance = ((uint16_t)buff[0] << 8) | ((uint16_t)buff[1] << 0);
  47. left_pos[0] = ((int32_t)buff[2] << 24) | ((int32_t)buff[3] << 16) | ((int32_t)buff[4] << 8) | ((int32_t)buff[5] << 0);
  48. left_pos[1] = ((int32_t)buff[6] << 24) | ((int32_t)buff[7] << 16) | ((int32_t)buff[8] << 8) | ((int32_t)buff[9] << 0);
  49. left_pos[2] = ((int32_t)buff[10] << 24) | ((int32_t)buff[11] << 16) | ((int32_t)buff[12] << 8) | ((int32_t)buff[13] << 0);
  50. left_att[0] = ((int16_t)buff[14] << 8) | ((int16_t)buff[15] << 0);
  51. left_att[1] = ((int16_t)buff[16] << 8) | ((int16_t)buff[17] << 0);
  52. left_att[2] = ((int16_t)buff[18] << 8) | ((int16_t)buff[19] << 0);
  53. left_zupt = ((uint8_t)buff[20]);
  54. left_acc[0] = ((int16_t)buff[21] << 8) | ((int16_t)buff[22] << 0);
  55. left_acc[1] = ((int16_t)buff[23] << 8) | ((int16_t)buff[24] << 0);
  56. left_acc[2] = ((int16_t)buff[25] << 8) | ((int16_t)buff[26] << 0);
  57. left_rssi = (uint8_t) buff[27];
  58. left_time = ((uint16_t)buff[28] << 8) | ((uint16_t)buff[29] << 0);
  59. left_press_front = ((uint16_t)buff[30] << 8) | ((uint16_t)buff[31] << 0);
  60. left_press_back = ((uint16_t)buff[32] << 8) | ((uint16_t)buff[33] << 0);
  61. }
  62. void special_motion(int time_stamp, uint16_t h_press, uint16_t s_press, int16_t h_pos[3], int16_t s_pos[3],
  63. float left_acc_z, float right_acc_z, int16_t *down, int16_t *jump)
  64. {
  65. /*
  66. 处理蹲的动作
  67. */
  68. short down_tag = 0;
  69. int front_down = 0;
  70. int back_down = 0;
  71. if(0)
  72. {
  73. down_tag = press_down_detect_new(time_stamp, left_laser_distance, right_laser_distance, left_acc_z, right_acc_z,
  74. (float)left_att[1]/10000, (float)right_att[1]/10000, rssi);
  75. }
  76. else
  77. {
  78. press_down_detect_press(0, (float)left_press_front, (float)left_press_back,
  79. (float)right_press_front, (float)right_press_back, &front_down, &back_down);
  80. if(front_down == 1 || back_down == 1)
  81. {
  82. down_tag = 1;
  83. }
  84. }
  85. if (down_tag)
  86. {
  87. /*
  88. gpio_mt_run(300);
  89. */
  90. down_send_count = 10;
  91. }
  92. if(down_send_count > 0)
  93. {
  94. is_down = 1;
  95. down_send_count --;
  96. }
  97. else
  98. {
  99. is_down = 0;
  100. }
  101. /*
  102. 处理跳的动作
  103. */
  104. short jump_tag = 0;
  105. jump_tag = press_jump_detect(left_acc_z, right_acc_z);
  106. /*
  107. *利用zupt来避免跳
  108. */
  109. if(left_zupt || right_zupt)
  110. {
  111. jump_tag =0;
  112. }
  113. if (jump_tag)
  114. {
  115. /*
  116. gpio_mt_run(300);
  117. */
  118. jump_send_count = 10;
  119. }
  120. //连续发20次蹲,终端再处理
  121. if(jump_send_count > 0)
  122. {
  123. is_jump = 1;
  124. jump_send_count --;
  125. }
  126. else
  127. {
  128. is_jump = 0;
  129. }
  130. *down = is_down;
  131. *jump = is_jump;
  132. }
  133. uint8_t buf[64];
  134. uint8_t L=0;
  135. void inter_package_data()
  136. {
  137. static uint8_t package_time;
  138. L=0;
  139. buf[L++] = (uint8_t)(right_pos[0]>>24);
  140. buf[L++] = (uint8_t)(right_pos[0]>>16);
  141. buf[L++] = (uint8_t)(right_pos[0]>>8);
  142. buf[L++] = (uint8_t)(right_pos[0]>>0);
  143. buf[L++] = (uint8_t)(right_pos[1]>>24);
  144. buf[L++] = (uint8_t)(right_pos[1]>>16);
  145. buf[L++] = (uint8_t)(right_pos[1]>>8);
  146. buf[L++] = (uint8_t)(right_pos[1]>>0);
  147. buf[L++] = (uint8_t)(right_pos[2]>>24);
  148. buf[L++] = (uint8_t)(right_pos[2]>>16);
  149. buf[L++] = (uint8_t)(right_pos[2]>>8);
  150. buf[L++] = (uint8_t)(right_pos[2]>>0);
  151. buf[L++] = (uint8_t)(left_pos[0]>>24);
  152. buf[L++] = (uint8_t)(left_pos[0]>>16);
  153. buf[L++] = (uint8_t)(left_pos[0]>>8);
  154. buf[L++] = (uint8_t)(left_pos[0]>>0);
  155. buf[L++] = (uint8_t)(left_pos[1]>>24);
  156. buf[L++] = (uint8_t)(left_pos[1]>>16);
  157. buf[L++] = (uint8_t)(left_pos[1]>>8);
  158. buf[L++] = (uint8_t)(left_pos[1]>>0);
  159. buf[L++] = (uint8_t)(left_pos[2]>>24);
  160. buf[L++] = (uint8_t)(left_pos[2]>>16);
  161. buf[L++] = (uint8_t)(left_pos[2]>>8);
  162. buf[L++] = (uint8_t)(left_pos[2]>>0);
  163. buf[L++] = (uint8_t)(right_att[0]>>8);
  164. buf[L++] = (uint8_t)(right_att[0]>>0);
  165. buf[L++] = (uint8_t)(right_att[1]>>8);
  166. buf[L++] = (uint8_t)(right_att[1]>>0);
  167. buf[L++] = (uint8_t)(right_att[2]>>8);
  168. buf[L++] = (uint8_t)(right_att[2]>>0);
  169. buf[L++] = (uint8_t)(left_att[0]>>8);
  170. buf[L++] = (uint8_t)(left_att[0]>>0);
  171. buf[L++] = (uint8_t)(left_att[1]>>8);
  172. buf[L++] = (uint8_t)(left_att[1]>>0);
  173. buf[L++] = (uint8_t)(left_att[2]>>8);
  174. buf[L++] = (uint8_t)(left_att[2]>>0);
  175. buf[L++] = (uint8_t)(right_acc[0]>>8);
  176. buf[L++] = (uint8_t)(right_acc[0]>>0);
  177. buf[L++] = (uint8_t)(right_acc[1]>>8);
  178. buf[L++] = (uint8_t)(right_acc[1]>>0);
  179. buf[L++] = (uint8_t)(right_acc[2]>>8);
  180. buf[L++] = (uint8_t)(right_acc[2]>>0);
  181. buf[L++] = (uint8_t)(left_acc[0]>>8);
  182. buf[L++] = (uint8_t)(left_acc[0]>>0);
  183. buf[L++] = (uint8_t)(left_acc[1]>>8);
  184. buf[L++] = (uint8_t)(left_acc[1]>>0);
  185. buf[L++] = (uint8_t)(left_acc[2]>>8);
  186. buf[L++] = (uint8_t)(left_acc[2]>>0);
  187. int is_girl = 0;
  188. if(GIRL_SHOES)
  189. is_girl = 1;
  190. buf[L++] = (uint8_t)(is_girl * 16 + right_zupt * 8 + left_zupt * 4 + is_down * 2 + is_jump * 1);
  191. buf[L++] = (uint8_t)(rssi >> 0);
  192. buf[L++] = (uint8_t)(package_time);
  193. buf[L++] = (uint8_t)(right_press_front>>8);
  194. buf[L++] = (uint8_t)(right_press_front>>0);
  195. buf[L++] = (uint8_t)(right_press_back>>8);
  196. buf[L++] = (uint8_t)(right_press_back>>0);
  197. buf[L++] = (uint8_t)(left_press_front>>8);
  198. buf[L++] = (uint8_t)(left_press_front>>0);
  199. buf[L++] = (uint8_t)(left_press_back>>8);
  200. buf[L++] = (uint8_t)(left_press_back>>0);
  201. package_time ++;
  202. }
  203. void package_to_buff()
  204. {
  205. inter_package_data();
  206. }
  207. void integrate_left_right(uint8_t* left_buff,uint8_t left_len, uint8_t* right_buff, uint8_t right_len)
  208. {
  209. //把底层的数据解开
  210. if(LEFT_IS_HOST)
  211. {
  212. decode_shoes_data_right(right_buff, right_len);
  213. decode_shoes_data_left(left_buff, left_len);
  214. }
  215. else
  216. {
  217. decode_shoes_data_right(left_buff, left_len);
  218. decode_shoes_data_left(right_buff, right_len);
  219. }
  220. //整合左右脚的数据
  221. static int32_t last_pos_left[3];
  222. static int32_t last_pos_right[3];
  223. if(left_zupt)
  224. {
  225. memcpy(last_pos_left, left_pos, 3 * sizeof(int32_t));
  226. }
  227. //
  228. if(right_zupt)
  229. {
  230. memcpy(last_pos_right, right_pos, 3 * sizeof(int32_t));
  231. }
  232. int16_t left_pos_offset[3];
  233. int16_t right_pos_offset[3];
  234. for(int i = 0; i < 3 ; i ++)
  235. {
  236. left_pos_offset[i] = left_pos[i] - last_pos_left[i];
  237. right_pos_offset[i] = right_pos[i] - last_pos_right[i];
  238. }
  239. short *down = 0;
  240. short *jump = 0;
  241. rssi = left_rssi;
  242. special_motion(left_time, left_press_front, right_press_front, left_pos_offset, right_pos_offset, (float)left_acc[2]/2048.0f , (float)right_acc[2]/2048.0f, down, jump);
  243. //整合完,再组合成一包
  244. package_to_buff();
  245. }
  246. //获取包裹的接口
  247. void get_game_package(uint8_t* buff_address, uint8_t * buff_len)
  248. {
  249. memcpy(buff_address, buf, L);
  250. *buff_len = L;
  251. }