-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpmodel.h
137 lines (92 loc) · 2.79 KB
/
rpmodel.h
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
#ifndef RPMODEL_H
#define RPMODEL_H
// Standard Library
#include <vector>
// DAQmx
// Note that the first **must** be included when importing NIDAQmx header due to mingw
// compiler not detecting Microsoft's __int64 type natively.
// See the following thread:
// forums.ni.com/t5/Multifunction-DAQ/Howto-use-NIDAQmx-with-mingw-gcc-3-4-2/m-p/294361?jump=true
#include <stdio.h>
#include <C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\NIDAQmx.h>
// Qt
#include <QThread>
// Project related
#include <RPThreadController.h>
class Baseline
{
public:
Baseline();
double mean_;
double lower_thresh_;
double upper_thresh_;
void update(double mean, double std_dev, double multiplier);
};
class RPModel : public QObject
{
Q_OBJECT
public:
RPModel();
~RPModel();
// Loop control
RPThreadController* thread_controller_;
// Buffer things
int i_;
unsigned int data_buffer_length_;
unsigned int data_buffer_head_;
std::vector<double> time_buffer_;
std::vector<double> data_buffer_;
double* plot_time_buffer_;
double* plot_data_buffer_;
int plot_data_buffer_length_;
// For plotting the mean, upper thresh, and lower thresh lines
std::vector<double> baseline_time_buffer_;
std::vector<double> baseline_mean_buffer_;
std::vector<double> baseline_lower_thresh_buffer_;
std::vector<double> baseline_upper_thresh_buffer_;
// Processor things
Baseline baseline_;
int baseline_length_;
bool looking_for_event_stop_;
bool looking_for_event_start_;
signals:
// For communicating with other threads.
void request_syringe_switch_direction();
void request_camera_record();
public slots:
void start_main_loop();
private:
///////////////////////////////////////////
// Functions
///////////////////////////////////////////
// DAQmx things
void create_DAQ_task();
void sample_DAQ();
// Buffer
void update_buffer();
void save_buffer();
// Processer
void process_buffer();
void update_baseline(int index);
void look_for_event_start();
void look_for_event_stop();
void increment_i();
void event_start_found();
void event_stop_found();
///////////////////////////////////////////
// Objects
///////////////////////////////////////////
// DAQmx things
TaskHandle daq_task_handle_;
int32 sampling_frequency_; // Total sample rate =
int32 samples_per_channel_; // sampling_frequency_ x samples_per_channel_
uInt32 sample_buffer_length_;
float64* sample_buffer_;
// Parser things
// Plot things
unsigned int decimation_factor_;
unsigned int frames_per_sec_;
unsigned int frame_period_ms_;
unsigned int last_plot_update_time_;
};
#endif // RPMODEL_H