#pragma once
#include "pch.h"
#include "ATPControl_Serial_QT.h"
#include "OControl_USB.h"
#include <atomic>
#include <vector>

typedef struct tagFSInfo
{
	ZZ_U8         ucDeviceModel;
	std::string   strInterface;
	std::string   strSN;
	long          lDepth;
	float         fMinFactor;
	float         fMaxFactor;
}FSInfo;

class CAbstractFSController :public QObject
{
	Q_OBJECT
public:
	CAbstractFSController(QObject* parent = nullptr);
	virtual ~CAbstractFSController();
public:
	std::atomic_int  iFlagInit{ 0 };
public:
	//call first
	virtual int SetRunParas(int iThreadID, FSInfo fsInfo);

	//create derived class from base class 
	virtual int InitializeFSControl();
	virtual int InitializeFSControl_Self();

	//sync info
	virtual int GetDeviceAttr(DeviceAttribute &daAttr);
	//DataFrame GetLastDataFrame();

private:
	CIrisFSBase *m_pFSCtrl;
	int m_iThreadID;
	FSInfo m_fsInfo;
	//DataFrame m_dfDark,m_dfSignal;
	std::vector<DataFrame> m_vecDataFrameDark, m_vecDataFrameSignal;

	DeviceAttribute m_daDeviceAttr;
private:
	 int PerformAutoExposure();
	 int TakeDarkFrame();
	 int TakeSignalFrame();
	 DataFrame TakeOneFrame();
	 int SaveDataFile();

public slots:
	virtual int StartAcquisitionSignal();
	virtual int StartAcquisitionDark();
	virtual int StopAcquisition();
	virtual int ClearBuffer();
	virtual int GetBuffer(std::vector<DataFrame> &pvecDataFrameDark, std::vector<DataFrame> &pvecDataFrameSignal);


signals:
	void SignalInit_Self();
	void SignalAcqStarted();
	void SignalAcqFinished_Signal(int iThreadID, int iFlagStatus);
	void SignalAcqFinished_Dark  (int iThreadID, int iFlagStatus);
};