#include "guide.h" #include "driver.h" #include "env.h" #include "lift.h" #include "screen.h" #include "cargo.h" #include "apptask.h" #include "systick.h" #define DBG_SECTION_NAME "btn" #define DBG_LEVEL DBG_INFO #include static void BtnLogI(char *log, uint8_t *btn_stat) { if(!*btn_stat) { *btn_stat = 1; LOG_I(log); } } /** * @brief 按键线程,判断按键按下,执行相应的操作 * @param * @retval * @note */ void BtnProcess(void* parameter) { static uint8_t rmcEStopEnable = 1; uint8_t InTaskDemoTimer = 0; uint8_t InDecPressTimer = 0; uint8_t btn_down = 0; while (1) { rt_thread_mdelay(100); if (I.BtnCStop) { BtnLogI("BtnCStop pressed", &btn_down); GDEStop(); continue; } if (I.BtnLiftUp) { BtnLogI("BtnLiftUp pressed", &btn_down); Lift_ManualUp_Screw(); S.Status = STATUS_REMOTE_MANUAL; continue; } if (I.BtnLiftDown) { BtnLogI("BtnLiftDown pressed", &btn_down); Lift_ManualDown_Screw(); S.Status = STATUS_REMOTE_MANUAL; continue; } if (I.RmcStart) { /* bug106 */ S.ObsStatus = OBS_STATUS_NULL; S.reset_flag = 1; rmc_start: BtnLogI("RmcStart pressed", &btn_down); InTaskDemoTimer++; InDecPressTimer++; //rmcEStopEnable = 1; GDStart(FR_FORWARD); if (InDecPressTimer < 100) { S.DecPressStatus = 0; BtnLogI("No_DecPress", &btn_down); } if (InDecPressTimer > 200) { S.DecPressStatus = 1; BtnLogI("In_DecPress", &btn_down); } continue; } if (I.RmcStop) { BtnLogI("Stop pressed", &btn_down); GDStop(); continue; } if (I.RmcEStop) { if (rmcEStopEnable == 2) { LOG_I("RmcEStop pressed"); S.estop_flag = 1; GDEStop(); rmcEStopEnable = 1; continue; } } else { if (rmcEStopEnable == 1) { LOG_I("RmcEStop enable"); rmcEStopEnable = 2; Decompression(0); goto rmc_start; } } if (I.BtnRun) { BtnLogI("BtnRun pressed", &btn_down); //rmcEStopEnable = 1; GDStart(FR_FORWARD); continue; } if (I.BtnRev) { BtnLogI("BtnRev pressed Finish Task", &btn_down); Task_FinishCurTransport(); //GDStart(FR_BACKWARD); } if (I.RmcBackward) { BtnLogI("RmcBackward pressed", &btn_down); GD_ManualBackward(); Screen_Icon_Run(Icon_Run); Screen_Icon_Speed(Icon_Mid_Speed); continue; } if (I.RmcForward) { BtnLogI("RmcForward pressed", &btn_down); GD_ManualForward(); Screen_Icon_Run(Icon_Run); Screen_Icon_Speed(Icon_Mid_Speed); continue; } if (I.RmcRoteLeft) { BtnLogI("RmcRoteLeft pressed", &btn_down); Dir_Lift_ManualFB(); Screen_Icon_Run(Icon_Run); Screen_Icon_Speed(Icon_Mid_Speed); continue; } if (I.RmcRoteRight) { BtnLogI("RmcRoteRight pressed", &btn_down); Dir_Lift_ManualLR(); Screen_Icon_Run(Icon_Run); Screen_Icon_Speed(Icon_Mid_Speed); continue; } if (I.RmcDriftLeft) { BtnLogI("RmcDriftLeft pressed", &btn_down); GD_ManualDriftLeft(); Screen_Icon_Run(Icon_Run); Screen_Icon_Speed(Icon_Mid_Speed); continue; } if (I.RmcDriftRight) { BtnLogI("RmcDriftRight pressed", &btn_down); GD_ManualDriftRight(); Screen_Icon_Run(Icon_Run); Screen_Icon_Speed(Icon_Mid_Speed); continue; } if (I.RmcLiftUp) { if (S.DecPressStatus == 1) { Decompression(1); BtnLogI("Decompression pressed(1)", &btn_down); } else { Lift_ManualUp(); S.Status = STATUS_REMOTE_MANUAL; BtnLogI("lift up", &btn_down); } continue; } if (I.RmcLiftDown) { if (S.DecPressStatus == 1) { Decompression(2); BtnLogI("Decompression pressed(1)", &btn_down); } else { Lift_ManualDown(); S.Status = STATUS_REMOTE_MANUAL; BtnLogI("lift down", &btn_down); } continue; } if (S.Status == STATUS_REMOTE_MANUAL) { GD_ManualStop(); Lift_Stop(); Dir_Lift_Stop(); Screen_Icon_Run(Icon_Stop); Screen_Icon_Speed(Icon_Clear); } Decompression(0); InDecPressTimer = 0; InTaskDemoTimer = 0; btn_down = 0; } } static int Btn_Init(void) { static rt_thread_t tid; tid = rt_thread_create("btn", BtnProcess, NULL, 1024, RT_THREAD_PRIORITY_MAX - 6, 10); if (tid) { rt_thread_startup(tid); } return RT_EOK; } INIT_APP_EXPORT(Btn_Init);