// InputController.h: interface for the CInputController class.
//
//////////////////////////////////////////////////////////////////////
#pragma once

#include <array>
#include <vector>

#include "hardwareini.h"
#include "InputControllerBase.h"

#ifdef BUILD_IODLL
#define IODLLCLASS __declspec(dllexport)
#else
#define IODLLCLASS __declspec(dllimport)
#endif

class CInputSetting;

class IODLLCLASS CIpStatus
{
public:
    char m_cPtName[100];
    bool m_bOn;
};

class IODLLCLASS CInputController : public CCard
{
public:
    friend UINT InputControllerThreadFn(LPVOID pParam);

    CInputController();
    virtual ~CInputController();

    BOOL GetVoltage(const CInputSetting& InputSetting, double& dVoltage, int nRange);

    BOOL InitController();

    BOOL IsOff(const CInputSetting& InputSetting);

    BOOL IsOn(const CInputSetting& InputSetting);

    /***********************************************************************/
    /*********************currently for 9222 ONLY***************************/

    // method to setup general counter
    BOOL SetupCounter(const CInputSetting& InputSetting, int nMode);

    // method to clear counter
    BOOL ClearCounter(const CInputSetting& InputSetting);

    // method to enable counter counting
    BOOL EnableCounter(const CInputSetting& InputSetting);

    // method to disable counter counting
    BOOL DisableCounter(const CInputSetting& InputSetting);

    // method read the counter
    unsigned long ReadCounter(const CInputSetting& InputSetting);

    static CInputController* GetInstance();
    CInputControllerBase* GetController(int nCardType);

    void StartUpdateThread();

    void TerminateThread();

    void StartUpdate(bool bStartUpdate);

    // for bench debug testing
    void SetSimulationIO(const std::vector<std::string>& vecSimulationIO)
    {
        m_vecSimulationIO = vecSimulationIO;
    }

    const std::vector<std::string>& GetSimulationIO()
    {
        return m_vecSimulationIO;
    }

private:
    std::array<CInputControllerBase*, MAX_INPUT_CARD_TYPE> m_inputControllerBase{};

    int m_nNoOfCardType{ 0 };
    CHardwareIni m_iniHardware;
    std::vector<stCard> m_vecCard;

    std::vector<std::string> m_vecSimulationIO;

    static CInputController* instance;

    CWinThread* m_pThread{ nullptr };

    CEvt m_evtTerminate;
    CEvt m_evtStartUpdate{ "INPUT CONTROLLER START UPDATE" };
};
