Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120583445
mainwindow.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jul 5, 09:43
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Jul 7, 09:43 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27206380
Attached To
R2671 HHRI-software
mainwindow.cpp
View Options
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <climits>
#include <QMessageBox>
#include <QDebug>
#include <QInputDialog>
#include <QList>
#include "hriboard.h"
const int UPDATE_PERIOD = 50; // [ms].
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//
ui->setupUi(this);
//
voltage1SyncVar = nullptr;
voltage2SyncVar = nullptr;
// Ask for the COM port.
QString comPortName;
QStringList ports = HriBoard::getComPorts();
if(ports.size() == 0)
{
QMessageBox::critical(this, "HRI2_PC_Controller", "No COM port.");
exit(0);
}
else if(ports.size() == 1)
comPortName = ports.first();
else
{
bool ok;
QString portChoice = QInputDialog::getItem(this, "HRI2_PC_Controller",
"Serial port:", ports, 0,
false, &ok);
int portIndex = ports.indexOf(portChoice);
if(portIndex == -1 || !ok)
exit(0);
comPortName = ports[portIndex];
}
// Establish the link with the HRI board.
hriBoard.openLink(comPortName);
connect(&hriBoard, SIGNAL(syncVarsListReceived(QList<const SyncVar*>)),
this, SLOT(onVarsListReceived(QList<const SyncVar*>)));
connect(&hriBoard, SIGNAL(syncVarsUpdated()), this, SLOT(onVarsUpdated()));
// Setup the display update timer.
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateDisplay()));
updateTimer.setSingleShot(false);
updateTimer.start(UPDATE_PERIOD);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onVarsListReceived(QList<const SyncVar*> syncVars)
{
this->syncVars = syncVars;
// Search the useful variables handlers into the list.
voltage1SyncVar = nullptr;
voltage2SyncVar = nullptr;
for(SyncVar const* sv : syncVars)
{
if(sv->getName() == "adc1_voltage [V]")
voltage1SyncVar = sv;
else if(sv->getName() == "adc2_voltage [V]")
voltage2SyncVar = sv;
}
// If the desired variables have not been found, abort.
if(voltage1SyncVar == nullptr || voltage2SyncVar == nullptr)
{
qDebug() << "The variables list does not contains the right variables."
<< endl;
return;
}
// Start the streaming.
QList<SyncVar const*> varsToStream;
varsToStream.append(voltage1SyncVar);
varsToStream.append(voltage2SyncVar);
hriBoard.setStreamedVars(varsToStream);
}
void MainWindow::onVarsUpdated()
{
if(voltage1SyncVar != nullptr)
voltage1 = voltage1SyncVar->toDouble();
if(voltage2SyncVar != nullptr)
voltage2 = voltage2SyncVar->toDouble();
}
void MainWindow::updateDisplay()
{
// Update the label widgets.
ui->volt1Label->setText(QString::number(voltage1, 'f', 2) + " V");
ui->volt2Label->setText(QString::number(voltage2, 'f', 2) + " V");
}
Event Timeline
Log In to Comment