hal_mode_manage2.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include "hal_mode_manage.h"
  2. #include "hal_imu.h"
  3. #include "usr_config.h"
  4. #include "bsp_time.h"
  5. #include "system.h"
  6. #include "hal_wearshoes.h"
  7. /*********************************************************************
  8. * LOCAL VARIABLES
  9. */
  10. static hal_mode cur_mode;
  11. static hal_mode change_mode;
  12. static hal_mode process_mode;
  13. static uint8_t send_signal_flag = 0;
  14. static uint8_t critical_zone = 0;
  15. /*********************************************************************
  16. * LOCAL FUCTIONS
  17. */
  18. static void Send_Signal(hal_mode mode)
  19. {
  20. switch(mode)
  21. {
  22. case HAL_MODE_GAME:
  23. if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){
  24. IMU_SetSignal(SIGNAL_FULL_POWER, IMU_SIGNAL_ON);
  25. send_signal_flag = 1;
  26. }else critical_zone = 0; //解锁
  27. break;
  28. case HAL_MODE_REALSTEP:
  29. if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){
  30. IMU_SetSignal(SIGNAL_FULL_POWER, IMU_SIGNAL_ON);
  31. send_signal_flag = 1;
  32. }else critical_zone = 0; //解锁
  33. break;
  34. case HAL_MODE_STANDBY:
  35. if(IMU_GetCurrentMode() != STATE_STANDBY_POWER_MODE){
  36. IMU_SetSignal(SIGNAL_STANDBY_POWER, IMU_SIGNAL_ON);
  37. send_signal_flag = 1;
  38. }else critical_zone = 0; //解锁
  39. break;
  40. case HAL_MODE_NORMAL:
  41. if(IMU_GetCurrentMode() != STATE_LOW_POWER_MODE){
  42. IMU_SetSignal(SIGNAL_LOW_POWER, IMU_SIGNAL_ON);
  43. send_signal_flag = 1;
  44. }else critical_zone = 0; //解锁
  45. break;
  46. case HAL_MODE_SELF_CHECK:
  47. if(IMU_GetCurrentMode() != STATE_SELF_CHECK_MODE){
  48. IMU_SetSignal(SIGNAL_SELF_CHECK, IMU_SIGNAL_ON);
  49. send_signal_flag = 1;
  50. }else critical_zone = 0; //解锁
  51. break;
  52. default:
  53. break;
  54. }
  55. }
  56. static void Change_Mode(hal_mode mode)
  57. {
  58. switch(mode)
  59. {
  60. case HAL_MODE_GAME:
  61. if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){ //配置失败
  62. change_mode = cur_mode; //回退到上一个模式
  63. send_signal_flag = 0;
  64. critical_zone = 0; //解锁
  65. }else{
  66. if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 3){
  67. cur_mode = HAL_MODE_GAME;
  68. send_signal_flag = 0;
  69. critical_zone = 0; //解锁
  70. }
  71. }
  72. break;
  73. case HAL_MODE_REALSTEP:
  74. if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){
  75. change_mode = cur_mode;
  76. send_signal_flag = 0;
  77. critical_zone = 0; //解锁
  78. }else{
  79. if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 3){
  80. cur_mode = HAL_MODE_REALSTEP;
  81. send_signal_flag = 0;
  82. critical_zone = 0; //解锁
  83. }
  84. }
  85. break;
  86. case HAL_MODE_STANDBY:
  87. if(IMU_GetCurrentMode() != STATE_STANDBY_POWER_MODE){
  88. change_mode = cur_mode;
  89. send_signal_flag = 0;
  90. critical_zone = 0; //解锁
  91. }else{
  92. if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 3){
  93. cur_mode = HAL_MODE_STANDBY;
  94. send_signal_flag = 0;
  95. critical_zone = 0; //解锁
  96. }
  97. }
  98. break;
  99. case HAL_MODE_NORMAL:
  100. if(IMU_GetCurrentMode() != STATE_LOW_POWER_MODE){
  101. change_mode = cur_mode;
  102. send_signal_flag = 0;
  103. critical_zone = 0; //解锁
  104. }else{
  105. if(IMU_Get_Front_Data_Num() >= 10 && IMU_Get_Front_Data_Num() < 13){
  106. cur_mode = HAL_MODE_NORMAL;
  107. send_signal_flag = 0;
  108. critical_zone = 0; //解锁
  109. }
  110. }
  111. break;
  112. case HAL_MODE_SELF_CHECK:
  113. if(IMU_GetCurrentMode() != STATE_SELF_CHECK_MODE){
  114. change_mode = cur_mode;
  115. send_signal_flag = 0;
  116. critical_zone = 0; //解锁
  117. }else{
  118. if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 3){
  119. cur_mode = HAL_MODE_SELF_CHECK;
  120. send_signal_flag = 0;
  121. critical_zone = 0; //解锁
  122. }
  123. }
  124. break;
  125. default:
  126. break;
  127. }
  128. }
  129. static void hal_mode_manage_Process(void)
  130. {
  131. //没有信号的时候处理
  132. if(IMU_IsNoSignal()){
  133. if(!send_signal_flag){ //发送信号
  134. Send_Signal(process_mode);
  135. }else{ //配置判断
  136. Change_Mode(process_mode);
  137. }
  138. }
  139. }
  140. /********************** 外部接口声明区 *************************/
  141. void hal_mode_set(hal_mode mode)
  142. {
  143. static hal_mode screen = HAL_MODE_INIT;
  144. //筛选出优先级最大的
  145. screen = mode > screen ? mode : screen;
  146. change_mode = screen;
  147. SEGGER_RTT_printf(0,"=====>hal_mode_set change_mode:%d critical_zone:%d \r\n",change_mode,critical_zone);
  148. if(!critical_zone){
  149. process_mode = change_mode;
  150. critical_zone = 1; //锁上
  151. screen = HAL_MODE_INIT;
  152. }
  153. }
  154. hal_mode hal_mode_get(void)
  155. {
  156. return cur_mode;
  157. }
  158. static void hal_mode_manage_test_Process(void)
  159. {
  160. // SEGGER_RTT_printf(0,"change_mode=%d cur_mode=%d IMU_Get_Front_Data_Num():%d isWearShoes:%d\r\n",change_mode,cur_mode,IMU_Get_Front_Data_Num(),hal_wearshoes_is_wearshoes());
  161. }
  162. void hal_mode_manage_Init(void)
  163. {
  164. if(INIT_MODE == HAL_MODE_NORMAL){
  165. cur_mode = HAL_MODE_NORMAL;
  166. change_mode = HAL_MODE_NORMAL;
  167. }
  168. else if(INIT_MODE == HAL_MODE_STANDBY){
  169. cur_mode = HAL_MODE_STANDBY;
  170. change_mode = HAL_MODE_STANDBY;
  171. }
  172. Process_Start(0,"hal_mode_manage_Process",hal_mode_manage_Process);
  173. Process_Start(100,"hal_mode_manage_test_Process",hal_mode_manage_test_Process);
  174. }