-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
85 lines (62 loc) · 2.32 KB
/
main.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
#include "mainwindow.h"
#include <QApplication>
#include <QProcess>
#include <uartworker.h>
#include <QDebug>
#include <gpioworker.h>
#include <soundworker.h>
int main(int argc, char *argv[])
{
// Create GUI Thread
QApplication app(argc, argv);
/** DEBUG **/
//qDebug() << "Hello from GUI thread" << app.thread()->currentThreadId();
// Setup UI
MainWindow w;
w.setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
w.showFullScreen();
// All senosr images invisible at start
w.setAllImages2Zero();
// Enable camera
QProcess::execute("sudo modprobe bcm2835-v4l2");
/** UART THREAD SETUP START **/
// Create UART Thread
UARTWorker uartWorker;
// Setup connection between UART thread & GUI thread
QObject::connect(&uartWorker,
SIGNAL(progressChanged(unsigned char, unsigned char)), &w,
SLOT(onSensorChanged(unsigned char,unsigned char)), Qt::QueuedConnection);
// Setup callback for cleanup when it finishes
QObject::connect(&uartWorker, SIGNAL(finished()), &w, SLOT(deleteLater()));
// Start -> calls run()
uartWorker.start();
/** UART THREAD SETUP END **/
/** GPIO THREAD SETUP START **/
// Create GPIO Thread
GPIOWorker gpioWorker;
// Start -> calls run()
gpioWorker.start();
/** GPIO THREAD SETUP END **/
/** SOUND THREAD SETUP START **/
// Create SOUND Thread
SoundWorker soundworker;
// Setup connection between UART thread & SOUND thread
QObject::connect(&uartWorker,
SIGNAL(onSoundPlay(unsigned char)), &soundworker,
SLOT(currentNivaue(unsigned char)), Qt::QueuedConnection);
// Setup callback for cleanup when it finishes
QObject::connect(&uartWorker, SIGNAL(finished()), &soundworker, SLOT(deleteLater()));
//Setup connection between GPIO thread & SOUND thread
QObject::connect(&gpioWorker,
SIGNAL(toggleMusic(bool)), &soundworker,
SLOT(turnOnOff(bool)), Qt::QueuedConnection);
QObject::connect(&gpioWorker, SIGNAL(finished()), &soundworker, SLOT(deleteLater()));
// Start -> calls run()
soundworker.start();
/** SOUND THREAD SETUP END **/
app.exec();
soundworker.wait();
uartWorker.wait();
gpioWorker.wait();
return 0;
}