| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2016-03-06 09:06:59 +01:00
										 |  |  | // Copyright (C) 2016 F4EXB                                                      //
 | 
					
						
							|  |  |  | // written by Edouard Griffiths                                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // OpenGL interface modernization.                                               //
 | 
					
						
							|  |  |  | // See: http://doc.qt.io/qt-5/qopenglshaderprogram.html                          //
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef INCLUDE_GLSCOPE_H
 | 
					
						
							|  |  |  | #define INCLUDE_GLSCOPE_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QGLWidget>
 | 
					
						
							|  |  |  | #include <QPen>
 | 
					
						
							|  |  |  | #include <QTimer>
 | 
					
						
							|  |  |  | #include <QMutex>
 | 
					
						
							| 
									
										
										
										
											2015-10-29 02:35:20 +01:00
										 |  |  | #include <QFont>
 | 
					
						
							| 
									
										
										
										
											2016-03-05 21:54:24 +01:00
										 |  |  | #include <QMatrix4x4>
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "dsp/dsptypes.h"
 | 
					
						
							|  |  |  | #include "dsp/scopevis.h"
 | 
					
						
							| 
									
										
										
										
											2015-07-06 09:17:51 +02:00
										 |  |  | #include "gui/scaleengine.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-05 23:18:26 +01:00
										 |  |  | #include "gui/glshadersimple.h"
 | 
					
						
							|  |  |  | #include "gui/glshadertextured.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "util/export.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-03 03:08:48 +01:00
										 |  |  | #include "util/bitfieldindex.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class ScopeVis; | 
					
						
							| 
									
										
										
										
											2015-10-28 09:27:51 +01:00
										 |  |  | class QPainter; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-30 01:26:51 +02:00
										 |  |  | class SDRANGEL_API GLScope: public QGLWidget { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	enum Mode { | 
					
						
							|  |  |  | 		ModeIQ, | 
					
						
							|  |  |  | 		ModeMagLinPha, | 
					
						
							|  |  |  | 		ModeMagdBPha, | 
					
						
							| 
									
										
										
										
											2015-10-29 09:24:08 +01:00
										 |  |  | 		ModeMagLinDPha, | 
					
						
							|  |  |  | 		ModeMagdBDPha, | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		ModeDerived12, | 
					
						
							| 
									
										
										
										
											2015-11-06 04:40:59 +01:00
										 |  |  | 		ModeCyclostationary, | 
					
						
							|  |  |  | 		ModeIQPolar | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-12 22:22:04 +02:00
										 |  |  | 	enum Displays { | 
					
						
							|  |  |  | 		DisplayBoth, | 
					
						
							|  |  |  | 		DisplayFirstOnly, | 
					
						
							|  |  |  | 		DisplaySecondOnly | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	GLScope(QWidget* parent = NULL); | 
					
						
							|  |  |  | 	~GLScope(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-13 00:50:29 +02:00
										 |  |  | //	void setDSPEngine(DSPEngine* dspEngine);
 | 
					
						
							| 
									
										
										
										
											2015-10-31 12:33:59 +01:00
										 |  |  | 	void setAmp1(Real amp); | 
					
						
							|  |  |  | 	void setAmp1Ofs(Real ampOfs); | 
					
						
							| 
									
										
										
										
											2015-11-01 06:27:39 +01:00
										 |  |  | 	void setAmp2(Real amp); | 
					
						
							|  |  |  | 	void setAmp2Ofs(Real ampOfs); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void setTimeBase(int timeBase); | 
					
						
							|  |  |  | 	void setTimeOfsProMill(int timeOfsProMill); | 
					
						
							|  |  |  | 	void setMode(Mode mode); | 
					
						
							| 
									
										
										
										
											2015-07-12 22:22:04 +02:00
										 |  |  | 	void setDisplays(Displays displays); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void setOrientation(Qt::Orientation orientation); | 
					
						
							| 
									
										
										
										
											2015-06-23 22:52:27 +02:00
										 |  |  | 	void setDisplayGridIntensity(int intensity); | 
					
						
							| 
									
										
										
										
											2015-07-18 11:27:09 +02:00
										 |  |  | 	void setDisplayTraceIntensity(int intensity); | 
					
						
							| 
									
										
										
										
											2015-07-14 01:45:16 +02:00
										 |  |  | 	void setTriggerChannel(ScopeVis::TriggerChannel triggerChannel); | 
					
						
							|  |  |  | 	void setTriggerLevel(Real triggerLevel); | 
					
						
							| 
									
										
										
										
											2015-07-27 02:12:37 +02:00
										 |  |  | 	void setTriggerPre(Real triggerPre); | 
					
						
							| 
									
										
										
										
											2015-11-03 03:08:48 +01:00
										 |  |  | 	void setMemHistoryShift(int value); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void newTrace(const std::vector<Complex>& trace, int sampleRate); | 
					
						
							| 
									
										
										
										
											2015-11-03 03:08:48 +01:00
										 |  |  | 	int getTraceSize() const { return m_rawTrace[m_memTraceIndex - m_memTraceHistory].size(); } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-07 01:17:16 +02:00
										 |  |  | 	void setSampleRate(int sampleRate); | 
					
						
							| 
									
										
										
										
											2015-11-03 08:35:02 +01:00
										 |  |  | 	int getSampleRate() const {	return m_sampleRates[m_memTraceIndex - m_memTraceHistory]; } | 
					
						
							| 
									
										
										
										
											2015-07-12 11:25:55 +02:00
										 |  |  | 	Mode getDataMode() const { return m_mode; } | 
					
						
							| 
									
										
										
										
											2015-08-01 04:07:09 +02:00
										 |  |  | 	void connectTimer(const QTimer& timer); | 
					
						
							| 
									
										
										
										
											2015-07-06 09:17:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-07 05:43:59 +01:00
										 |  |  | 	static const int m_memHistorySizeLog2 = 5; | 
					
						
							| 
									
										
										
										
											2015-11-03 03:08:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | signals: | 
					
						
							|  |  |  | 	void traceSizeChanged(int); | 
					
						
							| 
									
										
										
										
											2015-07-07 01:17:16 +02:00
										 |  |  | 	void sampleRateChanged(int); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	// state
 | 
					
						
							|  |  |  | 	QTimer m_timer; | 
					
						
							|  |  |  | 	QMutex m_mutex; | 
					
						
							|  |  |  | 	bool m_dataChanged; | 
					
						
							|  |  |  | 	bool m_configChanged; | 
					
						
							|  |  |  | 	Mode m_mode; | 
					
						
							| 
									
										
										
										
											2015-07-12 22:22:04 +02:00
										 |  |  | 	Displays m_displays; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	Qt::Orientation m_orientation; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// traces
 | 
					
						
							| 
									
										
										
										
											2015-11-03 03:08:48 +01:00
										 |  |  | 	std::vector<Complex> m_rawTrace[1<<m_memHistorySizeLog2]; | 
					
						
							| 
									
										
										
										
											2015-11-07 05:43:59 +01:00
										 |  |  | 	int m_sampleRates[1<<m_memHistorySizeLog2]; | 
					
						
							| 
									
										
										
										
											2015-11-03 03:08:48 +01:00
										 |  |  | 	BitfieldIndex<m_memHistorySizeLog2> m_memTraceIndex;   //!< current index of trace being written
 | 
					
						
							|  |  |  | 	BitfieldIndex<m_memHistorySizeLog2> m_memTraceHistory; //!< trace index shift into history
 | 
					
						
							| 
									
										
										
										
											2015-11-06 08:56:33 +01:00
										 |  |  | 	int m_memTraceIndexMax; | 
					
						
							| 
									
										
										
										
											2015-11-03 03:08:48 +01:00
										 |  |  | 	bool m_memTraceRecall; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	std::vector<Complex> m_mathTrace; | 
					
						
							|  |  |  | 	std::vector<Complex>* m_displayTrace; | 
					
						
							| 
									
										
										
										
											2015-10-27 04:56:52 +01:00
										 |  |  | 	std::vector<Real> m_powTrace; | 
					
						
							|  |  |  | 	Real m_maxPow; | 
					
						
							|  |  |  | 	Real m_sumPow; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	int m_oldTraceSize; | 
					
						
							|  |  |  | 	int m_sampleRate; | 
					
						
							|  |  |  | 	Real m_amp1; | 
					
						
							|  |  |  | 	Real m_amp2; | 
					
						
							|  |  |  | 	Real m_ofs1; | 
					
						
							|  |  |  | 	Real m_ofs2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// config
 | 
					
						
							|  |  |  | 	int m_timeBase; | 
					
						
							|  |  |  | 	int m_timeOfsProMill; | 
					
						
							|  |  |  | 	ScopeVis::TriggerChannel m_triggerChannel; | 
					
						
							| 
									
										
										
										
											2015-07-14 01:24:59 +02:00
										 |  |  | 	Real m_triggerLevel; | 
					
						
							| 
									
										
										
										
											2015-07-27 02:12:37 +02:00
										 |  |  | 	Real m_triggerPre; | 
					
						
							| 
									
										
										
										
											2015-10-31 12:33:59 +01:00
										 |  |  | 	Real m_triggerLevelDis1; | 
					
						
							|  |  |  | 	Real m_triggerLevelDis2; | 
					
						
							| 
									
										
										
										
											2015-10-27 04:56:52 +01:00
										 |  |  | 	int m_nbPow; | 
					
						
							| 
									
										
										
										
											2015-10-29 09:24:08 +01:00
										 |  |  | 	Real m_prevArg; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// graphics stuff
 | 
					
						
							|  |  |  | 	QRectF m_glScopeRect1; | 
					
						
							|  |  |  | 	QRectF m_glScopeRect2; | 
					
						
							| 
									
										
										
										
											2016-03-05 21:54:24 +01:00
										 |  |  | 	QMatrix4x4 m_glScopeMatrix1; | 
					
						
							|  |  |  | 	QMatrix4x4 m_glScopeMatrix2; | 
					
						
							|  |  |  | 	QMatrix4x4 m_glLeft1ScaleMatrix; | 
					
						
							|  |  |  | 	QMatrix4x4 m_glRight1ScaleMatrix; | 
					
						
							|  |  |  | 	QMatrix4x4 m_glLeft2ScaleMatrix; | 
					
						
							|  |  |  | 	QMatrix4x4 m_glBot1ScaleMatrix; | 
					
						
							|  |  |  | 	QMatrix4x4 m_glBot2ScaleMatrix; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 09:17:51 +02:00
										 |  |  | 	QPixmap m_left1ScalePixmap; | 
					
						
							| 
									
										
										
										
											2015-07-08 02:05:32 +02:00
										 |  |  | 	QPixmap m_left2ScalePixmap; | 
					
						
							|  |  |  | 	QPixmap m_bot1ScalePixmap; | 
					
						
							|  |  |  | 	QPixmap m_bot2ScalePixmap; | 
					
						
							| 
									
										
										
										
											2015-10-28 09:27:51 +01:00
										 |  |  | 	QPixmap m_powerOverlayPixmap1; | 
					
						
							| 
									
										
										
										
											2016-03-05 21:54:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-06 09:06:59 +01:00
										 |  |  | 	int m_displayGridIntensity; | 
					
						
							|  |  |  | 	int m_displayTraceIntensity; | 
					
						
							| 
									
										
										
										
											2016-03-05 21:54:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-08 02:05:32 +02:00
										 |  |  | 	ScaleEngine m_x1Scale; | 
					
						
							|  |  |  | 	ScaleEngine m_x2Scale; | 
					
						
							|  |  |  | 	ScaleEngine m_y1Scale; | 
					
						
							|  |  |  | 	ScaleEngine m_y2Scale; | 
					
						
							| 
									
										
										
										
											2016-03-05 21:54:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 02:35:20 +01:00
										 |  |  | 	QFont m_powerOverlayFont; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 23:18:26 +01:00
										 |  |  | 	GLShaderSimple m_glShaderSimple; | 
					
						
							|  |  |  | 	GLShaderTextured m_glShaderLeft1Scale; | 
					
						
							| 
									
										
										
										
											2016-03-05 23:43:36 +01:00
										 |  |  | 	GLShaderTextured m_glShaderBottom1Scale; | 
					
						
							| 
									
										
										
										
											2016-03-06 02:06:36 +01:00
										 |  |  | 	GLShaderTextured m_glShaderLeft2Scale; | 
					
						
							|  |  |  | 	GLShaderTextured m_glShaderBottom2Scale; | 
					
						
							|  |  |  | 	GLShaderTextured m_glShaderPowerOverlay; | 
					
						
							| 
									
										
										
										
											2016-03-05 23:18:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void initializeGL(); | 
					
						
							|  |  |  | 	void resizeGL(int width, int height); | 
					
						
							|  |  |  | 	void paintGL(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void mousePressEvent(QMouseEvent*); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void handleMode(); | 
					
						
							|  |  |  | 	void applyConfig(); | 
					
						
							| 
									
										
										
										
											2015-10-29 02:35:20 +01:00
										 |  |  | 	void drawPowerOverlay(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected slots: | 
					
						
							| 
									
										
										
										
											2016-03-06 09:33:10 +01:00
										 |  |  | 	void cleanup(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void tick(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_GLSCOPE_H
 |