// Motor_ETEL.h: interface for the CMotor_ETEL class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MOTOR_ETEL_H__FC570503_D3D0_404B_91B5_62C2067BD698__INCLUDED_)
#define AFX_MOTOR_ETEL_H__FC570503_D3D0_404B_91B5_62C2067BD698__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "MotorBase.h"

class CMotor_ETEL : public CMotorBase
{
public:
    CMotor_ETEL(CMtrProfile mtrProfile, double *dpPos, CMotionControllerBase *pBaseController);
    virtual ~CMotor_ETEL();

// **************************************************************
// Methods declaration
// **************************************************************

// method to close the axis
    void CloseAxis() override;

// method to initialize and configure the axis
    void ConstructAxis() override;

//  method to On/Off motor
    bool OnMotor() override;
    bool OffMotor() override;

    bool IsBenchDebug() override;

//  method to stop motor with decceleration
    bool DecelStop() override;

//  method to trigger Emergency stop the motor  int EStop();
    bool EmergStop() override;

// method to get commanded position
    bool GetMotorCommandedPosition(int iMtrNo, double *pRaw) override;

// method to get other motor axis IO status
    int GetMotionIOStatus(const CMtrProfile &mtrProfile) override;

// method to get Other axis motor ready status
    BOOL IsMotorReady(const CMtrProfile &mtrProfile) override;

// method to get Other axis Alarm status
    BOOL IsMotorAlarm(const CMtrProfile &mtrProfile) override;

// method to get Other axis negative/ccw limit status
    BOOL IsNegLmtHit(const CMtrProfile &mtrProfile) override;

// method to get Other axis positive/cw limit status
    BOOL IsPosLmtHit(const CMtrProfile &mtrProfile) override;

// method to get Other axis home sensor status
    bool IsMtrOn(const CMtrProfile &mtrProfile) override;

// method to get other motor axis current position
    bool GetMotorPosition(const CMtrProfile &mtrProfile, double *pRawPosition) override;

// method to get motor axis current position error
    bool GetMotorPositionError(double *pRawPositionError) override;

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

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

// method to move absolute
    bool AbsoluteMove(double dPosition, int nMode, PROFILE_CURVE curve) override;

// method to move relative distance
    bool RelativeMove(double dDistance, PROFILE_CURVE curve) override;

// method to move continuously
    int MoveContinuously(bool bCW = true) override;

// method to process interrupt to decode what happen to the motor
    void ProcessInt(int nIntCode = 0) override;

// method to reset single trigger
    int ResetSingleTrigger() override;

// method to set the commanded position register
    bool SetMotorCommandedPosition(double dPosition) override;

// method to set homing modes
    int SetHomeMode(int iHomeMode) override;

// method to set the mechanical coversion factor
    bool RefreshMotorConversionFactor() override;

// method to set multiple trigger
    virtual bool SetMotorMultipleTrigger(const multiple_trigger &trigger) override;

// method to force set the current position
    bool SetMotorPosition(double dPosition) override;

// method to arm multiaxis for simultaneous motion,
// nMode = 0 : Normal multi-axis move
// nMode = 1 : Gantry move
    int SimultaneousMove(int nNoOfAxis, CMtrProfile *mtrProfile,  double *dPosition, double *dStartVel, double *dMaxVel, double *dAcc, int nMode = 0) override;

// method to move motor in s-curve continuously
    int SMoveContinuously(bool bCW = true) override;

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

// method to move profile
    int UpdateProfile() override;

    int GantryEnable(int nNoOfAxis, CMtrProfile *mtrProfile) override;

    int GantryDisable(int nNoOfAxis, CMtrProfile *mtrProfile) override;

    int ResetAlarm(bool bReset) override;

// Stop Motion Time Counter and return the time
    long StopMotionTimeCounter();

// Logging of messages
    void Log(CString csMsg);
private:
    enum ETEL_DRIVE_STATUS
    {
        MOTOR_ON_STATUS,
        MOTOR_READY_STATUS,
        MOTOR_ALARM_STATUS,
    };

// Get Axis Status, Polling, Bus Busy
    dword GetAxisStatusM60();

// Get Other Axis Status M60, Polling, Bus busy
    dword GetAxisStatusM60(CMtrProfile mtrProfile);

// Get Axis Status M63

// Get Other Axis Status M63

// Get Axis Home Complete Status
    bool IsAxisHomeSequenceCompleted();

// Check if axis is in Homing Sequence
    bool IsAxisInHoming();

    bool m_bBenchDebugWithActualHardware;

    BOOL GenerateNewHomePosition();

    DSA_DRIVE_GROUP *m_group;

// method to move profile
    int UpdateProfile(CMtrProfile mtrProfile, int nDepth, double dAcc, double dSpd, double dJerk);

// Gary 28Sep11, V1.29.03 added separate method to set gantry move profile
    int UpdateGantryProfile(int nDepth, double dAcc, double dSpd, double dJerk);

// MIT BT 0000030, Gary Lam 17Jan13, V1.29.08
    int iso_upi_converter(double isovalue, long &lInc);

    int trigger_pulse_generator_event_setting(int ntrigger_event_number, double dtrigger_start_on_position, double dtrigger_direction, long lgenerator_used, double ddelta_position);

    bool ResetDrive();

    bool ResetDriveError();

    bool GetDriveStatus(int nMtrNo, ETEL_DRIVE_STATUS status);

    bool UpdateHomingProfile();

    bool ConfigureTriggerUseRealPosition();
    bool ClearTriggerOutput();
    bool ConfigureTriggerOutput(int nCmpSource);
    bool ConfigureTriggerOutputMask();

    enum PULSE_GENERATOR
    {
        PG1,
        PG2,
    };

    bool ConfigureTriggerOutputPulse(PULSE_GENERATOR pg);
};

#endif // !defined(AFX_MOTOR_ETEL_H__FC570503_D3D0_404B_91B5_62C2067BD698__INCLUDED_)
