#pragma once

#include "NDTS2100Sdk.h"
#include "NDTSEnums.h"
namespace NDTS
{
namespace NDTS2100
{
	class TCGInternal : public TCG
{

public :
	static const int maxPointsPerCurve = 256000;
	static const int tcgMaxValue = 4095;
	TCGInternal();
	virtual ~TCGInternal();
	void initialise();

	// Set a new TCG curve.  There should be a value for each sample in the scan
	// The values of the curve should be from 0..4096 (12 bit curve on NDTS2100)
	// numberOfPointsInCurve should match the number of samples per A Scan.
	// The curve will be extended by 0 values if numberOfPointsInCurve is too small
	bool setCurve(int cardIndex, int sequenceStep, int *pTCGCurve, int numberOfPointsInCurve);

	// If isInterfaceTriggered is true, the TCG will start being applied when the interface gate is triggered
	void setIsInterfaceTriggered(int cardIndex, int sequenceStep, bool isInterfaceTriggered);
	// If isSimpleGain, use the simpleGain value for all points in the A Scan, otherwise use the shadow TCG curve
	void setIsSimpleGain(int cardIndex, int sequenceStep, bool isSimpleGain);
	// The simple gain value from 0..4096 that can be applied instead of the TCG curve
	void setSimpleGain(int cardIndex, int sequenceStep, int  simpleGain);

	// These functions must be called when the shape of the scan changes to keep the TCG in sync
	void setSamplesPerAScan(int cardIndex, int sequenceStep, int numberOfSamplesPerAScan);
	void setNumberOfSteps(int cardIndex, int numberOfSteps);
	void setSamplesDropPerAScan(int cardIndex, int sequenceStep, int numberOfSamplesDrop);

private:
	bool isInterfaceTriggered[maxCards][maxSteps];
	bool isSimpleGain[maxCards][maxSteps];
	int simpleGain[maxCards][maxSteps];

	int samplesPerAScan[maxCards][maxSteps];
	int samplesDropPerAScan[maxCards][maxSteps];
	int steps[maxCards];

	short pShadowCurve[maxCards][maxSteps][NDTS_MAXIMUM_NUMBER_OF_SAMPLES];

	bool sendCurve(int card, int step);
	bool isInitialised;
};
}}
