136 lines
4.5 KiB
C++
136 lines
4.5 KiB
C++
#include "mainwindow.h"
|
|
#include "./ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
mainChart = ui->chartWidget->chart();
|
|
spinner = ui->spinner;
|
|
connect(ui->actionConfiguration, SIGNAL(triggered()), &systemConfigWindow, SLOT(show()));
|
|
connect(ui->actionConnConfiguration, SIGNAL(triggered()), &connConf, SLOT(show()));
|
|
connect(ui->actionDebugStatus, SIGNAL(triggered()), &vdebug, SLOT(show()));
|
|
connect(&ctrl, &ShimLCController::connectionStateChanged, this, &MainWindow::updateConnectionState);
|
|
connect(ui->actionReconnect, &QAction::triggered, this, &MainWindow::reconnect);
|
|
connect(&ctrl, &ShimLCController::newConfigAv, this, &MainWindow::updateAvDevices);
|
|
connect(&ctrl, &ShimLCController::newStatusAv, this, &MainWindow::updateStatus);
|
|
connect(&ctrl, &ShimLCController::newDataAv, this, &MainWindow::updateSeries);
|
|
|
|
// Status Timer
|
|
connect(&statusTimer, &QTimer::timeout, &ctrl, &ShimLCController::updateBuf);
|
|
|
|
spinner->setRoundness(70.0);
|
|
spinner->setMinimumTrailOpacity(15.0);
|
|
spinner->setTrailFadePercentage(70.0);
|
|
spinner->setNumberOfLines(12);
|
|
spinner->setLineLength(10);
|
|
spinner->setLineWidth(5);
|
|
spinner->setInnerRadius(10);
|
|
spinner->setRevolutionsPerSecond(1);
|
|
spinner->setColor(QColor(81, 4, 71));
|
|
|
|
// Try to auto connect
|
|
ui->frame->setEnabled(false);
|
|
reconnect();
|
|
|
|
mainChart->setTitle("Detector Data");
|
|
//mainChart->setAnimationOptions(QChart::SeriesAnimations);
|
|
|
|
// Example...
|
|
/*
|
|
for (int i = 0; i < 500; i++) {
|
|
QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
|
|
p.ry() += QRandomGenerator::global()->bounded(20);
|
|
*series << p;
|
|
}
|
|
*/
|
|
mainChart->addSeries(series);
|
|
mainChart->createDefaultAxes();
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::updateConnectionState(QAbstractSocket::SocketState state)
|
|
{
|
|
const QMetaObject & mo = QAbstractSocket::staticMetaObject;
|
|
QMetaEnum me = mo.enumerator(mo.indexOfEnumerator("SocketState"));
|
|
QString connectionString(me.valueToKey(state));
|
|
ui->connState->setText("COM: "+connectionString);
|
|
ui->connState->setStyleSheet("QLabel { background-color : red; color : black; }");
|
|
if(state == QAbstractSocket::ConnectingState)
|
|
spinner->start();
|
|
else
|
|
spinner->stop();
|
|
if(state == QAbstractSocket::ConnectedState)
|
|
{
|
|
ui->frame->setEnabled(true);
|
|
ui->connState->setStyleSheet("QLabel { background-color : green; color : black; }");
|
|
}
|
|
else
|
|
ui->frame->setEnabled(false);
|
|
}
|
|
|
|
void MainWindow::reconnect()
|
|
{
|
|
// Properly disconnecting is handled by TCPhandler
|
|
// But cmd buffer needs to be cleared, configuration refreshed and all data up to now cleared
|
|
ctrl.reconnect(&settings);
|
|
ctrl.updateConfig();
|
|
ctrl.updateEnv();
|
|
ctrl.updateChk();
|
|
ctrl.updatePif();
|
|
}
|
|
|
|
void MainWindow::updateAvDevices()
|
|
{
|
|
ui->pumpsSelectorBox->clear();
|
|
for(int i=0; i<ctrl.configuration.pumps.length(); i++)
|
|
ui->pumpsSelectorBox->addItem(QString("%1").arg(QString("ABC").at(i)));
|
|
|
|
ui->detectorSelectorBox->clear();
|
|
foreach(LCPort item, ctrl.configuration.detectors)
|
|
ui->detectorSelectorBox->addItem(QString("Port %1: %2").arg(item.port).arg(item.name));
|
|
statusTimer.start(1000);
|
|
}
|
|
|
|
void MainWindow::updateStatus()
|
|
{
|
|
// Stats
|
|
vdebug.updateStatus(ctrl.lastStatus);
|
|
ui->stateLabel->setText(vdebug.cur_stats.join(","));
|
|
|
|
|
|
// Autospampler
|
|
ui->autoSamplerStatus->setText(QString("Rack: %1").arg(ctrl.lastStatus.autosampler.rack));
|
|
|
|
// Pumps
|
|
ui->pumpPress->display(ctrl.lastStatus.pump[ui->pumpsSelectorBox->currentIndex()].actPressure);
|
|
if(not ui->pumpFlow->hasFocus())
|
|
ui->pumpFlow->setValue(ctrl.lastStatus.pump[ui->pumpsSelectorBox->currentIndex()].setFlow);
|
|
|
|
// Detectors
|
|
if(not ui->detectorNmSpinBox->hasFocus())
|
|
ui->detectorNmSpinBox->setValue(ctrl.lastStatus.detector[ui->detectorSelectorBox->currentIndex()].waveLen1);
|
|
|
|
}
|
|
|
|
void MainWindow::updateSeries()
|
|
{
|
|
for(int i = 0; i<ctrl.bufst[0].vals.length(); i++)
|
|
{
|
|
double data_point = ctrl.bufst[0].vals.at(i);
|
|
if(graph_bounds[0] > data_point)
|
|
graph_bounds[0] = data_point;
|
|
if(graph_bounds[1] < data_point)
|
|
graph_bounds[1] = data_point;
|
|
QPointF p((qreal) series->count(), data_point);
|
|
*series << p;
|
|
}
|
|
ctrl.bufst[0].vals.clear();
|
|
mainChart->axisX()->setRange(0, series->count());
|
|
mainChart->axisY()->setRange(graph_bounds[0], graph_bounds[1]);
|
|
}
|