/*
 * SoftScanConverter.h
 *
 *  Created on: 22/feb/2018
 *      Author: chessaa
 */

#ifndef SOFTSCANCONVERTER_H_
#define SOFTSCANCONVERTER_H_

#include <stdint.h>

class SoftScanConverterDriver;

class SoftScanConverterObject
{
public:
	static SoftScanConverterDriver& instance();
};


class SoftScanConverterDriver
{
public:
	struct ScBuffer
	{
		unsigned int dx;
		unsigned int dy;
		unsigned int pitch;
		uint8_t* buffer;

		unsigned int width() const { return dx;}
		unsigned int height() const { return dy;}
		unsigned int bytesPerLine() const { return pitch;}

		uint8_t* row(int y) { return scanLine(y);}
		uint8_t& at(int x, int y) { return scanLine(y)[x];}

		uint8_t* scanLine(unsigned int y)
		{
			return &buffer[pitch*y];
		}
	};

	struct SweepHeader
	{
		float platform_azimuth;
		float map_reference_azimuth;

		float rbin_len_meters;

		float scan_limit_min;
		float scan_limit_max;

		float azimuth;
		unsigned int rbins;

		float vx;
		float vy;

		unsigned int inversions;
		int direction;	//0=stop, -1=decrese, 1=increase

		const uint8_t* data;
	};

	void enableMapDbg(bool enable);
	void displayWaveforms(bool show=true);

	void setTimestamp(int y, int m, int d, int s, unsigned int tt);

	void updateMessage(int n, const char* msg);
	void displayMessages(bool show=true);

	void addSweep(const SweepHeader& sweep);

	bool setImage(unsigned int bpp, int ox, int oy, int dx, int dy, int stride, int rows, const void* p, float heading=0, float lat=0, float lon=0, float resolutions=0);

	void showWaveforms(unsigned int wfn, unsigned int samples, char* data);

	void generate(void* fb);

	void generateDebug(void* fb);

	//ScBuffer buffer();
	void setZoom(int ox, int oy, float factor);
	void setInterpolation(bool enable);

	void enable(bool ena=true);

	void reset();

	void setGeometry(unsigned int dx, unsigned int dy, unsigned int pitch);

	void setScanVolumeFromSweep(bool from_sweep);
	void setScanVolume(float scan_center, float scan_width);

	void setNavigation(float range_scale, float vx, float vy);

	void setDbsMode(bool enable);

    void simulateSweep(float angle, float* data, int samples, int direction, float f_center, float scan_center, float left_limit, float right_limit);

public:
	class ScImplementation;

	SoftScanConverterDriver(ScImplementation&);

	SoftScanConverterDriver();

	ScImplementation& p_;

	friend class SoftScanConverterObject;
};


#endif /* SOFTSCANCONVERTER_H_ */
