RTXI  3.0.0
The Real-Time eXperiment Interface Reference Manual
oscilloscope.hpp
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah,
4  Weill Cornell Medical College
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19  */
20 
21 /*
22  Oscilloscope namespace. The namespace works with
23  both Scope and Panel classes to instantiate an oscilloscope
24  plugin.
25  */
26 
27 #ifndef OSCILLOSCOPE_H
28 #define OSCILLOSCOPE_H
29 
30 #include <QComboBox>
31 
32 #include "event.hpp"
33 #include "fifo.hpp"
34 #include "io.hpp"
35 #include "rt.hpp"
36 #include "scope.hpp"
37 #include "widgets.hpp"
38 
39 namespace Oscilloscope
40 {
41 
42 constexpr std::string_view MODULE_NAME = "Oscilloscope";
43 
44 enum PARAMETER : size_t
45 {
47 };
48 
49 inline std::vector<Widgets::Variable::Info> get_default_vars()
50 {
51  return {{PARAMETER::TRIGGERING,
52  "Trigger State",
53  "Trigger activity for the oscilloscope",
56 }
57 
58 inline std::vector<IO::channel_t> get_default_channels()
59 {
60  return {{"Probing Channel",
61  "This is the channel used by the osciloscope to probe on other "
62  "inputs and "
63  "output ports",
64  IO::INPUT}};
65 }
66 
68 {
69 public:
70  // We are forced to have a default constructor for Oscilloscope probes
71  // if we wish to be able to have them as values in a c++ standard map
72  Component(Widgets::Plugin* hplugin, const std::string& probe_name);
73  void flushFifo();
74  RT::OS::Fifo* getFifoPtr() { return this->fifo.get(); }
75  void execute() override;
76 
77 private:
78  std::unique_ptr<RT::OS::Fifo> fifo;
79 };
80 
81 class Panel : public Widgets::Panel
82 {
83  Q_OBJECT
84 
85 public:
86  Panel(QMainWindow* mw, Event::Manager* ev_manager);
87 
88  void setActivity(IO::endpoint endpoint, bool activity);
89  void adjustDataSize();
90  void updateTrigger();
91 
92 signals:
95 
96 public slots:
97  void togglePause();
98 
99 private slots:
100  void syncBlockInfo();
101  void showChannelTab();
102  void showDisplayTab();
103  void buildChannelList();
104  void screenshot();
105  void apply();
106  void showTab(int index);
107  void activateChannel(bool active);
108  void removeBlockChannels(IO::Block* block);
109  void syncChannelProperties();
110 
111 private:
112  void buildBlockList();
113  void enableChannel();
114  void disableChannel();
115 
116  // some utility functions
117  void updateChannelLabel(IO::endpoint probe_info);
118  void updateChannelScale(IO::endpoint probe_info);
119  void updateChannelOffset(IO::endpoint probe_info);
120  void updateChannelPen(IO::endpoint endpoint);
121  void updateWindowTimeDiv();
122 
123  // Tab Widget
124  QTabWidget* tabWidget = nullptr;
125 
126  // Create scope
127  Scope* scopeWindow = nullptr;
128 
129  // Create curve element
130  QwtPlotCurve* curve = nullptr;
131 
132  // Functions to initialize and
133  // apply changes made in tabs
134  void applyChannelTab();
135  void applyDisplayTab();
136  QWidget* createChannelTab(QWidget* parent);
137  QWidget* createDisplayTab(QWidget* parent);
138 
139  // Group and layout information
140  QVBoxLayout* layout = nullptr;
141  QWidget* scopeGroup = nullptr;
142  QGroupBox* setBttnGroup = nullptr;
143 
144  // Properties
145  // QSpinBox* ratesSpin=nullptr;
146  QLineEdit* sizesEdit = nullptr;
147  QButtonGroup* trigsGroup = nullptr;
148  QComboBox* timesList = nullptr;
149  QComboBox* trigsChanList = nullptr;
150  QComboBox* trigsThreshList = nullptr;
151  QComboBox* refreshDropdown = nullptr;
152  QLineEdit* trigsThreshEdit = nullptr;
153  QLineEdit* trigWindowEdit = nullptr;
154  QComboBox* trigWindowList = nullptr;
155 
156  // Lists
157  QComboBox* blocksListDropdown = nullptr;
158  QComboBox* typesList = nullptr;
159  QComboBox* channelsList = nullptr;
160  QComboBox* colorsList = nullptr;
161  QComboBox* offsetsList = nullptr;
162  QComboBox* scalesList = nullptr;
163  QComboBox* stylesList = nullptr;
164  QComboBox* widthsList = nullptr;
165  QLineEdit* offsetsEdit = nullptr;
166 
167  // Buttons
168  QPushButton* pauseButton = nullptr;
169  QPushButton* settingsButton = nullptr;
170  QPushButton* applyButton = nullptr;
171  QPushButton* activateButton = nullptr;
172 
173 }; // Panel
174 
175 class Plugin : public Widgets::Plugin
176 {
177 public:
178  explicit Plugin(Event::Manager* ev_manager);
179  Plugin(const Plugin&) = delete;
180  Plugin(Plugin&&) = delete;
181  Plugin& operator=(const Plugin&) = delete;
182  Plugin& operator=(Plugin&&) = delete;
183  ~Plugin() override;
184 
185  void receiveEvent(Event::Object* event) override;
187  void deleteProbe(IO::endpoint probe_info);
188  void deleteAllProbes(IO::Block* block);
189  Oscilloscope::Trigger::Info getTriggerInfo() { return this->trigger_info; }
190  void setProbeActivity(IO::endpoint endpoint, bool activity);
191  std::vector<IO::endpoint> getTrackedEndpoints();
192  void setAllProbesActivity(bool activity);
194 
195 private:
196  struct registry_entry_t
197  {
199  std::unique_ptr<Oscilloscope::Component> component;
200  };
201  // List to maintain multiple scopes
202  std::vector<registry_entry_t> m_component_registry;
203  Trigger::Info trigger_info;
204 }; // Plugin
205 
206 std::unique_ptr<Widgets::Plugin> createRTXIPlugin(Event::Manager* ev_manager);
207 
208 Widgets::Panel* createRTXIPanel(QMainWindow* main_window,
209  Event::Manager* ev_manager);
210 
211 std::unique_ptr<Widgets::Component> createRTXIComponent(
212  Widgets::Plugin* host_plugin);
213 
215 } // namespace Oscilloscope
216 
217 #endif // OSCILLOSCOPE_H
Definition: io.hpp:79
Component(Widgets::Plugin *hplugin, const std::string &probe_name)
void execute() override
RT::OS::Fifo * getFifoPtr()
void updateBlockChannels(IO::Block *block)
Panel(QMainWindow *mw, Event::Manager *ev_manager)
void setActivity(IO::endpoint endpoint, bool activity)
Plugin(Event::Manager *ev_manager)
Plugin & operator=(Plugin &&)=delete
Oscilloscope::Trigger::Info getTriggerInfo()
Plugin(Plugin &&)=delete
Plugin(const Plugin &)=delete
void receiveEvent(Event::Object *event) override
void setProbeActivity(IO::endpoint endpoint, bool activity)
void deleteProbe(IO::endpoint probe_info)
Oscilloscope::Component * getProbeComponentPtr(IO::endpoint endpoint)
RT::OS::Fifo * createProbe(IO::endpoint probe_info)
std::vector< IO::endpoint > getTrackedEndpoints()
void setAllProbesActivity(bool activity)
void deleteAllProbes(IO::Block *block)
Plugin & operator=(const Plugin &)=delete
@ INPUT
Definition: io.hpp:54
struct IO::endpoint endpoint
struct Oscilloscope::Trigger::Info Info
constexpr std::string_view MODULE_NAME
std::unique_ptr< Widgets::Plugin > createRTXIPlugin(Event::Manager *ev_manager)
Widgets::FactoryMethods getFactories()
std::unique_ptr< Widgets::Component > createRTXIComponent(Widgets::Plugin *host_plugin)
std::vector< Widgets::Variable::Info > get_default_vars()
Widgets::Panel * createRTXIPanel(QMainWindow *main_window, Event::Manager *ev_manager)
std::vector< IO::channel_t > get_default_channels()
@ INIT
Definition: rt.hpp:54