/*************************************************  
  File name     : hal_interface_ptz.c
  Module        : hal ptz library interface typedefs
  Author        : Eric.wu@anker.com
  Version       :
  Created on    : 2020-10-22
  Description   :
      Data structure and function definitions required by 
      the ptz interface
    
  Modify History:   
  1. Date:        Author:         Modification:
  2020-10-20    Eric.wu         create
*************************************************/
#include "pal.h"
#include "hal_interface_ptz.h"
#include "hal_product_config.h"
#include "hal_interface.h"


#ifndef HAL_CFG_PTZ_TYPE
#error HAL_CFG_PTZ_TYPE undefined !!! Go to "hal_gernerate_product_config_h.sh" settings
#endif

#if (HAL_CFG_PTZ_TYPE ==  HAL_CFG_PTZ_TYPE_T31)
#include "ms41929_motor.h"
#elif (HAL_CFG_PTZ_TYPE ==  HAL_CFG_PTZ_TYPE_T31_MS41969)
#include "ms41969_motor.h"
#elif (HAL_CFG_PTZ_TYPE ==  HAL_CFG_PTZ_TYPE_MCU)

#endif


ST_HAL_PTZ_INTERFACE g_HAL_PTZ_Itf[] =
{
#if (HAL_CFG_PTZ_TYPE ==  HAL_CFG_PTZ_TYPE_T31)
  {
    .pfnInit             = MS41929_Ctrl_Init,
    .pfnDeinit           = MS41929_Ctrl_Deinit,
    .pfnMove             = MS41929_ctrl_Move,
    .pfnGetStatus        = MS41929_ctrl_Motor_Get_Status,
    .pfnSelfCalibrate    = MS41929_ctrl_Self_Calibrate,
    .pfnPressureTest     = MS41929_ctrl_Pressure_Test,
	.pfnBackToOrigin     = MS41929_ctrl_GoOriginPlace,
	.pfnSetOrigin        = MS41929_ctrl_SetOriginPlace,
	.pfnSetSpeed         = MS41929_ctrl_SetSpeed,
	.pfnStop             = MS41929_ctrl_stop_run,
	.pfnGetOptoOut       = MS41929_ctrl_Motor_Get_OptoOut,
	.pfnSetType          = MS41929_ctrl_SetType,
 },
 #elif (HAL_CFG_PTZ_TYPE ==  HAL_CFG_PTZ_TYPE_T31_MS41969)
  {
    .pfnInit             = MS41969_Ctrl_Init,
    .pfnDeinit           = MS41969_Ctrl_Deinit,
    .pfnMove             = MS41969_ctrl_Move,
    .pfnGetStatus        = MS41969_ctrl_Motor_Get_Status,
    .pfnSelfCalibrate    = MS41969_ctrl_Self_Calibrate,
    .pfnPressureTest     = MS41969_ctrl_Pressure_Test,
	.pfnBackToOrigin     = MS41969_ctrl_GoOriginPlace,
	.pfnSetOrigin        = MS41969_ctrl_SetOriginPlace,
	.pfnSetSpeed         = MS41969_ctrl_SetSpeed,
	.pfnStop             = MS41969_ctrl_stop_run,
	.pfnGetOptoOut       = MS41969_ctrl_Motor_Get_OptoOut,
	.pfnSetType          = NULL,
 },
#elif (HAL_CFG_PTZ_TYPE ==  HAL_CFG_PTZ_TYPE_MCU)
  {
    .pfnInit             = NULL,
    .pfnDeinit           = NULL,
    .pfnMove             = NULL,
    .pfnGetStatus        = NULL,
    .pfnSelfCalibrate    = NULL,
    .pfnPressureTest     = NULL,
	.pfnBackToOrigin     = NULL,
	.pfnSetOrigin        = NULL,
	.pfnSetSpeed         = NULL,
	.pfnStop             = NULL,
	.pfnGetOptoOut       = NULL,
	.pfnSetType          = NULL,
 },
#endif
};

ST_HAL_PTZ_INTERFACE *HAL_PTZ_GetInterface(int32_t Channel)
{

#if (HAL_CFG_PTZ_TYPE == HAL_TYPE_NONE)
    return NULL;
#elif (HAL_CFG_PTZ_TYPE ==  HAL_CFG_PTZ_TYPE_T31_MS41969)
	
		 HAL_ITF_INDEX idx = HAL_SELF;
		if ( Channel <= HAL_CHANNEL_SELF + 1)
		{
			idx = HAL_SELF;
		}
		else
		{
			// 需要从NV获取通道号Channel对应的设备类型对应的hal
			//idx = HAL_REMOTE_SUB1G;
			return NULL;
		}
		return &g_HAL_PTZ_Itf[idx];

#else

    HAL_ITF_INDEX idx = HAL_SELF;

    if ( Channel == HAL_CHANNEL_SELF )
    {
        idx = HAL_SELF;
    }
    else
    {
        // 需要从NV获取通道号Channel对应的设备类型对应的hal
        //idx = HAL_REMOTE_SUB1G;
        return NULL;
    }
    return &g_HAL_PTZ_Itf[idx];
#endif

}

