#pragma once
#include "motorbase.h"

class CMotorAdlinkBase :
    public CMotorBase
{
public:
    CMotorAdlinkBase(void);
    CMotorAdlinkBase(const char* cpMutexName, CMtrProfile mtrProfile, double *dpPos, CMotionControllerBase *pBaseController);
    ~CMotorAdlinkBase(void);

protected:
    void         ConstructAxis() override;
    virtual void ConstructMotor() = 0;

// virtual method to set the motor type and encoder input type
    int          SetMtrType(int iMtrType);
    virtual bool SetMotorType(int iMtrType) = 0;

// virtual method to set the motor alarm signal logic
    int          SetALM(int iALM);
    virtual bool SetMotorAlarmLogic(int iALM) = 0;

// virtual method to set the home sensor signal logic
    int          SetORGI(int iORGI);
    virtual bool SetMotorHomeSensorLogic(int iORGI) = 0;

// virtual method to set the encoder Index signal logic
    int          SetIndexLogic(int iIndexLogic);
    virtual bool SetMotorIndexLogic(int iIndexLogic) = 0;

// virtual method to set the in position signal logic
    int          SetINP(int iINP);
    virtual bool SetMotorINPLogic(int iINP) = 0;

// virtual method to set clk type, out/dir or cw/ccw
    int          SetClk(int iClk);
    virtual bool SetMotorClk(int iClk) = 0;

    int          SetHomeMode(int iHomeMode) override;
    virtual bool SetMotorHomeMode(int iHomeMode) = 0;

    virtual void SetMotorProfile(double dValue, motion_profile::PROFILE_TYPE type);

    // method to do homing by Home Sensor
    virtual BOOL HomeBySensor() override;

// method to do homing by index signal
    virtual BOOL HomeByIndex() override;

    virtual bool SetHomingResetPosition(bool bEnable);

    bool FindHome(HOME_DIR homeDir, MOTION_SPEED speed, bool bToggleHomeSensor);

    virtual bool FindLimit(HOME_DIR homeDir, MOTION_SPEED speed);

    virtual bool EnableLimitInterrupt();

    virtual bool DisableLimitInterrupt();

    void SetVirtualPosition(double dPosition);

    virtual bool StartHomeMove(double dStartSpeed, double dMaxSpeed, double dAcc);

    // method to move continuously
    int          MoveContinuously(bool bCW = true) override;
    int          SMoveContinuously(bool bCW = true) override;
    bool         ContinuousMove(bool bCW, PROFILE_CURVE curve);
    virtual bool StartContinuousMove(double dStartSpeed, double dMaxSpeed, double dAcc);
    virtual bool StartSContinuousMove(double dStartSpeed, double dMaxSpeed, double dAcc, double dSAcc);

    bool         AbsoluteMove(double dPosition, int nMode, PROFILE_CURVE curve) override;
    virtual bool StartAbsoluteMove(double dPosition, double dStartSpeed, double dMaxSpeed, double dAcc, double dDec);
    virtual bool StartSAbsoluteMove(double dPosition, double dStartSpeed, double dMaxSpeed, double dAcc, double dDec, double dSAcc, double dSDec);

    bool         RelativeMove(double dDistance, PROFILE_CURVE curve) override;
    virtual bool StartRelativeMove(double dPosition, double dStartSpeed, double dMaxSpeed, double dAcc, double dDec);
    virtual bool StartSRelativeMove(double dPosition, double dStartSpeed, double dMaxSpeed, double dAcc, double dDec, double dSAcc, double dSDec);

    int          SimultaneousMove(int nNoOfAxis, CMtrProfile *mtrProfile,  double *dPosition, double *dStartVel, double *dMaxVel, double *dAcc, int nMode = 0) override;
    virtual bool GetMotorCommandedPosition(int nNoOfAxis, double *pRaw) = 0;

    virtual bool SetupAbsoluteSimultaneousMove(int nNoOfAxis, short *sAxis, double *dPosition, double *dStartVel, double *dMaxVel, double *dAcc, double *dDec);
    virtual bool SetupRelativeSimultaneousMove(int nNoOfAxis, short *sAxis, double *dPosition, double *dStartVel, double *dMaxVel, double *dAcc, double *dDec);
    virtual bool StartSimultaneousMove(int nFirstAxisNo);
};
