/*
 * 云台模组
 */

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ----------------------------------------------------------------- */
#include "device/device.h" 
#include "cmsis_os2.h" 
#include <stdbool.h>
#include <stdint.h>
/* Exported constants ------------------------------------------------------- */
#define ET16s_OK (0)        /* 运行正常 */
#define ET16s_ERR (-1)      /* 运行时发现了其他错误 */
#define ET16s_ERR_NULL (-2) /* 运行时发现NULL指针 */
#define ET16s_ERR_MODE (-3) /* 运行时配置了错误的CMD_GimbalMode_t */

/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */


/* 遥控器类型 */
// 遥控器状态
typedef enum
{
    RC_DR16,
    RC_LD,
    RC_ET16s,
    Control_loss
} rc_type_t;

/* 拨杆位置 */
typedef enum
{
    ET16S_SW_ERR = 0,
    ET16S_SW_UP = 1,
    ET16S_SW_MID = 3,
    ET16S_SW_DOWN = 2,
} ET16S_SwitchPos_t;


//乐迪
typedef struct
{
  float ch[4];
  int16_t sw[8]; 

} LD_raw_t;

typedef struct
{
  float ch[4];
  int16_t sw[8]; 
} ET16s_raw_t;

// 遥控器数据
typedef struct
{

    rc_type_t rc_type;

//    struct
//    {
//        float ch_l_x; /* 遥控器左侧摇杆横轴值，上为正 */
//        float ch_l_y; /* 遥控器左侧摇杆纵轴值，右为正 */
//        float ch_r_x; /* 遥控器右侧摇杆横轴值，上为正 */
//        float ch_r_y; /* 遥控器右侧摇杆纵轴值，右为正 */

//        ET16S_SwitchPos_t sw_r; /* 右侧拨杆位置 */
//        ET16S_SwitchPos_t sw_l; /* 左侧拨杆位置 */

//    } __attribute__((packed)) DJ;

    struct
    {
        float ch_l_x; /* 遥控器左侧摇杆横轴值，上为正 */
        float ch_l_y; /* 遥控器左侧摇杆纵轴值，右为正 */
        float ch_r_x; /* 遥控器右侧摇杆横轴值，上为正 */
        float ch_r_y; /* 遥控器右侧摇杆纵轴值，右为正 */

        ET16S_SwitchPos_t key_A;
        ET16S_SwitchPos_t key_B;
        ET16S_SwitchPos_t key_C;
        ET16S_SwitchPos_t key_D;
        ET16S_SwitchPos_t key_E;
        ET16S_SwitchPos_t key_F;
        ET16S_SwitchPos_t key_G;
        ET16S_SwitchPos_t key_H;

        int16_t knob_left;  // 左旋钮
        int16_t knob_right; // 右旋钮
    } __attribute__((packed)) ET16s;
		
			ET16s_raw_t raw_data;
		  DEVICE_Header_t header;
} __attribute__((packed)) ET16s_t;

/* Exported functions prototypes -------------------------------------------- */
int8_t REMOTE_Restart(void);
int8_t REMOTE_Init(void);
int8_t REMOTE_StartDmaRecv(void);
bool REMOTE_WaitDmaCplt(uint32_t timeout);


int8_t ET16S_ParseRC(ET16s_t *et16s);

int8_t LD_HandleOffline(const LD_raw_t *LD, ET16s_t *rc); 
int8_t ET16s_HandleOffline(ET16s_t *rc);


#ifdef __cplusplus
}
#endif

