qEcho/source/mainwindow.cpp

46 lines
1.0 KiB
C++
Raw Permalink Normal View History

2017-10-15 10:30:15 +00:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "blinkthread.h"
#include "distancethread.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->progressBar->setRange(0, 300);
ui->progressBar->setFormat("%v cm");
ui->progressBar->setValue(0);
BlinkThread *blinkThread = new BlinkThread(15);
2017-10-15 10:30:15 +00:00
connect(blinkThread, &BlinkThread::ledOn, this, &MainWindow::ledOn);
connect(blinkThread, &BlinkThread::ledOff, this, &MainWindow::ledOff);
blinkThread->start();
DistanceThread *distanceThread = new DistanceThread(28, 29);
2017-10-15 10:30:15 +00:00
connect(distanceThread, &DistanceThread::distanceUpdated, this, &MainWindow::distanceUpdated);
distanceThread->start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ledOn()
{
ui->label->setText("On");
}
void MainWindow::ledOff()
{
ui->label->setText("Off");
}
void MainWindow::distanceUpdated(double distMeters)
{
ui->progressBar->setValue(distMeters / 100);
}