-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpcontroller.cpp
158 lines (103 loc) · 4.13 KB
/
rpcontroller.cpp
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
// Standard library
#include <iostream>
// Program specific
#include "rpcontroller.h"
// Qt
#include <QThread>
RPController::RPController(MainModel* main_model, MainView* main_view)
{
main_model_ = main_model;
main_view_ = main_view;
rp_plot_period_ = (1000./30);
rp_plot_timer_ = new QTimer();
rp_plot_timer_->setInterval(rp_plot_period_);
// Set up thread and thread controller
rp_thread_ = NULL;
rp_thread_controller_ = new RPThreadController();
main_model_->rp_model().thread_controller_ = rp_thread_controller_;
setup_connections();
}
RPController::~RPController()
{
rp_thread_controller_->set_run(false);
delete rp_thread_controller_;
}
void RPController::setup_connections()
{
//main_view_->qwt_series_data_time_;
//main_view_->qwt_series_data_time_;
// Shared buffers
main_view_->rp_plot_curve_->setRawSamples(\
main_model_->rp_model().plot_time_buffer_,\
main_model_->rp_model().plot_data_buffer_,\
main_model_->rp_model().plot_data_buffer_length_\
);
main_view_->rp_baseline_mean_plot_curve_->setRawSamples(\
&main_model_->rp_model().baseline_time_buffer_.front(),
&main_model_->rp_model().baseline_mean_buffer_.front(),
2);
main_view_->rp_baseline_lower_thresh_plot_curve_->setRawSamples(\
&main_model_->rp_model().baseline_time_buffer_.front(),
&main_model_->rp_model().baseline_lower_thresh_buffer_.front(),
2);
main_view_->rp_baseline_upper_thresh_plot_curve_->setRawSamples(\
&main_model_->rp_model().baseline_time_buffer_.front(),
&main_model_->rp_model().baseline_upper_thresh_buffer_.front(),
2);
main_view_->rp_plot_->setAxisScale(0, -.1, 0.1, 0);
// View requests
QObject::connect(main_view_->rp_start_button_, SIGNAL(clicked()),\
this, SLOT(receive_request_view_start_main_loop()));
QObject::connect(main_view_->rp_set_threshold_multiplier_button_, SIGNAL(clicked()),
this, SLOT(receive_request_view_set_threshold_multiplier()));
QObject::connect(main_view_->rp_set_control_mode_button_, SIGNAL(clicked()),
this, SLOT(receive_request_view_set_control_mode()));
// Timers
QObject::connect(main_view_->rp_start_button_, SIGNAL(clicked()), rp_plot_timer_, SLOT(start()));
QObject::connect(rp_plot_timer_, SIGNAL(timeout()), main_view_->rp_plot_, SLOT(replot()));
QObject::connect(rp_plot_timer_, SIGNAL(timeout()), this->rp_plot_timer_, SLOT(start()));
return;
}
void RPController::receive_request_view_start_main_loop()
{
rp_thread_controller_->set_run(true);
rp_thread_ = new QThread();
main_model_->rp_model().moveToThread(rp_thread_);
///////////////////////////
// Control flow connections
///////////////////////////
// Connect start thread to start main loop
connect(rp_thread_, SIGNAL(started()), &main_model_->rp_model(), SLOT(start_main_loop()));
// Connect end main loop to stop thread
connect(main_view_->rp_stop_button_, SIGNAL(clicked()), rp_thread_controller_, SLOT(stop_run()));
connect(main_view_->rp_stop_button_, SIGNAL(clicked()), rp_thread_, SLOT(quit()));
// Connect stop thread to delete thread
connect(rp_thread_, SIGNAL(finished()), rp_thread_, SLOT(deleteLater()));
///////////////////////////
// Interactive connections
///////////////////////////
rp_thread_->start();
return;
}
void RPController::receive_request_view_set_threshold_multiplier()
{
rp_thread_controller_->set_threshold_multiplier(main_view_->rp_threshold_multiplier_field_->text().toDouble());
return;
}
void RPController::receive_request_record()
{
rp_thread_controller_->set_save_buffer(true);
return;
}
void RPController::receive_request_view_set_control_mode()
{
if(rp_thread_controller_->control_syringe() == false)
{
rp_thread_controller_->set_control_mode(true);
}
else
{
rp_thread_controller_->set_control_mode(false);
}
return;
}