btn.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #include "guide.h"
  2. #include "driver.h"
  3. #include "env.h"
  4. #include "lift.h"
  5. #include "screen.h"
  6. #include "cargo.h"
  7. #include "apptask.h"
  8. #include "systick.h"
  9. #define DBG_SECTION_NAME "btn"
  10. #define DBG_LEVEL DBG_INFO
  11. #include <rtdbg.h>
  12. static void BtnLogI(char *log, uint8_t *btn_stat)
  13. {
  14. if(!*btn_stat)
  15. {
  16. *btn_stat = 1;
  17. LOG_I(log);
  18. }
  19. }
  20. /**
  21. * @brief 按键线程,判断按键按下,执行相应的操作
  22. * @param
  23. * @retval
  24. * @note
  25. */
  26. void BtnProcess(void* parameter)
  27. {
  28. static uint8_t rmcEStopEnable = 1;
  29. uint8_t InTaskDemoTimer = 0;
  30. uint8_t InDecPressTimer = 0;
  31. uint8_t btn_down = 0;
  32. while (1)
  33. {
  34. rt_thread_mdelay(100);
  35. if (I.BtnCStop)
  36. {
  37. BtnLogI("BtnCStop pressed", &btn_down);
  38. GDEStop();
  39. continue;
  40. }
  41. if (I.BtnLiftUp)
  42. {
  43. BtnLogI("BtnLiftUp pressed", &btn_down);
  44. Lift_ManualUp_Screw();
  45. S.Status = STATUS_REMOTE_MANUAL;
  46. continue;
  47. }
  48. if (I.BtnLiftDown)
  49. {
  50. BtnLogI("BtnLiftDown pressed", &btn_down);
  51. Lift_ManualDown_Screw();
  52. S.Status = STATUS_REMOTE_MANUAL;
  53. continue;
  54. }
  55. if (I.RmcStart)
  56. {
  57. /* bug106 */
  58. S.ObsStatus = OBS_STATUS_NULL;
  59. S.reset_flag = 1;
  60. rmc_start:
  61. BtnLogI("RmcStart pressed", &btn_down);
  62. InTaskDemoTimer++;
  63. InDecPressTimer++;
  64. //rmcEStopEnable = 1;
  65. GDStart(FR_FORWARD);
  66. if (InDecPressTimer < 100)
  67. {
  68. S.DecPressStatus = 0;
  69. BtnLogI("No_DecPress", &btn_down);
  70. }
  71. if (InDecPressTimer > 200)
  72. {
  73. S.DecPressStatus = 1;
  74. BtnLogI("In_DecPress", &btn_down);
  75. }
  76. continue;
  77. }
  78. if (I.RmcStop)
  79. {
  80. BtnLogI("Stop pressed", &btn_down);
  81. GDStop();
  82. continue;
  83. }
  84. if (I.RmcEStop)
  85. {
  86. if (rmcEStopEnable == 2)
  87. {
  88. LOG_I("RmcEStop pressed");
  89. S.estop_flag = 1;
  90. GDEStop();
  91. rmcEStopEnable = 1;
  92. continue;
  93. }
  94. }
  95. else
  96. {
  97. if (rmcEStopEnable == 1)
  98. {
  99. LOG_I("RmcEStop enable");
  100. rmcEStopEnable = 2;
  101. Decompression(0);
  102. goto rmc_start;
  103. }
  104. }
  105. if (I.BtnRun)
  106. {
  107. BtnLogI("BtnRun pressed", &btn_down);
  108. //rmcEStopEnable = 1;
  109. GDStart(FR_FORWARD);
  110. continue;
  111. }
  112. if (I.BtnRev)
  113. {
  114. BtnLogI("BtnRev pressed Finish Task", &btn_down);
  115. Task_FinishCurTransport();
  116. //GDStart(FR_BACKWARD);
  117. }
  118. if (I.RmcBackward)
  119. {
  120. BtnLogI("RmcBackward pressed", &btn_down);
  121. GD_ManualBackward();
  122. Screen_Icon_Run(Icon_Run);
  123. Screen_Icon_Speed(Icon_Mid_Speed);
  124. continue;
  125. }
  126. if (I.RmcForward)
  127. {
  128. BtnLogI("RmcForward pressed", &btn_down);
  129. GD_ManualForward();
  130. Screen_Icon_Run(Icon_Run);
  131. Screen_Icon_Speed(Icon_Mid_Speed);
  132. continue;
  133. }
  134. if (I.RmcRoteLeft)
  135. {
  136. BtnLogI("RmcRoteLeft pressed", &btn_down);
  137. Dir_Lift_ManualFB();
  138. Screen_Icon_Run(Icon_Run);
  139. Screen_Icon_Speed(Icon_Mid_Speed);
  140. continue;
  141. }
  142. if (I.RmcRoteRight)
  143. {
  144. BtnLogI("RmcRoteRight pressed", &btn_down);
  145. Dir_Lift_ManualLR();
  146. Screen_Icon_Run(Icon_Run);
  147. Screen_Icon_Speed(Icon_Mid_Speed);
  148. continue;
  149. }
  150. if (I.RmcDriftLeft)
  151. {
  152. BtnLogI("RmcDriftLeft pressed", &btn_down);
  153. GD_ManualDriftLeft();
  154. Screen_Icon_Run(Icon_Run);
  155. Screen_Icon_Speed(Icon_Mid_Speed);
  156. continue;
  157. }
  158. if (I.RmcDriftRight)
  159. {
  160. BtnLogI("RmcDriftRight pressed", &btn_down);
  161. GD_ManualDriftRight();
  162. Screen_Icon_Run(Icon_Run);
  163. Screen_Icon_Speed(Icon_Mid_Speed);
  164. continue;
  165. }
  166. if (I.RmcLiftUp)
  167. {
  168. if (S.DecPressStatus == 1)
  169. {
  170. Decompression(1);
  171. BtnLogI("Decompression pressed(1)", &btn_down);
  172. }
  173. else
  174. {
  175. Lift_ManualUp();
  176. S.Status = STATUS_REMOTE_MANUAL;
  177. BtnLogI("lift up", &btn_down);
  178. }
  179. continue;
  180. }
  181. if (I.RmcLiftDown)
  182. {
  183. if (S.DecPressStatus == 1)
  184. {
  185. Decompression(2);
  186. BtnLogI("Decompression pressed(1)", &btn_down);
  187. }
  188. else
  189. {
  190. Lift_ManualDown();
  191. S.Status = STATUS_REMOTE_MANUAL;
  192. BtnLogI("lift down", &btn_down);
  193. }
  194. continue;
  195. }
  196. if (S.Status == STATUS_REMOTE_MANUAL)
  197. {
  198. GD_ManualStop();
  199. Lift_Stop();
  200. Dir_Lift_Stop();
  201. Screen_Icon_Run(Icon_Stop);
  202. Screen_Icon_Speed(Icon_Clear);
  203. }
  204. Decompression(0);
  205. InDecPressTimer = 0;
  206. InTaskDemoTimer = 0;
  207. btn_down = 0;
  208. }
  209. }
  210. static int Btn_Init(void)
  211. {
  212. static rt_thread_t tid;
  213. tid = rt_thread_create("btn", BtnProcess, NULL, 1024, RT_THREAD_PRIORITY_MAX - 6, 10);
  214. if (tid)
  215. {
  216. rt_thread_startup(tid);
  217. }
  218. return RT_EOK;
  219. }
  220. INIT_APP_EXPORT(Btn_Init);