MonsterH5.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include "MonsterH5.h"
  2. void MonsterH5::Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
  3. int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
  4. int jump, int down, int rssi)
  5. {
  6. static int right_zupt_count = 0;
  7. static int left_zupt_count = 0;
  8. static int last_right_zupt = 0;
  9. static int last_left_zupt = 0;
  10. static int right_wait = 0;
  11. static int left_wait = 0;
  12. int right_is_zupt = 0;
  13. static int left_trigger_wait = 0;
  14. static int right_trigger_wait = 0;
  15. static float left_max_z_unzero = 1.0f;
  16. static float left_min_z_unzero = 1.0f;
  17. static float right_max_z_unzero = 1.0f;
  18. static float right_min_z_unzero = 1.0f;
  19. if (right_trigger_wait > 0)
  20. {
  21. float right_acc_z = right_acc[2] / 2048.f;
  22. if (right_acc_z > right_max_z_unzero)
  23. {
  24. right_max_z_unzero = right_acc_z;
  25. }
  26. if (right_acc_z < right_min_z_unzero)
  27. {
  28. right_min_z_unzero = right_acc_z;
  29. }
  30. }
  31. else
  32. {
  33. right_max_z_unzero = 1.0f;
  34. right_min_z_unzero = 1.0f;
  35. }
  36. if (left_trigger_wait > 0)
  37. {
  38. float left_acc_z = left_acc[2] / 2048.f;
  39. if (left_acc_z > left_max_z_unzero)
  40. {
  41. left_max_z_unzero = left_acc_z;
  42. }
  43. if (left_acc_z < left_min_z_unzero)
  44. {
  45. left_min_z_unzero = left_acc_z;
  46. }
  47. }
  48. else
  49. {
  50. left_max_z_unzero = 1.0f;
  51. left_min_z_unzero = 1.0f;
  52. }
  53. if (right_zupt == 1 && last_right_zupt == 0 &&
  54. (right_trigger_wait <= 0 || (right_max_z_unzero >2.0f && right_min_z_unzero <0.0f)))
  55. //if (right_zupt == 1 && last_right_zupt == 0)
  56. {
  57. std::cout << "塘신뇰랙劫뒈" << endl;
  58. result[1] = 1;
  59. right_wait = 5;
  60. right_max_z_unzero = 1.0f;
  61. right_min_z_unzero = 1.0f;
  62. }
  63. else
  64. {
  65. result[1] = 0;
  66. }
  67. if (left_zupt == 1 && last_left_zupt == 0 &&
  68. (left_trigger_wait <=0 || (left_max_z_unzero > 2.0f && left_min_z_unzero < 0.0f)))
  69. {
  70. std::cout << "璘신뇰랙劫뒈" << endl;
  71. result[0] = 1;
  72. left_wait = 5;
  73. left_max_z_unzero = 1.0f;
  74. left_min_z_unzero = 1.0f;
  75. }
  76. else
  77. {
  78. result[0] = 0;
  79. }
  80. //털뙤崗신뇰뒀
  81. if (right_wait > 0 && left_wait > 0)
  82. {
  83. result[2] = 1;
  84. std::cout << "崗신꽂뒈" << std::endl;
  85. }
  86. else
  87. {
  88. result[2] = 0;
  89. }
  90. if (right_zupt == 1)
  91. {
  92. right_trigger_wait = 15;
  93. }
  94. else
  95. {
  96. right_trigger_wait--;
  97. }
  98. if (left_zupt == 1)
  99. {
  100. left_trigger_wait = 15;
  101. }
  102. else
  103. {
  104. left_trigger_wait--;
  105. }
  106. last_right_zupt = right_zupt;
  107. last_left_zupt = left_zupt;
  108. if (left_wait > 0)
  109. {
  110. left_wait--;
  111. }
  112. if (right_wait > 0)
  113. {
  114. right_wait--;
  115. }
  116. if (right_trigger_wait > 0)
  117. {
  118. right_trigger_wait--;
  119. }
  120. if (left_trigger_wait > 0)
  121. {
  122. left_trigger_wait--;
  123. }
  124. }
  125. void MonsterH5::getResult(int* dec)
  126. {
  127. memcpy(dec, result, 4 * sizeof(int));
  128. }