-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreceivethread.cpp
More file actions
92 lines (80 loc) · 1.69 KB
/
receivethread.cpp
File metadata and controls
92 lines (80 loc) · 1.69 KB
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
#include "receivethread.h"
receiveThread::receiveThread()
{
//setting initial values to zero to avoid drawing line before the data is sent
for (int i=0; i<=9; i++)
{
sCoordinateX[i]=0;
sCoordinateY[i]=0;
eCoordinateX[i]=0;
eCoordinateY[i]=0;
}
}
void receiveThread::run()
{
QMutex mutex;
while(1)
{
if(sharedPins[10]==1)
emit clearBtnSignal();
else
{
if(sharedPins[20]==1)//case where the starting point is being sent
{
for(int i=0; i<=9;i++)
{
qDebug()<<sharedPins[i];
mutex.lock();
sCoordinateX[i] = sharedPins[i];
sCoordinateY[i] = sharedPins[i+10];
mutex.unlock();
}
}
else//case where the ending point is being sent
{
for(int i=0; i<=9;i++)
{
mutex.lock();
eCoordinateX[i] = sharedPins[i];
eCoordinateY[i] = sharedPins[i+10];
mutex.unlock();
}
emit readingFinished();
}
}
usleep(10);
}
}
void receiveThread::assignPins(bool *target)
{
for(int i=0;i<=9;i++)
{
target[i]=sharedPins[i];
}
}
int receiveThread::getSX()
{
return deserialize(sCoordinateX);
}
int receiveThread::getSY()
{
return deserialize(sCoordinateY);
}
int receiveThread::getEX()
{
return deserialize(eCoordinateX);
}
int receiveThread::getEY()
{
return deserialize(eCoordinateY);
}
int receiveThread::deserialize(bool *data)
{
int sum = 0;
for (int i=0;i<=9;i++)
{
if(data[i]==1)
sum += pow(2,9-i);
}
return sum;
}