//******************************************************************************
//Oscilloscope		-	Library for interfacign with external FPGA oscilloscope
//
//By				-	Yi Yao			http://yyao.ca/
//Date				-	2006-01-05
//******************************************************************************

#ifndef __OSCILLOSCOPE_H
#define __OSCILLOSCOPE_H

#include "Pluto.h"


//**************************************
//Constants

enum OscAmpLevels {	X1 = 0x00,			//Unity gain
					X2 = 0x01,			//Magification of 2
					X5 = 0x02,			//Magification of 5
					X10 = 0x03,			//Magification of 10
					X20 = 0x04,			//Magification of 20
					X50 = 0x05,			//Magification of 50
					X100 = 0x06};		//Magification of 100

//End of constants
//**************************************


//**************************************
//Oscilloscope class

class Oscilloscope {
	private:
		unsigned char	*Buffer;		//Buffer to hold data
		int		BufferLength;			//Number of bytes captured
		int		MaxBufferLength;		//Maximum buffer length

		void	SetReg(int n, unsigned char Value);		//Sets register n to an 8 bit value
		void	SetWord(int n, unsigned int Value);		//Sets a 16 bit word over to fill 2 registers

	public:
		Oscilloscope(int BufferSize);	//Creates an instance with set buffer size
		~Oscilloscope(void);			//Default destructor

		int		OpenConnection(int ComPort);	//Opens connection to oscilloscope via COM port (returns true if error)
		void	CloseConnection(void);			//Closes current connection

		void	SetVerticalShift(float V);		//Sets vertical shift (-5 to 5V)
		void	SetTriggerLevel(float V);		//Sets the trigger level (-5 to 5V)
		void	SetAmplification(OscAmpLevels AmpLevel);		//Sets the amplication level

		void	EnableCapture(void);			//Enables capture and sending of data
		void	DisableCapture(void);			//Disables capture and sending of data

		int		ReadData(char *Buffer, int BufferLength);		//Fills Buffer with data if possible, number of bytes read will be returned
		void	FlushBuffer(void);				//Removes all characters from communication buffer
};

//End of Oscilloscope class
//**************************************


#endif
