#ifndef __PTZ_ROATE_CONTROL_H_
#define __PTZ_ROATE_CONTROL_H_
#include "ptz_header_file.h"
#include "ptz_type_select.h"
#include "tmc2160.h"

//步进电机
#ifdef PTZ_SUPER_LIGHT_WORM_STEP_TMC2160_AS5047D_24V
      ///云台水平右转
      #define PTZ_HORI_DIR_RIGHT     3//0
      ///云台水平左转
      #define PTZ_HORI_DIR_LEFT      1
      ///云台处于停止状态
      #define PTZ_HORI_DIR_STOP      2

      ///云台垂直向上
      #define PTZ_VERT_DIR_UP        3//0
      ///云台垂直向下
      #define PTZ_VERT_DIR_DOWN      1
      ///云台处于停止状态
      #define PTZ_VERT_DIR_STOP      2

      ///距离最近刹车点以最小转速运行的距离
      #define PTZ_HORI_BREAK_SPEED_ANGLE  ptz_hori_break_angle()
      #define PTZ_VERT_BREAK_SPEED_ANGLE  ptz_vert_break_angle()

      ///刹车最近距离
      #define PTZ_HORI_STOP_NEAR_DISTANCE    0.005
      ///刹车最远距离
      #define PTZ_HORI_STOP_FAR_DISTANCE     4.0

      ///刹车最近距离
      #define PTZ_VERT_STOP_NEAR_DISTANCE    0.005
      ///刹车最远距离
      #define PTZ_VERT_STOP_FAR_DISTANCE     4.0

      ///云台定位精度，也可用于判断是不是同一个位置
      #define PTZ_HORI_ANGLE_ACCURACY  0.05
      ///云台定位精度，也可用于判断是不是同一个位置
      #define PTZ_VERT_ANGLE_ACCURACY  0.05
#endif

//中型步进电机
#ifdef PTZ_MEDIUM_WORM_STEP_TMC2160_AS5047D_24V
      ///云台水平右转
      #define PTZ_HORI_DIR_RIGHT     1//0
      ///云台水平左转
      #define PTZ_HORI_DIR_LEFT      0//1
      ///云台处于停止状态
      #define PTZ_HORI_DIR_STOP      2

      ///云台垂直向上
      #define PTZ_VERT_DIR_UP        1//0
      ///云台垂直向下
      #define PTZ_VERT_DIR_DOWN      0//1
      ///云台处于停止状态
      #define PTZ_VERT_DIR_STOP      2

      ///距离最近刹车点以最小转速运行的距离
      #define PTZ_HORI_BREAK_SPEED_ANGLE  ptz_hori_break_angle()
      #define PTZ_VERT_BREAK_SPEED_ANGLE  ptz_vert_break_angle()

      ///刹车最近距离
      #define PTZ_HORI_STOP_NEAR_DISTANCE    0.005
      ///刹车最远距离
      #define PTZ_HORI_STOP_FAR_DISTANCE     4.0

      ///刹车最近距离
      #define PTZ_VERT_STOP_NEAR_DISTANCE    0.005
      ///刹车最远距离
      #define PTZ_VERT_STOP_FAR_DISTANCE     4.0

      ///云台定位精度，也可用于判断是不是同一个位置
      #define PTZ_HORI_ANGLE_ACCURACY  0.05
      ///云台定位精度，也可用于判断是不是同一个位置
      #define PTZ_VERT_ANGLE_ACCURACY  0.05
#endif





#ifdef PTZ_STEP_MOTOR

float ptz_vert_break_angle();
float ptz_hori_break_angle();

float ptz_hori_step_v_to_f(float v, unsigned short int microstep_alue);
float ptz_hori_step_f_to_v(float f, unsigned short int microstep_alue);

float ptz_vert_step_v_to_f(float v, unsigned short int microstep_alue);
float ptz_vert_step_f_to_v(float f, unsigned short int microstep_alue);


#ifdef TMC2160
TMC2160Control ptz_hori_choice_microstep(float ptz_v);
TMC2160Control ptz_vert_choice_microstep(float ptz_v);
#endif

void ptz_sem_post_stop_mutex();
void ptz_hori_start(char direction, float speed);
void ptz_hori_stop(unsigned short int time);
void ptz_vert_start(char direction, float speed);
void ptz_vert_stop(unsigned short int time);

void init_rotate_monitor_module(void);
#endif

#endif