#include "ccam_mv.h"

CCam_MV::CCam_MV(const QString &name, int32_t id)
    :CCam(name,id)
{
    m_MVCamHandle=-1;
}

int32_t CCam_MV::init_channel()
{
    MVCAMFUN(CameraInit(&m_MVCamInfo,-1,-1,&m_MVCamHandle));
    MVCAMFUN(CameraGetCapability(m_MVCamHandle,&m_MVCamCapbility));

    MVCAMFUN(CameraSetTriggerMode(m_MVCamHandle,0));
    MVCAMFUN(CameraSetIspOutFormat(m_MVCamHandle, CAMERA_MEDIA_TYPE_MONO8));

    MVCAMFUN(CameraSetAeState(m_MVCamHandle,false));
    MVCAMFUN(CameraPlay(m_MVCamHandle));


    int iWidth=m_MVCamCapbility.pImageSizeDesc->iWidth;
    int iHeight=m_MVCamCapbility.pImageSizeDesc->iHeight;

    bool bFold=m_Variants.get_VData(Var_Cam_Image_Fold)->toBool();
    if(bFold)
    {
        iWidth/=2;iHeight/=2;
    }
    MqDebug()<<m_sName<<iWidth<<iHeight;
    m_Variants.set_VData(Var_Cam_Width_ID,int(iWidth));
    m_Variants.set_VData(Var_Cam_Height_ID,int(iHeight));

    m_pRawImageData=new uint8_t[iHeight*iWidth];
    memset(m_pRawImageData,0,iHeight*iWidth);
    return CCam::init_channel();
}

int32_t CCam_MV::exit_channel()
{
    if(m_MVCamHandle>0)
    {
        CameraStop(m_MVCamHandle);
        CameraUnInit(m_MVCamHandle);
        m_MVCamHandle=-1;
    }
    return CCam::exit_channel();
}

