special_motion.c 7.1 KB

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