-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
133 lines (119 loc) · 4.03 KB
/
widget.cpp
File metadata and controls
133 lines (119 loc) · 4.03 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "widget.hpp"
#include <math.h>
alpha_synapse::Plugin::Plugin(Event::Manager* ev_manager)
: Widgets::Plugin(ev_manager, std::string(alpha_synapse::MODULE_NAME))
{
}
alpha_synapse::Panel::Panel(QMainWindow* main_window,
Event::Manager* ev_manager)
: Widgets::Panel(
std::string(alpha_synapse::MODULE_NAME), main_window, ev_manager)
{
setWhatsThis("Template Plugin");
createGUI(alpha_synapse::get_default_vars(),
{}); // this is required to create the GUI
refresh();
resizeMe();
}
alpha_synapse::Component::Component(Widgets::Plugin* hplugin)
: Widgets::Component(hplugin,
std::string(alpha_synapse::MODULE_NAME),
alpha_synapse::get_default_channels(),
alpha_synapse::get_default_vars())
, gmax(0.0)
, tau(0.0)
, esyn(0.0)
, start_time(RT::OS::getTime())
{
}
void alpha_synapse::Component::execute()
{
const double max_time = 10 * tau;
double Vm = NAN;
// This is the real-time function that will be called
switch (this->getState()) {
case RT::State::EXEC:
// reset stimulus starting time if triggered
if (readinput(1) > 0.5) {
start_time = RT::OS::getTime();
}
Vm = readinput(0); // voltage in V
if (tau <= max_time) {
writeoutput(0, Stimulus() * (Vm - esyn));
setValue<uint64_t>(
PARAMETER::TIME,
(RT::OS::getTime() - start_time) / RT::OS::SECONDS_TO_NANOSECONDS);
} else {
writeoutput(0, 0.0);
setState(RT::State::PAUSE);
}
break;
case RT::State::INIT:
gmax = getValue<double>(PARAMETER::G_MAX) * 1e-9; // initialized in S, display in nS
tau = getValue<double>(PARAMETER::TAU) * 1e-3; // initialized in s, display in ms
esyn = getValue<double>(PARAMETER::E_SYN) * 1e-3; // initialized in V, display in mV
setValue(PARAMETER::TIME, uint64_t {0});
setState(RT::State::PAUSE);
break;
case RT::State::MODIFY:
gmax = getValue<double>(PARAMETER::G_MAX) * 1e-9;
tau = getValue<double>(PARAMETER::TAU) * 1e-3;
esyn = getValue<double>(PARAMETER::E_SYN) * 1e-3;
setState(RT::State::PAUSE);
break;
case RT::State::PERIOD:
break;
case RT::State::PAUSE:
writeoutput(0, 0.0);
break;
case RT::State::UNPAUSE:
start_time = RT::OS::getTime();
writeoutput(0, 0.0);
setState(RT::State::EXEC);
default:
break;
}
}
//void alpha_synapse::Panel::initParameters()
//{
// Widgets::Plugin* hplugin = getHostPlugin();
// hplugin->setComponentParameter(PARAMETER::G_MAX, 4e-9); // S
// hplugin->setComponentParameter(PARAMETER::TAU, 10e-3); // s
// hplugin->setComponentParameter(PARAMETER::E_SYN, -70e-3); // V inhibitory
//}
inline double alpha_synapse::Component::Stimulus() const
{
const auto time = static_cast<double>(RT::OS::getTime() - start_time) * 1e-9;
return gmax * time / tau * exp(-(time - tau) / tau);
}
///////// 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<alpha_synapse::Plugin>(ev_manager);
}
Widgets::Panel* createRTXIPanel(QMainWindow* main_window,
Event::Manager* ev_manager)
{
return new alpha_synapse::Panel(main_window, ev_manager);
}
std::unique_ptr<Widgets::Component> createRTXIComponent(
Widgets::Plugin* host_plugin)
{
return std::make_unique<alpha_synapse::Component>(host_plugin);
}
Widgets::FactoryMethods fact;
extern "C"
{
Widgets::FactoryMethods* getFactories()
{
fact.createPanel = &createRTXIPanel;
fact.createComponent = &createRTXIComponent;
fact.createPlugin = &createRTXIPlugin;
return &fact;
}
};
//////////// END //////////////////////