#pragma once

#include "RQConstants.h"
#include "NDTSRS2A.h"
#include "NDTSEnums.h"
namespace NDTS
{
namespace RS2A
{
	class TCGInternal : public TCG
{

public :
	TCGInternal();
	virtual ~TCGInternal();
	void initialise();

	// Set a new normalisation value for one A Scan stripe
	// Value is an offset between -255 and +255.
	// aScanIndex is the scan line that is to be adjusted.
	bool setNormalisation(int value, int aScanIndex);

	// 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..255.
	// 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 *pTCGCurve, int numberOfPointsInCurve);

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

	// If normalisation is off, all elements receive the same curve.  If normalisation is on, the values
	// that have been set by setNormalisation are applied.
	void setIsNormalisationOn(bool isNormalisationOn);

	// These functions must be called when the shape of the scan changes to keep the TCG in sync
	void setSamplesPerAScan(int numberOfSamplesPerAScan);
	void setAScansPerBScan(int numberOfAScansPerBScan);
	void setSamplesDropPerAScan(int numberOfSamplesDrop);

	// Don't attempt to send the TCG during a pre-commit when the range and drop are set to
	// various values
	void preCommitStart();
	void preCommitComplete();

private:
	int boardIndex;
	bool isInterfaceTriggered;
	bool isSimpleGain;
	int simpleGain;
	bool isNormalisationOn;

	unsigned char pShadowCurve[NDTS_MAXIMUM_NUMBER_OF_SAMPLES];
	int pointsInShadowCurve;

	int samplesPerAScan;
	int samplesDropPerAScan;
	int aScansPerBScan;

	int pNormalisationValues[NDTS_MAXIMUM_NUMBER_OF_ELEMENTS];
	bool sendCurve();
	bool isInitialised;

	bool isInPreCommit;
};
}}
