-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
119 lines (100 loc) · 3.46 KB
/
widget.cpp
File metadata and controls
119 lines (100 loc) · 3.46 KB
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
/*
Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill
Cornell Medical College
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 3 of the License, or
(at your option) any later version.
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 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/>.
*/
#include <QTimer>
#include "widget.hpp"
#include <rtxi/event.hpp>
mimic_signal::Plugin::Plugin(Event::Manager* ev_manager)
: Widgets::Plugin(ev_manager, std::string(mimic_signal::MODULE_NAME))
{
}
mimic_signal::Panel::Panel(QMainWindow* main_window, Event::Manager* ev_manager)
: Widgets::Panel(
std::string(mimic_signal::MODULE_NAME), main_window, ev_manager)
{
setWhatsThis(
"<p><b>Mimic:</b><br>This module outputs the signal that is used as "
"input with an optional gain and offset applied..</p>");
createGUI(get_default_vars(), {});
QTimer::singleShot(0, this, SLOT(resizeMe()));
}
mimic_signal::Component::Component(Widgets::Plugin* hplugin)
: Widgets::Component(hplugin,
std::string(mimic_signal::MODULE_NAME),
mimic_signal::get_default_channels(),
mimic_signal::get_default_vars())
, gain(1.0)
, offset(0.0)
{
}
void mimic_signal::Component::execute()
{
// This is the real-time function that will be called
switch (this->getState()) {
case RT::State::EXEC:
writeoutput(0, readinput(0) * gain + offset);
break;
case RT::State::INIT:
gain = getValue<double>(PARAMETER::GAIN);
offset = getValue<double>(PARAMETER::OFFSET);
setState(RT::State::PAUSE);
break;
case RT::State::MODIFY:
gain = getValue<double>(PARAMETER::GAIN);
offset = getValue<double>(PARAMETER::OFFSET);
setState(RT::State::EXEC);
break;
case RT::State::PERIOD:
setState(RT::State::EXEC);
break;
case RT::State::PAUSE:
break;
case RT::State::UNPAUSE:
setState(RT::State::EXEC);
break;
default:
break;
}
}
///////// DO NOT MODIFY BELOW //////////
// The exception is if your plugin is not going to need real-time functionality.
// For this case just replace the craeteRTXIComponent return type to nullptr.
// RTXI will automatically handle that case and won't attach a component to the
// real time thread for your plugin.
std::unique_ptr<Widgets::Plugin> createRTXIPlugin(Event::Manager* ev_manager)
{
return std::make_unique<mimic_signal::Plugin>(ev_manager);
}
Widgets::Panel* createRTXIPanel(QMainWindow* main_window,
Event::Manager* ev_manager)
{
return new mimic_signal::Panel(main_window, ev_manager);
}
std::unique_ptr<Widgets::Component> createRTXIComponent(
Widgets::Plugin* host_plugin)
{
return std::make_unique<mimic_signal::Component>(host_plugin);
}
Widgets::FactoryMethods fact;
extern "C"
{
Widgets::FactoryMethods* getFactories()
{
fact.createPanel = &createRTXIPanel;
fact.createComponent = &createRTXIComponent;
fact.createPlugin = &createRTXIPlugin;
return &fact;
}
}
//////////// END //////////////////////