-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
171 lines (138 loc) · 4.37 KB
/
mainwindow.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "iostream"
#include <time.h>
#include <QFile>
using namespace std ;
// Construct the main window and related buttons
// as well as initialize spectrometer X123 class
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
char conffile [240] ;
ui->setupUi(this);
haveSpec = false ;
// create the x123 instance
x123 = new X123 () ;
// get the spectrometer
getSpectrometer() ;
strcpy (conffile,"C:/Users/przem/workdir/X123/PX5_Console_Test.txt") ;
x123->ReadConfigFile(conffile) ;
x123->ClearSpectrum () ;
nptsSpec = x123->nptsSpec ;
xvals = new float [nptsSpec] ;
yvals = new float [nptsSpec] ;
for (int i=0; i<nptsSpec; i++){
xvals [i]=i;
yvals [i]=0;
}
ui->SpectrumPlot->setXYData (xvals, yvals, nptsSpec) ;
ui->acquireButton->setStyleSheet("color:yellow;background-color:green") ;
totalSecs = 0 ;
// set acquisition time to 20 seconds
curTime = 20 ;
x123->SendPresetAcquisitionTime(curTime) ;
// connect signals to slots
connect (x123, SIGNAL(updData(int)), this, SLOT(newdata(int))) ;
connect (x123, SIGNAL(endAcquire()), this, SLOT(endAcquire())) ;
connect (x123, SIGNAL(sendStatus(QString)), this, SLOT(setStatusLabel(QString))) ;
}
MainWindow::~MainWindow()
{
if (haveSpec) {
x123->DisconnectUSB() ;
}
delete ui;
delete [] xvals ;
delete [] yvals ;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
// connect to the spectrometer
bool MainWindow::getSpectrometer() {
haveSpec = x123->ConnectUSB() ;
if (haveSpec){
setStatusLabel ("Spectrometer connected") ;
} else {
setStatusLabel ("No spectrometer connected") ;
return false ;
}
x123->GetDppStatus() ;
return true ;
}
// put string in status window
void MainWindow::setStatusLabel (QString s){
QString status ("Status : "+s) ;
ui->statusLabel->setText (status) ;
}
// user interface event handler for acquire button
void MainWindow::on_acquireButton_clicked()
{
this->setCursor (Qt::WaitCursor) ;
int timeSecs = ui->accumTimeLE->text().toInt() ;
this->getOutputSpectrumFile () ;
if (timeSecs != curTime){
x123->SendPresetAcquisitionTime(timeSecs) ;
curTime = timeSecs ;
}
ui->acquireButton->setStyleSheet("color:black;background-color:yellow") ;
totalSecs = 0 ;
x123->StartAcquisition() ;
}
// get timestamped ouput file
void MainWindow::getOutputSpectrumFile() {
time_t curtime ;
struct tm *loctime ;
char timestring[80] ;
curtime = time(NULL) ;
loctime = localtime (&curtime) ;
QString str = ui->PrefixLE->text() ;
sprintf (timestring,"_%04d%02d%02d%02d%02d%02d.mca", loctime->tm_year+1900,
loctime->tm_mon+1,
loctime->tm_mday, loctime->tm_hour, loctime->tm_min, loctime->tm_sec);
QString str1 = QString("%1%2").arg(str).arg(timestring);
QFile tstr (str1) ;
bool status = tstr.isWritable() ;
status = true ;
if (!status){
QMessageBox::warning (this, tr("X123 Control"),
tr ("Could not save to file"), QMessageBox::Ok) ;
}
x123->SetSpectrumFile (str1.toLatin1().data()) ;
}
void MainWindow::newdata() {
int i ;
for (i=0;i<nptsSpec;i++)yvals[i] = x123->specData[i];
ui->SpectrumPlot->setXYData (xvals, yvals, nptsSpec) ;
setStatusLabel ("Updating spectrum") ;
}
void MainWindow::newdata(int secs) {
int i ;
QString statstring = QString ("Updating spectrum : %1 secs").arg (secs);
for (i=0;i<nptsSpec;i++)yvals[i] = x123->specData[i];
ui->SpectrumPlot->setXYData (xvals, yvals, nptsSpec) ;
setStatusLabel (statstring) ;
}
void MainWindow::endAcquire() {
int i ;
for (i=0;i<nptsSpec;i++)yvals[i] = x123->specData[i];
ui->SpectrumPlot->setXYData (xvals, yvals, nptsSpec) ;
setStatusLabel ("Acquisition Complete") ;
ui->acquireButton->setStyleSheet("color:yellow;background-color:green") ;
this->setCursor (Qt::ArrowCursor) ;
}
void MainWindow::on_PrefixBrowseButton_clicked()
{
QString prefx = QFileDialog::getSaveFileName (this, "Output Spectrum File Prefix") ;
ui->PrefixLE->setText(prefx) ;
}