summaryrefslogtreecommitdiffstats
path: root/src/gui/oscilloscope.h
blob: 79e0dbd601985694af33b8b5bedf790c6d825cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   [email protected]                                                    *
 *                                                                         *
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef OSCILLOSCOPE_H
#define OSCILLOSCOPE_H

#ifndef PROBE_H
#ifndef KTECHLAB_H
#ifndef OSCILLOSCOPEDATA_H
#include "oscilloscopewidget.h"
#endif
#endif
#endif

#include "simulator.h"
#include <qmap.h>

class FloatingProbeData;
class LogicProbe;
class LogicProbeData;
class KTechlab;
class Oscilloscope;
class Probe;
class ProbeData;
class VoltageProbe;
class QTimer;
namespace KateMDI { class ToolView; }

typedef QMap< int, ProbeData * > ProbeDataMap;
typedef QMap< int, LogicProbeData * > LogicProbeDataMap;
typedef QMap< int, FloatingProbeData * > FloatingProbeDataMap;

typedef unsigned long long ullong;
typedef long long llong;


#if 0
const double MAX_BITS_PER_S = 100000;

// NOTE: The 10 has to agree with the 2^10 = 1024.0
const int MIN_MAX_LOG_2_DIFF = 10;
const double MIN_BITS_PER_S = MAX_BITS_PER_S / 1024.0;
#else
const double MAX_BITS_PER_S = LOGIC_UPDATE_RATE * 4;

// NOTE: The 18 has to agree with the 2^18 = 262144.0
const int MIN_MAX_LOG_2_DIFF = 18;
const double MIN_BITS_PER_S = MAX_BITS_PER_S / 262144.0;
#endif


/*
Due to strangeness with generation of .[cpp/h] files from .ui files (that is,
my inability to sort it out neatly), files other than those in /src/gui can't
see header files such as "oscilloscopewidget.h", so we have to provide some
interface functions for accessing the functionality in this class
*/
ProbeData * registerProbe( Probe * probe );
void unregisterProbe( int id );
void addOscilloscopeAsToolView( KTechlab *ktechlab );


#ifndef PROBE_H
#ifndef KTECHLAB_H
#ifndef OSCILLOSCOPEDATA_H
/**
@author David Saxton
*/
class Oscilloscope : public OscilloscopeWidget
{
	Q_OBJECT
	public:
		static Oscilloscope * self( KateMDI::ToolView * parent = 0l );
		static QString toolViewIdentifier() { return "Oscilloscope"; }
		virtual ~Oscilloscope();
		
		/**
	 	* Register a probe (that outputs boolean data) with the oscilloscope.
	 	* Returns a unique id that the probe can use to add data points
		 */
		ProbeData * registerProbe( Probe * probe );
		void unregisterProbe( int id );
		/**
		 * Returns the Simulator time since recording started.
		 */
		ullong time() const;
		/**
		 * Returns how much of an increment in value of the oscilloscope slider
		 * is equivalent to one second.
		 */
		int sliderTicksPerSecond() const;
		/**
		 * Returns the number of pixels per second the user has requested to be
		 * displayed.
		 */
		double pixelsPerSecond() const;
		/**
		 * Zoom level; a value between 0 and 1. 0 is maximum zoom out, and 1 is
		 * maximum zoom in.
		 */
		double zoomLevel() const { return m_zoomLevel; }
		/**
		 * Sets the zoom level (and in the process, checks that it is within the
		 * bounds allowed).
		 */
		void setZoomLevel( double zoomLevel );
		/**
		 * Returns the Simulator time as given by the current scrollbar
		 * position.
		 */
		llong scrollTime() const;
		/**
		 * @returns pointer to probe with given id, or NULL if no such probe exists
		 */
		ProbeData * probeData( int id ) const;
		/**
		 * @returns the total number of probes
		 */
		int numberOfProbes() const;
		/**
		 * @returns number of the probe with the given id, starting from 0, or -1 if no such probe
		 */
		int probeNumber( int id ) const;
		
	signals:
		/**
		 * Emitted when a probe is registered
		 */
		void probeRegistered( int id, ProbeData * probe );
		/**
		 * Emitted when a probe is unregistered
		 */
		void probeUnregistered( int id );
		
	public slots:
		/**
		 * Resets all recorded data
		 */
		void reset();
		/**
		 * Called when the zoom slider value was changed.
		 */
		void slotZoomSliderChanged( int value );
		/**
		 * Called when the horizontal scrollbar was scrolled by the user
		 */
		void slotSliderValueChanged( int value );
		/**
		 * Pause the data capture (e.g. user clicked on pause button)
		 */
		void slotTogglePause();
	
	protected:
		void getOldestProbe();
		
// 		bool b_isPaused;
		int m_nextId;
		ProbeData * m_oldestProbe;
		int m_oldestId;
		int m_nextColor; // For giving the probes colours
		
		ProbeDataMap m_probeDataMap;
		LogicProbeDataMap m_logicProbeDataMap;
		FloatingProbeDataMap m_floatingProbeDataMap;
		
		Simulator * m_pSimulator;
		
	protected slots:
		void updateScrollbars();
		
	private:
		Oscilloscope( KateMDI::ToolView * parent );
		
		static Oscilloscope * m_pSelf;
		double m_zoomLevel;
		
		friend class OscilloscopeView;
		friend class ProbePositioner;
};

#endif // OSCILLOSCOPEDATA_H
#endif // KTECHLAB_H
#endif // PROBE_H

#endif // OSCILLOSCOPE_H