#ifndef BALL_HPP
#define BALL_HPP
#include "main.h"
#include "TopDefine.h"
#include "cmsis_os.h"
#include "FreeRTOS.h"
#include <cmsis_os2.h>
#include "bsp_delay.h"
#include "djiMotor.h"
#include "pid.h"
#include "filter.h"
#include "calc_lib.h"



// 定义状态枚举
typedef enum {
    BALL_IDLE,         // 空闲状态
    BALL_FORWARD,      // 
    BALL_DROP,         // 
    BALL_FLAG,
    BALL_CLOSE,         // 关闭状态
    BALL_FINISH,        // 完成状态

  //持球状态
    BALL_TAKE,
    EXTEND_DOWN,
    EXTEND_OUT,
    EXTEND_FINISH,
    BALL_LOSE,

} BallState_t;


typedef enum
{
    UP2=1,
    MIDDLE2,
    DOWN2,
    IN,
    OUT,
    SIDE,
    DEF
}ball_rc_mode;

// 定义光电传感器检测宏
#define IS_PHOTOELECTRIC_BALL() (HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin) == GPIO_PIN_RESET)

class Ball
{
public:
    Ball();
    void ballHadling(void);
    void ballDown(void);
    void Send_control(void);
    void Move_Extend(void);
    void Idle_control(void);
    void rc_mode(void);
    void test_Handling(void);
    void ball_control(void);
  
    BallState_t currentState1; // 运球任务状态机
      int flag_thread;//暂时还没用到
	  int ball_state ;//光电检测
    

    //小米电机伸缩
    MotorFeedback_t *feedback;
    JZ_xiaomi_t xiaomi;


//==========================公共变量==========================//
    int16_t rc_key; //遥控器按键
    int16_t extern_key;
    int16_t ready_key; //准备按键
    //用于传接球,运球后通知
    volatile uint32_t hand_thread;//接收传回的线程通知

private:  
    bool haveball;

    
};

#endif
